This question already has an answer here:
- how to use hough circles in cv2 with python? 3 answers
I have a small test code block trying to process a simple photo with a ball in it:
#!/usr/local/bin/python import cv2 import numpy as np img = cv2.imread("b.jpg") gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) circles = cv2.HoughCircles(gray,cv2.CV_HOUGH_GRADIENT)
When I try to run this I get:
AttributeError: 'module' object has no attribute 'HOUGH_GRADIENT'
I've been installing and reinstalling for two days trying to figure out whats wrong. Any help or pointers would be appreciated!
add this line :
import cv2.cv as cv and change
circles = cv2.HoughCircles(gray,cv.CV_HOUGH_GRADIENT)
cv.CV_HOUGH_GRADIENT in place of
This will solve the
AttributeError that you were getting but still you'll get a type error, you'll have to provide arguments for
minDist (arguments at pos 3 and pos 4) and that you can give accordingly.(Here I've given 1 and 10)
#!/usr/local/bin/python import cv2 import cv2.cv as cv import numpy as np img = cv2.imread("test.jpg") gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) circles = cv2.HoughCircles(gray,cv.CV_HOUGH_GRADIENT, 1, 10)
also please see a similar problem solved here: