pyqt5 使用cv2 显示图片,摄像头
来源:互联网 发布:php淘宝互刷平台源码 编辑:程序博客网 时间:2024/05/01 19:21
#! /usr/bin/python3
# coding = utf-8
# from PyQt5 import QtGui,QtCore,Qt
import sys
from PyQt5.QtCoreimport Qt,pyqtSignal,QSize,QRect,QMetaObject,QCoreApplication,pyqtSlot,QPropertyAnimation,QThread
from PyQt5.QtGuiimport QIcon,QFont, QPixmap, QPainter,QImage
from PyQt5.QtWidgetsimport QMainWindow,QApplication
import cv2
from gevent.libev.corecextimport SIGNAL,time
from qtpy importQtCore
class mycsms(QMainWindow):
def __init__(self):
super(mycsms,self).__init__()
self.setupUi(self)
self.image= QImage()
self.device= cv2.VideoCapture(0)
self.playTimer= Timer("updatePlay()")
self.connect(self.playTimer,SIGNAL("updatePlay()"),self.showCamer)
# 读摄像头
def showCamer(self):
if self.device.isOpened():
ret, frame=self.device.read()
else:
ret =False
# 读写磁盘方式
# cv2.imwrite("2.png",frame)
#self.image.load("2.png")
height,width, bytesPerComponent= frame.shape
bytesPerLine = bytesPerComponent* width
# 变换彩色空间顺序
cv2.cvtColor(frame,cv2.COLOR_BGR2RGB,frame)
# 转为QImage对象
self.image= QImage(frame.data,width, height, bytesPerLine,QImage.Format_RGB888)
self.view.setPixmap(QPixmap.fromImage(self.image))
if __name__ =="__main__":
app = QApplication(sys.argv)
myshow = mycsms()
myshow.playTimer.start()
myshow.show()
sys.exit(app.exec_())
# 线程类:
class Timer(QtCore.QThread):
def __init__(self,signal="updateTime()",parent=None):
super(Timer,self).__init__(parent)
self.stoped=False
self.signal= signal
self.mutex= QtCore.QMutex()
def run(self):
with QtCore.QMutexLocker(self.mutex):
self.stoped=False
while True:
if self.stoped:
return
self.emit(QtCore.SIGNAL(self.signal))
#40毫秒发送一次信号
time.sleep(0.04)
def stop(self):
with QtCore.QMutexLocker(self.mutex):
self.stoped=True
def isStoped(self):
with QtCore.QMutexLocker(self.mutex):
return self.stoped
- pyqt5 使用cv2 显示图片,摄像头
- opencv学习——cv2.imshow()显示图片
- Qt v4l2显示摄像头图片
- 使用GraphEdit显示摄像头
- 使用摄像头捕获图片
- python3下使用cv2.imwrite存储带有中文路径图片
- PyQt5简易入门指南02,简单图片显示程序
- USB摄像头图片采集+QT显示(二)
- matplotlib.pyplot与cv2、Image.open 读取图片显示的差异
- 如何用cv2读取图片
- PyQt5实时显示Camera
- opencv cv2.read 读取不了cv2.imwrite 写入的图片
- 使用Python import cv2失败 显示ImportError: DLL load failed:找不到指定的模块。
- cv2
- 任务二:使用GraphEdit显示摄像头
- 使用Qt+OpenCV+VideoInput 显示摄像头图像
- MFC中使用OpenCV显示摄像头图像
- openCV库cv2的使用
- poj 2546
- 类型错误导致的bug
- Ubuntu16.04安装Hadoop单机和伪分布式环境超详细
- Java 虚拟机
- git添加tag
- pyqt5 使用cv2 显示图片,摄像头
- 创业失败后的他们,是怎么找工作的?
- django配置URL
- 基于JavaMail的Java邮件开发
- HDU 1061
- AOP
- A001-《操作系统:设计与实现(第三版)》学习第一周感想
- jquery.cookie() 方法的使用(读取、写入、删除)(转)
- LeetCode<Day2>PerfectNumber