55import tkinter as tk
66
77photo = 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 )
1111# 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 )
1314# the parameters in the above function needs to be adjusted for each image accordingly.
1415circles = np .uint16 (np .around (circles ))
1516
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 )
1920 # 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 )
2122 # drawing its center
2223
23- cv2 .imwrite ('output.jpg' ,colorImg )
24- cv2 .imshow ('output' ,colorImg )
24+ cv2 .imwrite ('output.jpg' , colorImg )
25+ cv2 .imshow ('output' , colorImg )
2526cv2 .waitKey (2000 )
26- cv2 .destroyAllWindows ()
27+ cv2 .destroyAllWindows ()
0 commit comments