python opencv PyQt5(python能做什么)

网友投稿 339 2022-09-03


python opencv PyQt5(python能做什么)

import cv2import numpy as npimport sysfrom PyQt5.QtGui import *from PyQt5.QtCore import *from PyQt5.QtWidgets import *import datetimeclass Video(): def __init__(self, capture): self.capture = capture capture.set(3,960) # set Width capture.set(4,2560) # set Height self.currentFrame = np.array([]) def captureFrame(self): ret, readFrame = self.capture.read() return readFrame def captureNextFrame(self): ret, readFrame = self.capture.read() if (ret == True): readFrame=cv2.resize(readFrame, (int(960 / 4), int(2560 / 4))) #cv2.waitKey(1) self.currentFrame = cv2.cvtColor(readFrame, cv2.COLOR_BGR2RGB) def convertFrame(self): try: height, width = self.currentFrame.shape[:2] #print(height, width) img = QImage(self.currentFrame, width, height, QImage.Format_RGB888) img = QPixmap.fromImage(img) #self.previousFrame = self.currentFrame return img except: return Noneclass win(QMainWindow): def __init__(self, parent=None): super(win,self).__init__() self.setGeometry(250, 80, 960, 2560) self.setWindowTitle('camera') self.video = Video(cv2.VideoCapture(1)) print(self.video) self._timer = QTimer(self) 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() def play(self): try: nowTime=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') print(nowTime) self.video.captureNextFrame() self.videoFrame.setPixmap(self.video.convertFrame()) self.videoFrame.setScaledContents(True) except TypeError: print('No Frame')if __name__ == '__main__': app = QApplication(sys.argv) win = win() win.show() sys.exit(app.exec_())


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:安装python 3.7(安装python第三方库的工具)
下一篇:关于maven依赖 ${xxx.version}报错问题
相关文章

 发表评论

暂时没有评论,来抢沙发吧~