Facebook
From SHA, 5 Days ago, written in Python.
Embed
Download Paste or View Raw
Hits: 26
  1. import numpy as np
  2. import cv2
  3. import time
  4.  
  5. camera_indexes = range(4)
  6. cams = {}
  7. for cam_id in camera_indexes:
  8.     start = time.time()
  9.     cam = cv2.VideoCapture(cam_id + cv2.CAP_DSHOW)
  10.     #cam = cv2.VideoCapture(cam_id)
  11.     #cam = cv2.VideoCapture(cam_id + cv2.CAP_FFMPEG)
  12.     open_time = time.time()
  13.     print '{} seconds to open the cameras'.format(open_time - start)
  14.     if cam.isOpened():
  15.         cams[cam_id] = cam
  16.    
  17. for cam in cams.values():
  18.     cam.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('H', '2', '6', '4'))
  19.     cam.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
  20.     cam.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
  21.     cam.set(cv2.CAP_PROP_FPS, 10)
  22.     cam.set(cv2.CAP_PROP_AUTOFOCUS, 0)
  23.     cam.set(cv2.CAP_PROP_AUTO_EXPOSURE, 0)
  24.  
  25. while(True):
  26.     for index, cam in cams.iteritems():
  27.         success, frame = cam.read()
  28.         if success:
  29. #               gray1 = cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY)
  30.             cv2.imshow('cam{}'.format(index), frame)
  31.  
  32.     if cv2.waitKey(1) & 0xFF == ord('q'):
  33.             break
  34.  
  35. # When everything done, release the capture
  36. for cam in cams.values():
  37.     cam.release()
  38.  
  39. cv2.destroyAllWindows()