Skip to content

Commit 97d3a88

Browse files
Opencv
1 parent c0caa67 commit 97d3a88

File tree

3 files changed

+360
-0
lines changed

3 files changed

+360
-0
lines changed

Linkedin/Opencv/0.jpeg

173 KB
Loading

Linkedin/Opencv/Untitled.ipynb

Lines changed: 360 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,360 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 8,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import cv2\n",
10+
"img=cv2.imread('0.jpeg')\n",
11+
"# initilization of window\n",
12+
"cv2.namedWindow('IMAGE',0)\n",
13+
"\n",
14+
"cv2.imshow('IMAGE',img)\n",
15+
"cv2.imwrite('output.jpeg',img)\n",
16+
"cv2.waitKey()\n",
17+
"cv2.destroyAllWindows()"
18+
]
19+
},
20+
{
21+
"cell_type": "code",
22+
"execution_count": 18,
23+
"metadata": {},
24+
"outputs": [
25+
{
26+
"name": "stdout",
27+
"output_type": "stream",
28+
"text": [
29+
"[[[ 24 146 162]\n",
30+
" [ 21 146 166]\n",
31+
" [ 16 147 174]\n",
32+
" ...\n",
33+
" [ 7 146 172]\n",
34+
" [ 16 149 169]\n",
35+
" [ 23 155 172]]\n",
36+
"\n",
37+
" [[ 24 151 166]\n",
38+
" [ 22 151 170]\n",
39+
" [ 15 151 177]\n",
40+
" ...\n",
41+
" [ 7 151 176]\n",
42+
" [ 13 152 171]\n",
43+
" [ 17 156 172]]\n",
44+
"\n",
45+
" [[ 22 159 175]\n",
46+
" [ 19 158 177]\n",
47+
" [ 14 157 184]\n",
48+
" ...\n",
49+
" [ 13 165 189]\n",
50+
" [ 14 164 181]\n",
51+
" [ 17 166 180]]\n",
52+
"\n",
53+
" ...\n",
54+
"\n",
55+
" [[ 6 176 194]\n",
56+
" [ 2 174 192]\n",
57+
" [ 8 179 201]\n",
58+
" ...\n",
59+
" [ 1 186 196]\n",
60+
" [ 0 183 188]\n",
61+
" [ 0 175 178]]\n",
62+
"\n",
63+
" [[ 0 167 185]\n",
64+
" [ 0 167 185]\n",
65+
" [ 0 168 191]\n",
66+
" ...\n",
67+
" [ 0 177 188]\n",
68+
" [ 0 180 188]\n",
69+
" [ 0 180 186]]\n",
70+
"\n",
71+
" [[ 0 162 180]\n",
72+
" [ 0 163 181]\n",
73+
" [ 0 161 184]\n",
74+
" ...\n",
75+
" [ 0 168 182]\n",
76+
" [ 0 173 183]\n",
77+
" [ 0 181 189]]]\n",
78+
"<class 'numpy.ndarray'>\n",
79+
"920\n",
80+
"752\n",
81+
"3\n",
82+
"(920, 752, 3)\n",
83+
"uint8\n",
84+
"[[24 21 16 ... 7 16 23]\n",
85+
" [24 22 15 ... 7 13 17]\n",
86+
" [22 19 14 ... 13 14 17]\n",
87+
" ...\n",
88+
" [ 6 2 8 ... 1 0 0]\n",
89+
" [ 0 0 0 ... 0 0 0]\n",
90+
" [ 0 0 0 ... 0 0 0]]\n",
91+
"[ 86 162 214]\n"
92+
]
93+
}
94+
],
95+
"source": [
96+
"#access and understand pixel data\n",
97+
"import cv2\n",
98+
"import numpy as np\n",
99+
"img=cv2.imread('0.jpeg')\n",
100+
"\n",
101+
"print(img)\n",
102+
"print(type(img))\n",
103+
"print(len(img))\n",
104+
"print(len(img[0]))\n",
105+
"print(len(img[0][0]))\n",
106+
"print(img.shape)\n",
107+
"print(img.dtype)\n",
108+
"print(img[:,:,0]) #red channel\n",
109+
"print(img[10][15])\n"
110+
]
111+
},
112+
{
113+
"cell_type": "code",
114+
"execution_count": 15,
115+
"metadata": {},
116+
"outputs": [
117+
{
118+
"name": "stdout",
119+
"output_type": "stream",
120+
"text": [
121+
"[0]\n",
122+
"[1 1 1]\n",
123+
"[65535 65535 65535]\n",
124+
"[255 0 0]\n"
125+
]
126+
}
127+
],
128+
"source": [
129+
"# Data types and structures\n",
130+
"import numpy as np\n",
131+
"import cv2\n",
132+
"\n",
133+
"black=np.zeros([150,150,1],'uint8')\n",
134+
"cv2.imshow('black',black)\n",
135+
"print(black[0,0,:])\n",
136+
"\n",
137+
"ones=np.ones([150,150,3],'uint8')\n",
138+
"# ones*=(2**8-1)\n",
139+
"cv2.imshow('ones',ones)\n",
140+
"print(ones[0,0,:])\n",
141+
"\n",
142+
"white=np.ones([150,150,3],'uint16')\n",
143+
"white*=(2**16-1)\n",
144+
"cv2.imshow('white',white)\n",
145+
"print(white[0,0,:])\n",
146+
"\n",
147+
"#\n",
148+
"color=ones.copy()\n",
149+
"color[:,:]=(255,0,0) #blue\n",
150+
"cv2.imshow('blue',color)\n",
151+
"print(color[0,0,:])\n",
152+
"\n",
153+
"cv2.waitKey(0)\n",
154+
"cv2.destroyAllWindows()"
155+
]
156+
},
157+
{
158+
"cell_type": "code",
159+
"execution_count": 17,
160+
"metadata": {},
161+
"outputs": [
162+
{
163+
"name": "stdout",
164+
"output_type": "stream",
165+
"text": [
166+
"(920, 752, 3)\n"
167+
]
168+
}
169+
],
170+
"source": [
171+
"# image types and color channels\n",
172+
"import numpy as np\n",
173+
"import cv2\n",
174+
"img=cv2.imread('0.jpeg',1)\n",
175+
"cv2.imshow('image',img)\n",
176+
"cv2.moveWindow('image',0,0)\n",
177+
"\n",
178+
"print(img.shape)\n",
179+
"width,height,channel=img.shape\n",
180+
"\n",
181+
"cv2.waitKey(0)\n",
182+
"cv2.destroyAllWindows()"
183+
]
184+
},
185+
{
186+
"cell_type": "code",
187+
"execution_count": 7,
188+
"metadata": {},
189+
"outputs": [],
190+
"source": [
191+
"# pixel manipulation and filtering\n",
192+
"import cv2\n",
193+
"img=cv2.imread('0.jpeg',1)\n",
194+
"\n",
195+
"gray=cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)\n",
196+
"cv2.imshow('KESHAV',gray)\n",
197+
"\n",
198+
"r=img[:,:,0]\n",
199+
"g=img[:,:,1]\n",
200+
"b=img[:,:,2]\n",
201+
"\n",
202+
"rgba=cv2.merge((r,g,b,g))\n",
203+
"cv2.imshow('rgba',rgba)\n",
204+
"\n",
205+
"\n",
206+
"cv2.waitKey(0)\n",
207+
"cv2.destroyAllWindows()"
208+
]
209+
},
210+
{
211+
"cell_type": "code",
212+
"execution_count": 3,
213+
"metadata": {},
214+
"outputs": [],
215+
"source": [
216+
"# Gussian Blur,dilation and erosion\n",
217+
"import numpy as np\n",
218+
"import cv2\n",
219+
"img=cv2.imread('0.jpeg',1)\n",
220+
"cv2.imshow('original',img)\n",
221+
"\n",
222+
"# blur\n",
223+
"blur=cv2.GaussianBlur(img,(5,55),0)\n",
224+
"cv2.imshow('Gaussian Blur',blur)\n",
225+
"\n",
226+
"kernel=np.ones((5,5),'uint8')\n",
227+
"dilate=cv2.dilate(img,kernel,iterations=1)\n",
228+
"erode=cv2.erode(img,kernel,iterations=1)\n",
229+
"\n",
230+
"cv2.imshow('dilate',dilate)\n",
231+
"cv2.imshow('erode',erode)\n",
232+
"\n",
233+
"cv2.waitKey(0)\n",
234+
"cv2.destroyAllWindows()"
235+
]
236+
},
237+
{
238+
"cell_type": "code",
239+
"execution_count": 3,
240+
"metadata": {},
241+
"outputs": [],
242+
"source": [
243+
"# scale and rotate image\n",
244+
"import numpy as np\n",
245+
"import cv2\n",
246+
"img=cv2.imread('0.jpeg',1)\n",
247+
"cv2.imshow('original',img)\n",
248+
"\n",
249+
"# scale\n",
250+
"half=cv2.resize(img,(0,0),fx=0.5,fy=0.5,)\n",
251+
"cv2.imshow('half',half)\n",
252+
"\n",
253+
"stretch_=cv2.resize(img,(600,600),fx=0.5,fy=0.5)\n",
254+
"cv2.imshow('stretch_',stretch_)\n",
255+
"\n",
256+
"stretch_near_=cv2.resize(img,(600,600),fx=0.5,fy=0.5,interpolation = cv2.INTER_NEAREST)\n",
257+
"cv2.imshow('stretch_near_',stretch_near_)\n",
258+
"\n",
259+
"# rotate\n",
260+
"M=cv2.getRotationMatrix2D((0,0),-30,1)\n",
261+
"rotated=cv2.warpAffine(img,M,(img.shape[1],img.shape[0]))\n",
262+
"cv2.imshow('rotated',rotated)\n",
263+
"\n",
264+
"cv2.waitKey(0)\n",
265+
"cv2.destroyAllWindows()"
266+
]
267+
},
268+
{
269+
"cell_type": "code",
270+
"execution_count": 6,
271+
"metadata": {},
272+
"outputs": [],
273+
"source": [
274+
"# video inputs\n",
275+
"import numpy as np\n",
276+
"import cv2\n",
277+
"cap=cv2.VideoCapture(0)\n",
278+
"while True:\n",
279+
" ret,frame=cap.read()\n",
280+
" cv2.imshow('keshav',frame)\n",
281+
" if cv2.waitKey(1)&0xff==ord('q'):\n",
282+
" break\n",
283+
"cap.release()\n",
284+
"cv2.destroyAllWindows()"
285+
]
286+
},
287+
{
288+
"cell_type": "code",
289+
"execution_count": 3,
290+
"metadata": {},
291+
"outputs": [],
292+
"source": [
293+
"# create custom interface\n",
294+
"import numpy as np\n",
295+
"import cv2\n",
296+
"cap=cv2.VideoCapture(0)\n",
297+
"# circle\n",
298+
"color=(0,255,0)\n",
299+
"point=(200,200)\n",
300+
"radius=40\n",
301+
"border_width=6\n",
302+
"\n",
303+
"while True:\n",
304+
" ret,frame=cap.read()\n",
305+
" cv2.circle(frame,point,radius,color,border_width)\n",
306+
" cv2.imshow('keshav',frame)\n",
307+
" if cv2.waitKey(1)&0xff==ord('q'):\n",
308+
" break\n",
309+
"cap.release()\n",
310+
"cv2.destroyAllWindows()"
311+
]
312+
},
313+
{
314+
"cell_type": "code",
315+
"execution_count": null,
316+
"metadata": {},
317+
"outputs": [],
318+
"source": [
319+
"import numpy as np\n",
320+
"import cv2\n",
321+
"cap=cv2.VideoCapture(0)\n",
322+
"# circle\n",
323+
"color=(0,255,0)\n",
324+
"point=(200,200)\n",
325+
"radius=40\n",
326+
"border_width=6\n",
327+
"def click(event,x,y)\n",
328+
"while True:\n",
329+
" ret,frame=cap.read()\n",
330+
" cv2.circle(frame,point,radius,color,border_width)\n",
331+
" cv2.imshow('keshav',frame)\n",
332+
" if cv2.waitKey(1)&0xff==ord('q'):\n",
333+
" break\n",
334+
"cap.release()\n",
335+
"cv2.destroyAllWindows()"
336+
]
337+
}
338+
],
339+
"metadata": {
340+
"kernelspec": {
341+
"display_name": "Python 3",
342+
"language": "python",
343+
"name": "python3"
344+
},
345+
"language_info": {
346+
"codemirror_mode": {
347+
"name": "ipython",
348+
"version": 3
349+
},
350+
"file_extension": ".py",
351+
"mimetype": "text/x-python",
352+
"name": "python",
353+
"nbconvert_exporter": "python",
354+
"pygments_lexer": "ipython3",
355+
"version": "3.7.5"
356+
}
357+
},
358+
"nbformat": 4,
359+
"nbformat_minor": 2
360+
}

Linkedin/Opencv/output.jpeg

330 KB
Loading

0 commit comments

Comments
 (0)