Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use hough circles in cv2 with python?

I have the following code and I want to detect the circle.

   img = cv2.imread("act_circle.png")
   gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
   circles = cv2.HoughCircles(gray,cv2.CV_HOUGH_GRADIENT)

it looks like it does not have the attribute and the error is the following

'module' object has no attribute 'CV_HOUGH_GRADIENT'

Does anybody know where this hidden parameters is?

Thanks

like image 616
Shan Avatar asked Oct 18 '12 14:10

Shan


People also ask

Can Hough transform Detect circles?

The circle Hough Transform (CHT) is a basic feature extraction technique used in digital image processing for detecting circles in imperfect images. The circle candidates are produced by “voting” in the Hough parameter space and then selecting local maxima in an accumulator matrix.

How do I find circles in OpenCV?

Use the OpenCV function HoughCircles() to detect circles in an image.

What is cv2 HoughCircles?

OpenCV provides a built-in cv2.HoughCircles() function that finds circles in a grayscale image using the Hough transform. Below is the syntax. circles = cv2.HoughCircles(image, method, dp, minDist[, param1[, param2[, minRadius[, maxRadius]]]]]) 1.


1 Answers

CV_HOUGH_GRADIENT belongs to the cv module, so you'll need to import that:

import cv2.cv as cv

and change your function call to

circles = cv2.HoughCircles(gray,cv.CV_HOUGH_GRADIENT)
like image 65
jam Avatar answered Oct 30 '22 03:10

jam