camera.py 897 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. #线程的任务
  8. def run(self):
  9. #摄像头的操作
  10. # 1.打开摄像头
  11. while True:
  12. # 2.循环抓取视频帧
  13. status,img = self.camera.read()
  14. print(status,img.shape)
  15. if status:
  16. # img = cv2.cvtColor(img,cv2.COLOR)
  17. if not solf.isSave:
  18. if status:
  19. cv2.imwrite("1.jpg",img)
  20. self.isSave = True
  21. # 3.显示到窗体
  22. print("视频处理")
  23. QThread.usleep(100000)
  24. # self.camera.close() #关闭摄像头
  25. # self.camera.release() #释放设备