1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- from PyQt5.QtCore import QThread
- from PyQt5.QtWidgets import QApplication
- from PyQt5.QtCore import pyqtSignal
- import cv2
- from cores.facepcore import FaceFeatures
- import os
- current_dir = os.path.dirname(__file__)
- avi_file = os.path.join(current_dir, "data/huigexuandetu.mp4")
- class CameraPlay(QThread):
- # 定义信号发送采集的视频图像
- sign_show = pyqtSignal(int, int, int , bytes) # 前面三个是图像高度,宽度,深度,最后是图像数据
- def __init__(self, dev_id):
- super(CameraPlay, self).__init__()
- self.face = FaceFeatures()
- # 完成摄像头初始化
- self.dev = cv2.VideoCapture(avi_file, cv2.CAP_DSHOW) # 避免报一个警告
- # self.dev = cv2.VideoCapture(0) # 避免报一个警告
- self.dev.open(avi_file)
- self.isOver = False
- self.is_landmark = False
-
- # 线程运行函数
- def run(self):
- while not self.isOver:
- # 抓取视频
- status, img = self.dev.read()
- if not status:
- print("读取失败, 结束线程!")
- self.dev.release()
- self.exit(0)
- break
- # landmark处理
- if self.is_landmark:
- self.face.landmark(img)
- # 发送图像到窗体显示
- self.sign_show.emit(img.shape[0], img.shape[1], img.shape[2], img.tobytes())
-
- QThread.usleep(100000)
- def close(self):
- # 用来释放线程与设备
- self.isOver = True
- while self.isRunning(): # 避免提前释放设备导致run函数中的操作报错
- self.isOver = True
- if self.dev.isOpened():
- self.dev.release()
- def landmark(self, is_landmark):
- self.is_landmark = is_landmark
|