IndexError:列表索引超出范围,opencv

时间:2016-12-05 23:12:43

标签: python opencv numpy

opencv,我有一个问题:

import cv2
import numpy as np
import time

cap=cv2.VideoCapture(0)

while(1):
    ret,frame=cap.read()

    gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    ret, thresh = cv2.threshold(gray, 35, 255,0)
    cv2.imshow('thresh',thresh)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    image,contours,hierarchy = cv2.findContours(thresh,2,1)
    img=cv2.drawContours(frame,contours,-1,(0,0,255),1)
    print(contours[0])
    cnt=contours[0]

    hull=cv2.convexHull(cnt,returnPoints=False)
    defects=cv2.convexitDefects(cnt,hull)

    for i in range(defects.shape[0]):
        s,e,f,d = defects[i,0]
        start = tuple(cnt[s][0])
        end = tuple(cnt[e][0])
        far = tuple(cnt[f][0])
        cv2.line(img,start,end,[0,255,0],2)
        cv2.circle(frame,far,5,[0,0,255],-1)

    cv2.imshow('contours',frame)

cap.release()
cv2.destroyAllWindows()

当我运行时,我得到:IndexError: list index out of range

0 个答案:

没有答案