Reputation: 151
I have the following image of a bubble raft
Here's the code I'm using to detect the circles:
import cv2
import numpy as np
import sys
img = cv2.imread(sys.argv[1],0)
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,20,
param1=50,param2=30,minRadius=5,maxRadius=25)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
cv2.imshow('detected circles',cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()
Unfortunately, I only get to detect a few circles:
I'd like to detect most of the circles in the image. From that I can programmatically find the dislocation near the middle of the image. Any help much appreciated. Thanks in advance.
Edit: Based on the suggestion by shortcipher3 below, I lowered param2 from HoughCircles to 15
and increased the minimum radius to 16 and now I can detect most of the circles as you can see below:
Upvotes: 0
Views: 1372
Reputation: 1380
I'm not clear what your question is, I assume you want more of the circles to be detected?
The documentation for HoughCircles can be found here:
https://docs.opencv.org/2.4/modules/imgproc/doc/feature_detection.html?highlight=houghcircles
Based on the documentation, I would say that your thresholds aren't ideal in the call circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,20,
param1=50,param2=30,minRadius=5,maxRadius=25)
I would first try lowering param2
and also play with the value of param1
if that doesn't work for you.
Upvotes: 1