运行python代码进行眼动检测时出现错误, 我遵循https://www.youtube.com/watch?v=kbdbZFT9NQI
中的步骤#https://www.youtube.com/watch?v=kbdbZFT9NQI
import cv2
import numpy
cap = cv2.VideoCapture("C:\\Users\\sinsbv\\Desktop\\Project\\Kaggle\\Tutorial_Mini_Project\\open_cv\\eye_recording.flv")
while True:
ret,frame = cap.read()
roi = frame[269:795,537:1416]
gray_roi = cv2.cvtColor(roi,cv2.COLOR_BGR2GRAY)
gray_roi = cv2.GaussianBlur(gray_roi , (7 , 7) ,0)
_,threshold = cv2.threshold(gray_roi,5,255,cv2.THRESH_BINARY_INV)
_, contours = cv2.findContours ( threshold , cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE )
for cnt in contours:
# ctr = numpy.array(cnt).reshape((-1,1,2)).astype(numpy.int32)
cv2.drawContours(roi,cnt , -1,(0,0,255) ,3)
cv2.imshow("threshold" , threshold)
cv2.imshow("gray roi" , gray_roi)
cv2.imshow("Roi" , roi)
key = cv2.waitKey(30)
if key == 27:
break
cv2.destroyAllWindows()
预期结果-眼动检测 实际结果-错误以下,
回溯(最近通话最近): 文件“ C:/Users/sinsbv/Desktop/Project/Kaggle/Tutorial_Mini_Project/open_cv/open_cv.py”,第14行,在 cv2.drawContours(roi,cnt,-1,(0,0,255),3) cv2.error:OpenCV(4.0.0)C:\ projects \ opencv-python \ opencv \ modules \ imgproc \ src \ drawing.cpp:2509:error:(-215:Assertion failed)npoints> 0 in function'cv: :drawContours'