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。有關獲取質心位置的任何建議?
感謝
ž