Hi I'm new with python and OpenCV. With the code below I'm trying to stream from a web camera and detect circles. I'm trying to extract the center of the circle and the radius in the for loop and then draw the circle. Every time I do that I get the following error.
ValueError: too many values to unpack (expected 3)
Any help about why the code dosnt work would be greatly appreciated. Thanks
import cv2
import numpy as np
import sys
cap = cv2.VideoCapture(1)
while(True):
gray = cv2.medianBlur(cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2GRAY),5)
circ = cv2.HoughCircles(gray,cv2.HOUGH_GRADIENT,1,20,param1=50,param2=30,
minRadius=0,maxRadius=0)
for(x,y,r) in circ:
cv2.circle(gray,int(x),int(y),int(r),(0,255,0),2)
cv2.imshow('video',gray)
if cv2.waitKey(1)==27:# esc Key
break
cap.release()
cv2.destroyAllWindows()
Edit: The Traceback
Traceback (most recent call last): File "C:/Documents/pythonproj/webcameratest.py", line 11, in for(x,y,r) in circ: TypeError: 'NoneType' object is not iterable
cv2.circ
is a valid OpenCV function in Python API. Also it would be helpful if you paste the full error traceback, which includes the line number where the error is happening. – ZdaRfor(x,y,r) in circ: TypeError: 'NoneType' object is not iterable
, which clearly means thatcv2.HoughCircles()
is simply returningNone
. – ZdaR