Ask Your Question

Revision history [back]

Unable to detect circles with HOUGH_GRADIENT_ALT (OpenCV 4.4.0.44 Python)

Hello, I'm trying to use the HOUGH_GRADIENT_ALT mode of the Hough Circles package and I'm having a lot of trouble. I am not even to detect a circle in a very simple test case (I attached a low resolution copy), let alone for the intended use. I did a basic parameter sweep for p1 and p2, which was a successful strategy for me using the HOUGH_GRADIENT mode. Based off my understanding of the documentation, calling the function with these parameters should work for a clearly defined circle.

cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT_ALT, 1.5, 1, 300, 0.9)

I've tried a combination of values for dp (0.5,1,1.5), parameter 1 (100-10000 in increments of 100), and parameter 2 (0.1 to 1.0 in increments of 0.1), none of which returned a single circle. I also confirmed that the original mode worked as expected, so I'm not sure what caused this change in behavior. I would appreciate any advice that someone could give because I'm really at a loss as to what's gone wrong. I included an example workflow below in case there's something I'm doing incorrectly beforehand.

import cv2
input_tif = '/path/to/tif'
image = cv2.imread(input_tif)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT_ALT, 1.5, 1, 300, 0.9)

C:\fakepath\test_circle.png

click to hide/show revision 2
None

updated 2020-10-20 01:55:59 -0600

berak gravatar image

Unable to detect circles with HOUGH_GRADIENT_ALT (OpenCV 4.4.0.44 Python)

Hello, I'm trying to use the HOUGH_GRADIENT_ALT mode of the Hough Circles package and I'm having a lot of trouble. I am not even to detect a circle in a very simple test case (I attached a low resolution copy), let alone for the intended use. I did a basic parameter sweep for p1 and p2, which was a successful strategy for me using the HOUGH_GRADIENT mode. Based off my understanding of the documentation, calling the function with these parameters should work for a clearly defined circle.

cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT_ALT, 1.5, 1, 300, 0.9)

I've tried a combination of values for dp (0.5,1,1.5), parameter 1 (100-10000 in increments of 100), and parameter 2 (0.1 to 1.0 in increments of 0.1), none of which returned a single circle. I also confirmed that the original mode worked as expected, so I'm not sure what caused this change in behavior. I would appreciate any advice that someone could give because I'm really at a loss as to what's gone wrong. I included an example workflow below in case there's something I'm doing incorrectly beforehand.

import cv2
input_tif = '/path/to/tif'
image = cv2.imread(input_tif)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT_ALT, 1.5, 1, 300, 0.9)

C:\fakepath\test_circle.pngC:\fakepath\test_circle.png