资源简介
Pythone+pyq5+opencv 多线程模式调用摄像头。这样你在识别人脸的时候,可以通过线程输出结果,这时候摄像头保持流畅视频。
代码片段和文件信息
“““
In this example we demonstrate how to create simple camera viewer using Opencv3 and PyQt5
Author: Berrouba.A
Last edited: 21 Feb 2018
“““
# import system module
import sys
import time
# import some PyQt5 modules
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QWidget
from PyQt5.QtGui import QImage
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import QTimer
from PyQt5.QtCore import *
# import Opencv module
import cv2
from ui_main_window import *
class Mythread(QThread):
# 定义信号定义参数为str类型
breakSignal = pyqtSignal(QPixmap)
def __init__(self parent=None):
super().__init__(parent)
# 下面的初始化方法都可以,有的python版本不支持
super(Mythread self).__init__()
self.cap = cv2.VideoCapture(0)
def run(self):
while True:
ret image = self.cap.read()
# convert image to RGB format
image = cv2.cvtColor(image cv2.COLOR_BGR2RGB)
# get image infos
height width channel = image.shape
step = channel * width
# create QImage from image
qImg = QImage(image.data width height step QImage.Format_RGB888)
# show image in img_label
self.breakSignal.emit(QPixmap.fromImage(qImg))
#self.ui.image_label.setPixmap(QPixmap.fromImage(qImg))
‘‘‘
for i in range(2000000):
# 发出信号
print(12)
a=[ii+1]
self.breakSignal.emit(str(i))
# 让程序休眠
time.sleep(0.5)
‘‘‘
class Mythread2(QThread):
# 定义信号定义参数为str类型
breakSignal2 = pyqtSignal(str)
def __init__(self parent=None):
super().__init__(parent)
# 下面的初始化方法都可以,有的python版本不支持
super(Mythread2 self).__init__()
def run(self):
for i in range(2000000):
# 发出信号
print(12)
a=[ii+1]
self.breakSignal2.emit(str(i))
# 让程序休眠
time.sleep(0.5)
class MainWindow(QWidget):
# class constructor
def __init__(self):
# call QWidget constructor
super().__init__()
self.ui = Ui_Form()
self.ui.setupUi(self)
#按钮启动现成
self.ui.control_bt.clicked.connect(self.controlTimer)
# 创建线程
self.thread = Mythread()
# 连接信号
self.thread.breakSignal.connect(self.chuli)
# 开始线程
# 创建线程
self.thread2 = Mythread2()
self.thread2.breakSignal2.connect(self.chuli2)
self.thread2.start()
def chuli(selfqImg):
self.ui.image_label.setPixmap(qImg)
def chuli2(selfmsg):
self.ui.control_bt.setText(msg)
# start/stop timer
def controlTimer(self):
self.thread.start()
if __name__ == ‘__main__‘:
app = QApplication(sys.argv)
# create and show mainWindow
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec_())
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 771499 2018-10-19 11:28 camView\build\main_window\ba
文件 1036 2018-10-19 11:28 camView\build\main_window\main_window.exe.manifest
文件 3159 2018-10-22 18:19 camView\main_window.py
文件 981 2018-10-19 11:28 camView\main_window.spec
文件 325 2018-02-22 13:17 camView\README.md
文件 1344 2018-02-22 13:17 camView\ui_main_window.py
文件 882 2018-02-22 13:17 camView\ui_main_window.ui
文件 1365 2018-02-22 13:17 camView\__pycache__\ui_main_window.cpython-35.pyc
文件 1217 2018-10-18 10:54 camView\__pycache__\ui_main_window.cpython-36.pyc
目录 0 2018-10-19 11:28 camView\build\main_window
目录 0 2018-10-19 11:26 camView\build
目录 0 2018-10-19 11:26 camView\dist
目录 0 2018-10-18 10:54 camView\__pycache__
目录 0 2018-10-19 11:26 camView
----------- --------- ---------- ----- ----
781808 14
- 上一篇:pcap-1.1.win32-py2.7.exe
- 下一篇:爬取瓜子二手车.py
相关资源
- 基于Python的双路视频传输及双显示系
- python调用opencv实现人脸识别的简单D
- 树莓派小车物体追踪
- OpenCV动作识别
- 基于OpenCV的python颜色提取
- 火焰检测代码python
- python,Opencv实现的车牌识别定位及分
- python+opencv实现初步手势识别源码(本
- opencv实时识别指定物体
- OpenCV 3.x with Python By Example 2nd .txt
- 基于Python-opencv的车牌识别
- 基于OpenCV SIFT的指纹识别算法 python实
- Python+OpenCV实现Selective Search算法
- python opencv 图片去噪
- Python+OpenCV实现行人检测含配置说明
- python+opencv识别出物体颜色红白黑蓝绿
- opencv_python-3.4.3.18-cp37-cp37m-linux_armv7l
- 基于OpenCV的人脸识别-python3.zip
- pyinstaller打包OpenCV错误解决
- Python OpenCV 图像使用-
- Python OpenCV 类型转换-
- Python给照片换底色(基于opencv模块)
- OPENCV视频头调用
- 基于opencv和tkinter的图像处理GUI-源代码
- Python OpenCV 图像轮廓-.zip
- Python OpenCV 形态学操作-.zip
- Python OpenCV 傅里叶变换-.zip
- Python OpenCV 图像运算-.zip
- Python OpenCV 图像处理基础-.zip
- Python OpenCV 直方图-.zip
评论
共有 条评论