pyqt5 使用opencv cv2展示视频及resize视频大小

 def on_display(self):

        while self.cap.isOpened():
            success, frame = self.cap.read()
            # print('video readed')

            if success == False:
                print("play finished")  # 判断本地文件播放完毕
                break
              
            #视频的resize操作
            frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
            newRate = int(frame.shape[0]/400) #求出resize的比值
            newHeight = int(frame.shape[0]/newRate)	#resize后的高和宽
            newWidth = int(frame.shape[1]/newRate) 
            newFrame = cv2.resize(frame,(newWidth,newHeight),interpolation=cv2.INTER_AREA)
            bytesPerLine = 3*newWidth
            temp_image = QImage(newFrame.data, newWidth, newHeight, bytesPerLine,QImage.Format_RGB888)
            # temp_image = QImage(rgb.flatten(), width, height, QImage.Format_RGB888)
            temp_pixmap = QPixmap.fromImage(temp_image)

            self.page3_videolabel.setPixmap(temp_pixmap)
            # self.video_label.setScaledContents(True)
            cv2.waitKey(int(1000 / self.frameRate))
            # 判断关闭事件是否已触发
            if True==self.continueEvent1.is_set():
                self.continueEvent1.clear()
                self.b=1
                while self.b==1:
                    if True == self.continueEvent1.is_set():
                        self.continueEvent1.clear()
                        self.b=0
            if True == self.stopEvent.is_set():
                # 关闭事件置为未触发,清空显示label
                break
        self.cap.release()
        self.stopEvent.clear()

参考博客:http://www.manongjc.com/detail/7-idbkllykcnrotfn.html

你可能感兴趣的:(pyqt5 使用opencv cv2展示视频及resize视频大小)