在这里我们基于Python-Windows+Pycharm+PyQt5基础环境配置,1000%解决你的环境问题(一)的学习,我们搭建好PyQt5的基础环境,这里我们将进行制作一个简单的软件;
基础环境:
- Windows10
- pycharm2019.3.4
- python3.7.3
- PyQt5
- OpenCV4.5.1
这里我们将使用PyQt5创建一个获取摄像头的软件;
废话不多说,上代码
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import cv2
import sys
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.initTimer()
def initTimer(self):
self.timer = QTimer(self)
self.timer.timeout.connect(self.show_pic)
def show_pic(self):
ret, img = self.vc.read