パイソンOpenCVのPyQt5

輸入CV2の
NPのようインポートnumpyの
輸入SYS 
PyQt5.QtGuiのインポート*から
PyQt5.QtCoreのインポート*からの
インポート* PyQt5.QtWidgetsから
インポート日時


:クラスのビデオ()
    デフ__init __(自己、キャプチャ):
        self.capture =キャプチャ
        capture.set( 3,960)#設定幅
        capture.set(4,2560)#セット高
        self.currentFrame = np.array([])

    DEF captureFrame(自己):
        RET、readFrame = self.capture.read()
        readFrame戻り

    DEF captureNextFrameを(自己):
        RET、readFrame = self.capture.read()
        (RET)真の==場合:

            readFrame = cv2.resize(readFrame、(INT(4分の960)、INT(4分の2560)))
            
            #1 cv2.waitKey(1)
            self.currentFrame = cv2.cvtColor(readFrame、cv2.COLOR_BGR2RGB)

    convertFrame DEF(自己) :
        試す:
            高さ、幅= self.currentFrame.shape [2] 
            #print(高さ、幅)
            IMG = QImageの(self.currentFrame、幅、高さ、QImage.Format_RGB888)
            IMG = QPixmap.fromImage(IMG)
            #selfを。 previousFrame = self.currentFrame 
            戻りIMG 
        :除く
            なし返す


クラス優勝(QMainWindowを):
    デフ__init __(自己、親=なし):
        スーパー(勝利、自己).__のinit __()
        self.setGeometry(250、80、960、2560)
        self.setWindowTitle( 'カメラ')
        self.video =ビデオ(cv2.VideoCapture(1))
        プリント(self.video)
        self._timer = QTimer(自己)
        self._timer .timeout.connect(self.play)
        self._timer.start(2)
        self.update()
        self.videoFrame = QLabel( 'VideoCapture')
        self.videoFrame.setAlignment(Qt.AlignCenter)
        self.setCentralWidget(self.videoFrame)
        self.ret、self.capturedFrame = self.video.capture.read()

    デフ(自己)を再生:
        試してみてください
            。nowTime = datetime.datetime.now()はstrftimeを( '%Y-%M-%D%H:% M:%S ')
            プリント(nowTime)
            self.video.captureNextFrame()
            self.videoFrame.setPixmap(self.video.convertFrame())
            self.videoFrame.setScaledContents(真)
        TypeError例外を除い:
            プリント( 'いいえフレーム')


であれば__name__ == '__main__':
    アプリ=はQApplication (sys.argvの)
    勝利=ウィン()
    win.show()
    sys.exit(app.exec_())

  

おすすめ

転載: www.cnblogs.com/ahuo/p/11247294.html