self.cap = cv2.VideoCapture(str('./video1/video1logo.avi'))
def timer_TimeOut(self):
frame_count = self.cap.get(cv2.CAP_PROP_FRAME_COUNT)
#print(frame_count)
self.n += 1
if self.n > frame_count:
self.n = 1
self.timer1.stop()
# 视频txt帧播放
ret, frame = self.cap.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
img = QtGui.QImage(frame, frame.shape[1], frame.shape[0], QtGui.QImage.Format_RGB888)
self.pm = QPixmap.fromImage(img)
self.lblpic.setPixmap(self.pm)
首先进行判断视频路径格式、读取的格式都没问题
发现是每次视频读取完毕的时候报错,cv2.cvtcolor中的frame变成了空,所以需要在视频读取结束frame变为空的时候重新循环
在if判断语句的末尾加上
self.cap = cv2.VideoCapture(str('./video1/video1logo.avi'))
让其重新读取视频文件就解决啦