Opencv,函数问题TypeError: Incorrect type of self (must be 'VideoCapture' or its derivative)

部分代码

vc = cv2.VideoCapture('./test.mp4')
#省略部分。。。。
while True:
    ret, frame = vc.read()
    if frame is None:
        break

报错显示:

ret, frame = vc.read()
TypeError: Incorrect type of self (must be 'VideoCapture' or its derivative)

瞅瞅
https://blog.csdn.net/Sumehay/article/details/85989519

给的代码和错误信息不完整,看错误提示应该是在某个类的方法里定义的函数,调用时参数传入类型不对导致的。

你这报错应该是视频的路径不对吧,导致你的VideoCapture返回None?或者是你对VC进行了修改导致这个问题也有可能。要么代码和报错都不完整,只能你自己debug一下看看了,特别是路径先对的情况下,看下哪里导致你的vc地址变了

1、你电脑是windows还是Linux,windows的话,('./test.mp4')改为('\test.mp4')这个视频文件和本py文件在同一级下是改这样的
2、 if frame is None:
break
改为
cv2.imshow("video", frame)
if ret is None:
break

你试试吧