使用cv2.VideoCapture时出现AttributeError

我想使用cv2.VideoCapture,但得到AttributeError

我的代码:

import cv2
import numpy as np

cap=cv2.VideoCapture(0)
while(True):
    if cap.isOpened():
        ret,frame=cap.read()
    else:
        ret=False
        ret,frame1=cap.read()
        ret,frame2=cap.read()
        ret,frame=cap.read()
        d=cv2.absdiff(frame1,frame2)
        grey=cv2.cvtColor(d,cv2.COLOR_BGR2GRAY)
        blur=cv2.GaussianBlur(grey,(5,5),0)
        ret,th=cv2.threshold(blur,130,255,cv2.THRESH_BINARY)
        dil=cv2.dilate(th,np.ones((3,3),np.unit8),iterations=2)
        img,c,h=cv2.findContours(dil,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
        cv2.Contours(frame1,-1,(0,0),2)
        cv2.imshow("inter",grey)

        if cv2.waitKey(40)==27:
            break
        frame1=frame2
        ret,frame2=cap.read()
        cv2.destroyAllWindows()
        cap.release()

遇到错误:

AttributeError: 'module' object has no attribute 'VideoCapture'

有什么办法可以解决吗?

xxxcs001 回答:使用cv2.VideoCapture时出现AttributeError

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3145195.html

大家都在问