I'm using OpenCV on the raspberry pi and building with Python. Trying to make a simple object tracker that uses color to find the object by thresholding the image and finding the contours to locate the centroid. When I use the following code:
image=frame.array
imgThresholded=cv2.inRange(image,lower,upper)
_,contours,_=cv2.findContours(imgThresholded,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cnt=contours[0]
Moments = cv2.moments(cnt)
Area = cv2.contourArea(cnt)
I get the following error.
Traceback (most recent call last):
File "realtime.py", line 122, in <module>
cnt=contours[0]
IndexError: list index out of range
I've tried a few other settings and get the same error or
ValueError: too many values to unpack
I'm using the PiCamera. Any suggestions for getting centroid position?
Thanks
Z