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. Java -- springboot 配置 freemarker

    1.添加依赖 org.springframework.boot spring-boot-starter-freemarker 2.配置application.properties spring.fre ...

  2. 个人项目WC(Python实现)

    一.GitHub地址 https://github.com/hoka-17/WC 二.PSP表格 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际 ...

  3. java-Java实现mysql事务处理操作

    数据库事务(简称:事务)是数据库管理系统执行过程中的一个逻辑单位,由一个有限的数据库操作序列构成. 并非任意的对数据库的操作序列都是数据库事务.数据库事务拥有以下四个特性,习惯上被称之为ACID特性. ...

  4. Windows安装MySQL5.7教程

    导读: 我们日常学习可能会需要在本地安装MySQL服务,也遇到过小伙伴探讨关于Windows系统安装MySQL的问题.在这里建议大家安装MySQL5.7版本,当然想尝试8.0版本的同学也可以参考安装. ...

  5. Oracle 11g RAC to RAC ADG搭建(一)采用rman备份恢复方式

    (一)基础环境   主库 备库 操作系统 RedHat6.7 RedHat6.7 服务器名称 primarydb1primarydb2 standbydb1standbydb2 IP地址规划 192. ...

  6. 异常详细信息: System.MissingMethodException: 无法创建抽象类。

    asp.net mvc 在使用post向后端传送json数据时报异常,在路由配置中添加如下即可 public static void RegisterRoutes(RouteCollection ro ...

  7. BootstrapValidator 表单验证超详细教程

    一. 引入js 和css文件 在有jquery和bootstrap的页面里引入 bootstrapValidator.js bootstrapValidator.css 链接: https://pan ...

  8. Python并发编程-concurrent包

    Python并发编程-concurrent包 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.concurrent.futures包概述 3.2版本引入的模块. 异步并行任务编程 ...

  9. Flooded! UVA - 815 (sort排序)

    错了好多遍,不知道为啥出错,如果有大神发现,请求指点!!! 附错误代码(错的不知道怎么回事): #include<iostream> #include<cstdio> #inc ...

  10. Kotlin反射实践操作详解

    继续对反射进行实战. 获取构造方法: 先定义一个主构造方法,2个次构造方法,接下来咱们用反射来获取一下构造方法: 其结果: [fun <init>(kotlin.Int, kotlin.S ...