5
5
import tkinter as tk
6
6
7
7
photo = askopenfilename ()
8
- img = cv2 .imread (photo ,cv2 .IMREAD_GRAYSCALE )
9
- blurred = cv2 .medianBlur (img ,5 )
10
- edges = cv2 .Canny (blurred ,50 ,150 ,apertureSize = 3 )
8
+ img = cv2 .imread (photo , cv2 .IMREAD_GRAYSCALE )
9
+ blurred = cv2 .medianBlur (img , 5 )
10
+ edges = cv2 .Canny (blurred , 50 , 150 , apertureSize = 3 )
11
11
# the image read in grayscale format is blurred and edges are detected in it
12
- circles = cv2 .HoughCircles (edges ,cv2 .HOUGH_GRADIENT ,1 ,30 ,param1 = 50 ,param2 = 31 ,minRadius = 0 ,maxRadius = 0 )
12
+ circles = cv2 .HoughCircles (edges , cv2 .HOUGH_GRADIENT ,
13
+ 1 , 30 , param1 = 50 , param2 = 31 , minRadius = 0 , maxRadius = 0 )
13
14
# the parameters in the above function needs to be adjusted for each image accordingly.
14
15
circles = np .uint16 (np .around (circles ))
15
16
16
- colorImg = cv2 .cvtColor (img ,cv2 .COLOR_GRAY2BGR )
17
- for i in circles [0 ,:]:
18
- cv2 .circle (colorImg ,(i [0 ],i [1 ]),i [2 ],(0 ,255 ,0 ),2 )
17
+ colorImg = cv2 .cvtColor (img , cv2 .COLOR_GRAY2BGR )
18
+ for i in circles [0 , :]:
19
+ cv2 .circle (colorImg , (i [0 ], i [1 ]), i [2 ], (0 , 255 , 0 ), 2 )
19
20
# drawing the circle
20
- cv2 .circle (colorImg ,(i [0 ],i [1 ]),2 , (0 ,0 , 255 ),3 )
21
+ cv2 .circle (colorImg , (i [0 ], i [1 ]), 2 , (0 , 0 , 255 ), 3 )
21
22
# drawing its center
22
23
23
- cv2 .imwrite ('output.jpg' ,colorImg )
24
- cv2 .imshow ('output' ,colorImg )
24
+ cv2 .imwrite ('output.jpg' , colorImg )
25
+ cv2 .imshow ('output' , colorImg )
25
26
cv2 .waitKey (2000 )
26
- cv2 .destroyAllWindows ()
27
+ cv2 .destroyAllWindows ()
0 commit comments