camera.py 919 B

12345678910111213141516171819202122232425262728
  1. from PyQt5.QtCore import QThread # 多线程实现多任务
  2. import cv2
  3. class CameraDev:
  4. def __init__(self):
  5. super(CameraDev,self).__init__()
  6. self.camera = cv2.VideoCapture(0,cv2.CAP_DSHOW) #摄像头编号从0开始
  7. self.isSave = False
  8. #线程的任务
  9. def run(self):
  10. #摄像头的操作
  11. # 1.打开摄像头
  12. while True:
  13. # 2.循环抓取视频帧
  14. status,img = self.camera.read()
  15. print(status,img.shape)
  16. if status:
  17. img = cv2.cvtColor(img,cv2,COLOR_RGB2BGR)
  18. if not self.isSave:
  19. cv2.imwrite("2,jpg",img)
  20. self.isSave = True
  21. # 3.显示到窗体
  22. print("视频处理")
  23. QThread.usleep(100000)
  24. # self.camera.close() #关闭摄像头
  25. # self.camera.release() #释放设备