pyqt5 使用cv2 显示图片,摄像头的实例
2019-06-27 20:13
1126 查看
如下所示:
#! /usr/bin/python3 # coding = utf-8 # from PyQt5 import QtGui,QtCore,Qt import sys from PyQt5.QtCore import Qt,pyqtSignal,QSize,QRect,QMetaObject, QCoreApplication, pyqtSlot,QPropertyAnimation,QThread from PyQt5.QtGui import QIcon, QFont, QPixmap, QPainter, QImage from PyQt5.QtWidgets import QMainWindow, QApplication import cv2 from gevent.libev.corecext import 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 显示图片,摄像头的实例就是小编分享给大家的全部内容了,希望能给大家一个参考
您可能感兴趣的文章:
相关文章推荐
- pyqt5 使用cv2 显示图片,摄像头
- 使用内置摄像头并优化显示结果大图片的方法
- Android深入浅出系列之实例应用—简单的手指拖动图片,图片滑来滑去显示应用Gallery和BaseAdapter以及ImageView的使用
- UITableView 系列一 :基本使用方法 (显示,删除,添加图片,添加样式等) (实例)
- UITableView 系列一 :基本使用方法 (显示,删除,添加图片,添加样式等) (实例)
- Android深入浅出系列之实例应用—简单的手指拖动图片,图片滑来滑去显示应用Gallery和BaseAdapter以及ImageView的使用
- pyqt 使用cv2 显示摄像头
- pyqt5 从本地选择图片 并显示在label上的实例
- pyqt5 使用label控件实时显示时间的实例
- Android深入浅出系列之实例应用—简单的手指拖动图片,图片滑来滑去显示应用Gallery和BaseAdapter以及ImageView的使用
- emWin 2天速成实例教程014_BMP位图图片显示以及位图皮肤的使用方法
- 使用asp.net将图片上传并存入SqlServer中,然后从SqlServer中读取并显示出来
- video4linux(v4l)使用摄像头的实例基础教程与体会(二)
- 学习使用资源文件[3] - 用 Image 显示资源中的图片
- 使用PhotoShop分割图片并通过Html组合显示
- 使用下拉列表显示图片
- 使用ADO ACCESS ImageEn 动态,显示图片,导入图片,导出图片,删除图片
- 母板页图片使用相对路径显示问题
- Response.AddHeader使用实例收集 如何做下载,下载中文显示乱码怎么办 ContentType类型大全