import cv2
import numpy as np
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import datetime
class 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 None
class 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_())
python opencv PyQt5
原创
©著作权归作者所有:来自51CTO博客作者ahuoheng的原创作品,请联系作者获取转载授权,否则将追究法律责任
python opencv PyQt5
https://blog.51cto.com/ahuo/5317171
python opencv PyQt5
https://blog.51cto.com/ahuo/5317171
下一篇:安装python 3.7
举报文章
请选择举报类型
内容侵权
涉嫌营销
内容抄袭
违法信息
其他
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
OpenCV 简单的人脸识别
OpenCV中自带已训练好的检测器,包括面部,眼睛,猫脸等,都保存在XML文件中,我们可以通过以下程序找到他们
opencv python 人工智能 xml 人脸识别 -
Python+OpenCV 轻松实现人脸识别签到考勤系统
大家好,今天本文给大家利用Python+OpenCV 人脸
opencv python 计算机视觉 人脸识别 数据 -
人脸检测(Python dlib)
code:https://github.com/davisking/dlib文章目录介绍编
python opencv 深度学习 sed 加载 -
Opencv与python实现多目标跟踪(一)-PaddleDetection目标检测
使用PaddleDetection模型快速实现目标检测模型,再将模型转为onnx,使用cv2.dnn读取模型
目标跟踪 opencv python paddle 目标检测 -
ROS2+Gazebo+OpenCV之mobot仿真视觉传感器
之前介绍了使用笔记本或者USB摄像头的一些方法,比如
opencv 计算机视觉 人工智能 ROS2 Gazebo