gpt4 book ai didi

pyqt5 使用cv2 显示图片,摄像头的实例

转载 作者:qq735679552 更新时间:2022-09-28 22:32:09 25 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章pyqt5 使用cv2 显示图片,摄像头的实例由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

如下所示:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /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 显示图片,摄像头的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我.

原文链接:https://blog.csdn.net/jacke121/article/details/78765178 。

最后此篇关于pyqt5 使用cv2 显示图片,摄像头的实例的文章就讲到这里了,如果你想了解更多关于pyqt5 使用cv2 显示图片,摄像头的实例的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com