pyqt5 使用cv2 顯示圖片,攝像頭的實(shí)例
更新時(shí)間:2019年06月27日 20:13:14 作者:ShellCollector
今天小編就為大家分享一篇pyqt5 使用cv2 顯示圖片,攝像頭的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
如下所示:
#! /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) # 轉(zhuǎn)為QImage對(duì)象 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毫秒發(fā)送一次信號(hào) 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 顯示圖片,攝像頭的實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python numpy多維數(shù)組實(shí)現(xiàn)原理詳解
這篇文章主要介紹了python numpy多維數(shù)組實(shí)現(xiàn)原理詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03TensorFlow Autodiff自動(dòng)微分詳解
這篇文章主要介紹了TensorFlow Autodiff自動(dòng)微分詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-07-07Python圖像處理之直線和曲線的擬合與繪制【curve_fit()應(yīng)用】
這篇文章主要介紹了Python圖像處理之直線和曲線的擬合與繪制,結(jié)合實(shí)例形式分析了Python曲線擬合相關(guān)函數(shù)curve_fit()的使用技巧,需要的朋友可以參考下2018-12-12python如何通過twisted搭建socket服務(wù)
這篇文章主要介紹了python如何通過twisted搭建socket服務(wù),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-02-02Python數(shù)據(jù)分析之NumPy常用函數(shù)使用詳解
本篇將介紹怎樣從文件中載入數(shù)據(jù),以及怎樣使用NumPy的基本數(shù)學(xué)和統(tǒng)計(jì)分析函數(shù)、學(xué)習(xí)讀寫文件的方法,并嘗試函數(shù)式編程和NumPy線性代數(shù)運(yùn)算,來學(xué)習(xí)NumPy的常用函數(shù),需要的可以參考一下2022-05-05Python代碼實(shí)現(xiàn)http/https代理服務(wù)器的腳本
這篇文章主要介紹了Python代碼做出http/https代理服務(wù)器,啟動(dòng)即可做http https透明代理使用,通過幾百行代碼做出http/https代理服務(wù)器代碼片段,需要的朋友可以參考下2019-08-08