Skip to content

Commit 80c61f0

Browse files
committed
Open-CV-Implementations
1 parent c47f012 commit 80c61f0

File tree

2 files changed

+161
-0
lines changed

2 files changed

+161
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ This is a repository of code files which can be used to perform some basic tasks
1010

1111
Python Code to load and display an image using OpenCV.
1212

13+
* [Changing Resolution & Rescaling of Frame of an Image ](https://github.com/altruistcoder/Open-CV-Implementations/blob/master/changing_resolution_and_scaling.ipynb):
14+
15+
Python Code to load and display an image using OpenCV.
16+
1317
* [Drawing Geometric Figures on Images](https://github.com/altruistcoder/Open-CV-Implementations/blob/master/drawing_figures_on_image.ipynb):
1418

1519
Python Code to draw geometric figures like lines, rectangles, circles and concentric circles on an image using OpenCV.
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Changing Resolution and Rescaling of Frame of an Image using OpencV"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 1,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"import cv2"
17+
]
18+
},
19+
{
20+
"cell_type": "markdown",
21+
"metadata": {},
22+
"source": [
23+
"## Adjusting Resolution of an Image"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": 2,
29+
"metadata": {},
30+
"outputs": [],
31+
"source": [
32+
"def make_1080p():\n",
33+
" cap.set(3, 1920)\n",
34+
" cap.set(4, 1080)\n",
35+
"\n",
36+
"def make_720p():\n",
37+
" cap.set(3, 1280)\n",
38+
" cap.set(4, 720)\n",
39+
"\n",
40+
"def make_480p():\n",
41+
" cap.set(3, 640)\n",
42+
" cap.set(4, 480)\n",
43+
"\n",
44+
"def change_res(width, height):\n",
45+
" cap.set(3, width)\n",
46+
" cap.set(4, height)"
47+
]
48+
},
49+
{
50+
"cell_type": "code",
51+
"execution_count": 4,
52+
"metadata": {},
53+
"outputs": [],
54+
"source": [
55+
"cap = cv2.VideoCapture(0)\n",
56+
"\n",
57+
"# make_720p()\n",
58+
"change_res(800, 400)\n",
59+
"\n",
60+
"while True:\n",
61+
" ret, frame = cap.read()\n",
62+
" cv2.imshow('Frame', frame)\n",
63+
" \n",
64+
" if cv2.waitKey(20) & 0xFF == ord('q'):\n",
65+
" break\n",
66+
"\n",
67+
"cap.release()\n",
68+
"cv2.destroyAllWindows()"
69+
]
70+
},
71+
{
72+
"cell_type": "markdown",
73+
"metadata": {},
74+
"source": [
75+
"## Scaling of the Frames"
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": 5,
81+
"metadata": {},
82+
"outputs": [],
83+
"source": [
84+
"def rescale_frame(frame, percent=75):\n",
85+
" width = int(frame.shape[1] * percent/ 100)\n",
86+
" height = int(frame.shape[0] * percent/ 100)\n",
87+
" dim = (width, height)\n",
88+
" return cv2.resize(frame, dim, interpolation =cv2.INTER_AREA)"
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": 7,
94+
"metadata": {},
95+
"outputs": [],
96+
"source": [
97+
"cap = cv2.VideoCapture(0)\n",
98+
"\n",
99+
"while True:\n",
100+
" rect, frame = cap.read()\n",
101+
" cv2.imshow(\"Original Frame\", frame)\n",
102+
" frame75 = rescale_frame(frame, percent=75)\n",
103+
" cv2.imshow('Frame75', frame75)\n",
104+
" frame150 = rescale_frame(frame, percent=150)\n",
105+
" cv2.imshow('Frame150', frame150)\n",
106+
" \n",
107+
" if cv2.waitKey(20) & 0xFF == ord('q'):\n",
108+
" break\n",
109+
"\n",
110+
"cap.release()\n",
111+
"cv2.destroyAllWindows()"
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": null,
117+
"metadata": {},
118+
"outputs": [],
119+
"source": []
120+
},
121+
{
122+
"cell_type": "code",
123+
"execution_count": null,
124+
"metadata": {},
125+
"outputs": [],
126+
"source": []
127+
},
128+
{
129+
"cell_type": "code",
130+
"execution_count": null,
131+
"metadata": {},
132+
"outputs": [],
133+
"source": []
134+
}
135+
],
136+
"metadata": {
137+
"kernelspec": {
138+
"display_name": "Python 3",
139+
"language": "python",
140+
"name": "python3"
141+
},
142+
"language_info": {
143+
"codemirror_mode": {
144+
"name": "ipython",
145+
"version": 3
146+
},
147+
"file_extension": ".py",
148+
"mimetype": "text/x-python",
149+
"name": "python",
150+
"nbconvert_exporter": "python",
151+
"pygments_lexer": "ipython3",
152+
"version": "3.5.2"
153+
}
154+
},
155+
"nbformat": 4,
156+
"nbformat_minor": 2
157+
}

0 commit comments

Comments
 (0)