OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type)
HoughCircles is expecting a numpy array as its first argument. The above error means that it didn't get it. The problem is that your input file is a jpg and the code is asking for a png:
img = cv2.imread('opencv-logo.png',0)
When a file does not exist, cv2.imread
quietly returns a None
. Consequently, img
is set to None
. When cv2.HoughCircles
receives that value as its first argument, it raises the error.
To solve the problem, replace the above line with:
img = cv2.imread('opencv-logo.jpg',0)
With that change, your code runs, finds many many potential circles, and produces the image:
You can control the number of circles found by changing the various parameters. Increasing the canny parameters to 70 and 50, for example, will reduce the number of circles found to seven.