0

I'm using the code explained in https://www.pyimagesearch.com/2014/07/21/detecting-circles-images-using-opencv-hough-circles/#comment-480634 and trying to basically detect the small rounded profile images (to be precise 5) displayed lower half of this sample instagram page (attached). What I can't figure out is why: 1. only one out of the 5 small rounded profile circles is captured by the code 2. how come there's a big circle displayed on the page and seems quite absurd to me. Here is the code I'm using:

# we create a copy of the original image so we can draw our detected circles 
# without destroying the original image.
image = cv2.imread("instagram_page.png")

# the cv2.HoughCircles function requires an 8-bit, single channel image, 
# so we’ll convert from the RGB color space to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
#blurred = cv2.GaussianBlur(gray, (5, 5), 0)

# detect circles in the image. We pass in the image we want to detect circles as the first argument, 
# the circle detection method as the second argument (currently, the cv2.cv.HOUGH_GRADIENT method 
# is the only circle detection method supported by OpenCV and will likely be the only method for some time),
# an accumulator value of 1.5 as the third argument, and finally a minDist of 100 pixels.
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.7, minDist= 1, param1 = 300, param2 = 100, minRadius=3, maxRadius=150)

print("Circles len -> {}".format(len(circles)))


# ensure at least some circles were found
if circles is not None:    
    # convert the (x, y) coordinates and radius of the circles to integers
    # converting our circles from floating point (x, y) coordinates to integers, 
    # allowing us to draw them on our output image.
    circles = np.round(circles[0, :]).astype("int")

    # loop over the (x, y) coordinates and radius of the circles
    for (x, y, r) in circles:
        # draw the circle in the output image, then draw a rectangle
        # corresponding to the center of the circle
        orange = (39, 127, 255)
        cv2.circle(output, (x, y), r, orange, 4)
        cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)


img_name = "Output"
cv2.namedWindow(img_name,cv2.WINDOW_NORMAL)
cv2.resizeWindow(img_name, 800,800)
cv2.imshow(img_name, output)
cv2.waitKey(0)    
cv2.destroyAllWindows()

I use minDist = 1 to make sure those close circles are potentially captured. Does anybody see something completely wrong with my parameters?enter image description here

1 Answer 1

2

I played around with the parameters and managed to detect all circles (Ubuntu 16.04 LTS x64, Python 3.7, numpy==1.15.1, python-opencv==3.4.3):

circles = cv2.HoughCircles(
    gray,
    cv2.HOUGH_GRADIENT,
    1.7,
    minDist=100,
    param1=48,
    param2=100,
    minRadius=2,
    maxRadius=100
)

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you Sir, appreciated. May I ask if you could explain with simple English what's the meaning of param1 and param2? Probably they are the only two parameters I don't fully understand in the formula (I reviewed the official definition but i honestly don't understand it). Thanks
I'm afraid I too don't have sufficient understanding about the algorithm. I just increased/decreased the parameters step by step to find the best results. All that I know is that param1 determines the sensitivity of edge detection algorithm while param2 determines the sensitivity of center detection algorithm docs.opencv.org/3.1.0/d4/d70/tutorial_hough_circle.html
I see. Your solution is helpful but I tested on another instagram page and it shows more than 30 random circles all over the page. I don't understand how come this library is so unstable especially when it comes to identify clear objects on a web page
You have to dive deeper to the theory & library source code to understand that. You can also post question in dsp.stackexchange.com as this is not actually about simple coding anymore. But if you don't want to go that far, you can play around with preprocessing methods such as filtering & additional edge detection layer0.authentise.com/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.