12345678910111213141516171819202122232425262728 |
- from PyQt5.QtCore import QThread # 多线程实现多任务
- import cv2
- class CameraDev:
- def __init__(self):
- super(CameraDev,self).__init__()
- self.camera = cv2.VideoCapture(0,cv2.CAP_DSHOW) #摄像头编号从0开始
- #线程的任务
- def run(self):
- #摄像头的操作
- # 1.打开摄像头
- while True:
- # 2.循环抓取视频帧
- status,img = self.camera.read()
- print(status,img.shape)
- if status:
- # img = cv2.cvtColor(img,cv2.COLOR)
- if not solf.isSave:
- if status:
- cv2.imwrite("1.jpg",img)
- self.isSave = True
- # 3.显示到窗体
- print("视频处理")
- QThread.usleep(100000)
- # self.camera.close() #关闭摄像头
- # self.camera.release() #释放设备
|