最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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í)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

宣城市| 洪洞县| 体育| 教育| 顺义区| 远安县| 遂宁市| 宜君县| 榆中县| 红河县| 平武县| 张家口市| 北辰区| 祁连县| 赤壁市| 高安市| 神农架林区| 银川市| 会东县| 信丰县| 彰武县| 隆林| 石门县| 牡丹江市| 杂多县| 上饶市| 延安市| 曲阜市| 安平县| 咸宁市| 庆城县| 江津市| 高阳县| 武陟县| 航空| 从化市| 合水县| 莆田市| 新田县| 大兴区| 泗洪县|