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的更多相关文章

  1. python+opencv+pyqt5控制摄像头在Qlabel上显示

    import cv2 import numpy as numpy from PIL import * import sys from PyQt5.QtWidgets import * from PyQ ...

  2. 搭建基于python +opencv+Beautifulsoup+Neurolab机器学习平台

    搭建基于python +opencv+Beautifulsoup+Neurolab机器学习平台 By 子敬叔叔 最近在学习麦好的<机器学习实践指南案例应用解析第二版>,在安装学习环境的时候 ...

  3. .NET + OpenCV & Python + OpenCV 配置

    最近需要做一个图像识别的GUI应用,权衡了Opencv+ 1)QT,2)Python GUI,3).NET后选择了.NET... 本文给出C#+Opencv和Python+Opencv的相应参考,节省 ...

  4. RPi 2B python opencv camera demo example

    /************************************************************************************** * RPi 2B pyt ...

  5. Python+OpenCV图像处理(一)

    Python+OpenCV图像处理(一): 读取,写入和展示图片 调用摄像头拍照 调用摄像头录制视频 1. 读取.写入和展示图片 图像读入:cv2.imread() 使用函数cv2.imread() ...

  6. python opencv show图片,debug技巧

    debug的时候可以直接把图片画出来debug. imshow函数就是python opencv的展示图片的函数,第一个是你要起的图片名,第二个是图片本身.waitKey函数是用来展示图片多久的,默认 ...

  7. Python+OpenCV图像处理(一)——读取显示一张图片

    先在此处先声明,后面学习python+opencv图像处理时均参考这位博主的博文https://blog.csdn.net/u011321546/article/category/7495016/2? ...

  8. Python+opencv 图像拼接

    1.http://www.cnblogs.com/skyfsm/p/7411961.html ,给出了很好地拼接算法实现 2.由于不是Python的,所以简单做了一些翻译转成Python+opencv ...

  9. 【python+opencv】直线检测+圆检测

     Python+OpenCV图像处理—— 直线检测 直线检测理论知识: 1.霍夫变换(Hough Transform) 霍夫变换是图像处理中从图像中识别几何形状的基本方法之一,应用很广泛,也有很多改进 ...

随机推荐

  1. k8s维护常用命令

    k8s维护 1. 不可调度 kubectl cordon k8s-node-1 kubectl uncordon k8s-node-1 #取消 2.驱逐已经运行的业务容器 kubectl drain ...

  2. nginx服务的基本配置

    Nginx在运行时,至少必须加载几个核心模块和一个事件类模块.这些模块运行时所支持的配置项称为基本配置.由于配置项较多,所以把它们按照用户使用时的预期功能分为四类: 用于调试.定位问题的配置项 正常运 ...

  3. 图说jdk1.8新特性(1)--- 函数式接口

    函数式接口 总结起来就以下几点: 如果一个接口要想成为函数接口(函数接口可以直接用lambda方式简化),则必须有且仅有一个抽象的方法(非default和static) 可以通过注解@Function ...

  4. Linux添加硬盘创建新的逻辑卷方式

    有同仁看了上文<Linux添加硬盘扩充已有分区存储空间方式>一文后,提出疑问,现在很多云服务器本来没有逻辑卷,添加数据盘后需要自行添加,如何处理? 此文将以某云服务器为例,详细进行解说. ...

  5. springmvc跨域问题的解决

    如果只想对某个方法开启跨域设置: controller上添加注解: @CrossOrigin(maxAge = 3600) 在特定的方法上添加注解: @CrossOrigin("*" ...

  6. Linux DNS 主从复制

    设置主从DNS的主要是为了冗余,分担压力,防止服务器宕机后,DNS无法正常解析. 配置 master 正常配置DNS服务. 设置主机名 [root@localhost ~]# hostnamectl ...

  7. 个人第五次作业-alpha2测试

    课程属于课程 课程链接 作业要求 作业要求链接 团队名称 你的代码我的发 https://www.cnblogs.com/skrchou/p/11885706.html 测试人名称 颜依婷 测试人学号 ...

  8. python——selenium库的使用

    selenium 是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE(7, 8, 9, 10, 11),Mozilla Fire ...

  9. JQ js 对数组的操作

    1.数组的创建 var arrayObj = new Array(); //创建一个数组 var arrayObj = new Array([size]); //创建一个数组并指定长度,注意不是上限, ...

  10. 【python】raise_for_status()抛出requests.HTTPError错误

    1.首先看下面代码的运行情况 import requests res = requests.get("https://www.csdn.net/eee", headers=head ...