55# load the image, clone it for output, and then convert it to grayscale
66image_file = '/Users/vaneesh_k/PycharmProjects/Albie_ML/size-of-objects/images/coin.png'
77image = cv2 .imread (image_file )
8- image = cv2 .resize (image ,(800 ,800 ))
8+ image = cv2 .resize (image , (800 , 800 ))
99output = image .copy ()
1010gray = cv2 .cvtColor (image , cv2 .COLOR_BGR2GRAY )
11+ # mask =
1112
13+ cv2 .imshow ('mask' ,gray )
1214# detect circles in the image
13- circles = cv2 .HoughCircles (gray , cv2 .HOUGH_GRADIENT , 2 , 1 , minRadius = 5 , maxRadius = 10 )
14- print ('FOund some circles' )
15+ circles = cv2 .HoughCircles (gray , cv2 .HOUGH_GRADIENT , 4.0 , 100 , 100.0 , 30.0 , 20 , 200 )
16+ print ('Found some circles' )
1517# ensure at least some circles were found
1618if circles is not None :
17- print ('Found circle ' )
18- # convert the (x, y) coordinates and radius of the circles to integers
19- circles = np .round (circles [0 , :]).astype ("int" )
19+ print ('filterd circles ' )
20+ # convert the (x, y) coordinates and radius of the circles to integers
21+ circles = np .round (circles [0 , :]).astype ("int" )
2022
23+ # loop over the (x, y) coordinates and radius of the circles
24+ for (x , y , r ) in circles :
25+ # draw the circle in the output image, then draw a rectangle
26+ # corresponding to the center of the circle
27+ cv2 .circle (output , (x , y ), r , (0 , 255 , 0 ), 4 )
28+ cv2 .rectangle (output , (x - 5 , y - 5 ), (x + 5 , y + 5 ), (0 , 128 , 255 ), - 1 )
2129
22- # loop over the (x, y) coordinates and radius of the circles
23- for (x , y , r ) in circles :
24- # draw the circle in the output image, then draw a rectangle
25- # corresponding to the center of the circle
26- cv2 .circle (output , (x , y ), r , (0 , 255 , 0 ), 4 )
27- cv2 .rectangle (output , (x - 5 , y - 5 ), (x + 5 , y + 5 ), (0 , 128 , 255 ), - 1 )
28-
29- # show the output image
30- cv2 .imshow ("output" , np .hstack ([image , output ]))
31- cv2 .waitKey (0 )
30+ # show the output image
31+ cv2 .imshow ("output" , np .hstack ([image , output ]))
32+ cv2 .waitKey (0 )
0 commit comments