0
我在树莓派上使用OpenCV并使用Python构建。试图制作一个简单的对象跟踪器,使用颜色通过阈值化图像找到对象并找到轮廓来定位质心。当我使用以下代码:在Python中使用findContours和OpenCV
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)
我收到以下错误消息。
Traceback (most recent call last):
File "realtime.py", line 122, in <module>
cnt=contours[0]
IndexError: list index out of range
我已经尝试了一些其他的设置,并得到同样的错误或
ValueError: too many values to unpack
我使用的PiCamera。有关获取质心位置的任何建议?
感谢
ž