Skip to content

Commit 8926cbd

Browse files
opencv
1 parent 97d3a88 commit 8926cbd

File tree

1 file changed

+96
-3
lines changed

1 file changed

+96
-3
lines changed

Linkedin/Opencv/Untitled.ipynb

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,18 @@
312312
},
313313
{
314314
"cell_type": "code",
315-
"execution_count": null,
315+
"execution_count": 3,
316316
"metadata": {},
317-
"outputs": [],
317+
"outputs": [
318+
{
319+
"name": "stdout",
320+
"output_type": "stream",
321+
"text": [
322+
"Pressed: 526 347\n",
323+
"Pressed: 332 243\n"
324+
]
325+
}
326+
],
318327
"source": [
319328
"import numpy as np\n",
320329
"import cv2\n",
@@ -324,7 +333,13 @@
324333
"point=(200,200)\n",
325334
"radius=40\n",
326335
"border_width=6\n",
327-
"def click(event,x,y)\n",
336+
"def click(event,x,y,flags,param):\n",
337+
" global point,pressed\n",
338+
" if event==cv2.EVENT_LBUTTONDOWN:\n",
339+
" print('Pressed: ',x,y)\n",
340+
" point=(x,y)\n",
341+
"cv2.namedWindow('keshav')\n",
342+
"cv2.setMouseCallback('keshav',click)\n",
328343
"while True:\n",
329344
" ret,frame=cap.read()\n",
330345
" cv2.circle(frame,point,radius,color,border_width)\n",
@@ -334,6 +349,84 @@
334349
"cap.release()\n",
335350
"cv2.destroyAllWindows()"
336351
]
352+
},
353+
{
354+
"cell_type": "code",
355+
"execution_count": 18,
356+
"metadata": {},
357+
"outputs": [],
358+
"source": [
359+
"# Drawing App\n",
360+
"import numpy as np\n",
361+
"import cv2\n",
362+
"# cap=cv2.VideoCapture(0)\n",
363+
"keshav=np.ones([500,500,3],'uint8')*255\n",
364+
"radius=3\n",
365+
"color=(0,255,0)\n",
366+
"pressed=False\n",
367+
"def click(event,x,y,flags,param):\n",
368+
" global keshav,pressed\n",
369+
" if event==cv2.EVENT_LBUTTONDOWN:\n",
370+
" pressed=True\n",
371+
" cv2.circle(keshav,(x,y),radius,color,-1)\n",
372+
" elif event==cv2.EVENT_MOUSEMOVE and pressed==True:\n",
373+
" cv2.circle(keshav,(x,y),radius,color,-1)\n",
374+
" elif event==cv2.EVENT_LBUTTONUP:\n",
375+
" pressed=False\n",
376+
"cv2.namedWindow('keshav')\n",
377+
"cv2.setMouseCallback('keshav',click)\n",
378+
"\n",
379+
"while True:\n",
380+
" cv2.imshow('keshav',keshav)\n",
381+
" if cv2.waitKey(1)&0xff==ord('q'):\n",
382+
" break\n",
383+
" elif cv2.waitKey(1)&0xff==ord('b'):\n",
384+
" color=(255,0,0)\n",
385+
" elif cv2.waitKey(1)&0xff==ord('g'):\n",
386+
" color=(0,255,0)\n",
387+
" elif cv2.waitKey(1)&0xff==ord('r'):\n",
388+
" color=(0,0,255)\n",
389+
"cv2.destroyAllWindows()"
390+
]
391+
},
392+
{
393+
"cell_type": "code",
394+
"execution_count": 12,
395+
"metadata": {},
396+
"outputs": [],
397+
"source": [
398+
"# chapter 3\n",
399+
"# segmentation\n",
400+
"# simple threading\n",
401+
"import numpy as np\n",
402+
"import cv2\n",
403+
"bw=cv2.imread('0.jpeg',0)\n",
404+
"cv2.imshow('Original',bw)\n",
405+
"\n",
406+
"'method1'\n",
407+
"height,width=bw.shape[0:2]\n",
408+
"binary=np.zeros([height,width,3],'uint8')\n",
409+
"thresh=85\n",
410+
"for row in range(0,height):\n",
411+
" for col in range(0,width):\n",
412+
" if bw[row][col]>thresh:\n",
413+
" binary[row][col]=255\n",
414+
"cv2.imshow('binary',binary)\n",
415+
"\n",
416+
"'method2'\n",
417+
"ret,thresh=cv2.threshold(bw,thresh,255,cv2.THRESH_BINARY)\n",
418+
"cv2.imshow('thresh',thresh)\n",
419+
"\n",
420+
"cv2.waitKey(0)\n",
421+
"cv2.destroyAllWindows()"
422+
]
423+
},
424+
{
425+
"cell_type": "code",
426+
"execution_count": null,
427+
"metadata": {},
428+
"outputs": [],
429+
"source": []
337430
}
338431
],
339432
"metadata": {

0 commit comments

Comments
 (0)