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. thrift java first demo

    参考文档:http://thrift.apache.org/ 1.下载需要的文件 地址:http://thrift.apache.org/download  需要下载 thrift-0.12.0.ta ...

  2. 将html版API文档转换成chm格式的API文档

    文章完全转载自: https://blog.csdn.net/u012557538/article/details/42089277 将html版API文档转换成chm格式的API文档并不是一件难事, ...

  3. Oracle SQL函数-NLSSORT

    Syntax 用途: NLSSORT返回字符值char的排序规则键和显式或隐式指定的排序规则.排序规则键是一个用于根据指定的排序规则对char进行排序的字节字符串.排序规则键的属性是:按二进制比较由给 ...

  4. 第二次作业之——AchaoCalculator

    AchaoCalculator(阿超计算器) GIT地址 我的GitHub GIT用户名 Pastrain 学号后五位 62213 博客地址 我的博客地址 作业链接 作业内容 Part.1 配置VS中 ...

  5. springboot全局异常处理(1)

    新建一个类 在类上加一个注解即可 @ControllerAdvice /** * 全局错误处理 * @author sys * */ @ControllerAdvice @ResponseBody p ...

  6. 列车网络智能诊断工具链—MVB智能诊断仪

    由于MVB网络采用分布式网络结构,各组网设备分布在不同电气柜,甚至是在不同车辆上,各组网设备往往来自于不同供应商,这给MVB网络调试及诊断带来了很大的难度.目前MVB网络调试及故障排查,主要是通过仪器 ...

  7. php过滤敏感词

    <?php /**  * 敏感词过滤工具类  * 使用方法  * echo FilterTools::filterContent("你妈的我操一色狼杂种二山食物"," ...

  8. Flume高级之自定义MySQLSource

    1 自定义Source说明 Source是负责接收数据到Flume Agent的组件.Source组件可以处理各种类型.各种格式的日志数据,包括avro.thrift.exec.jms.spoolin ...

  9. Java 锁(学习笔记)

    关于Java 锁的知识整理与回顾(个人笔记): 锁有哪些,分别用来干嘛? Java实现锁有两种方式,synchronized关键字和Lock (1)Lock(可判断锁状态) Lock是基于JDK层面实 ...

  10. Asia Jakarta Regional Contest 2019 I - Mission Possible

    cf的地址 因为校强, "咕咕十段"队获得了EC-final的参赛资格 因为我弱, "咕咕十段"队现在银面很大 于是咕咕十段决定进行训练. 周末vp了一场, 这 ...