Skip to content

Instantly share code, notes, and snippets.

@Mierenga
Created April 12, 2018 15:25
Show Gist options
  • Save Mierenga/b35f68b50442e487be55c46f60f7c66b to your computer and use it in GitHub Desktop.
Save Mierenga/b35f68b50442e487be55c46f60f7c66b to your computer and use it in GitHub Desktop.
# options
MAX_CAMS = 4
WIDTH_PIXELS = 1280
HEIGHT_PIXELS = 720
VIDEO_FORMAT = 'MJPG'
# connect to all available webcams
cams = []
for i in range(0, MAX_CAMS):
next_cam = cv2.VideoCapture(i)
if next_cam.isOpened():
cams.append(next_cam)
else:
break
# configure camera settings
# (use `v4l2-ctl -d /dev/video0 --list-formats-ext` in shell to see what webcam supports)
for cam in cams:
# resolution
cam.set(cv2.CAP_PROP_FRAME_WIDTH, WIDTH_PIXELS)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, HEIGHT_PIXELS)
# format
cam.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*VIDEO_FORMAT))
# read frames
while True:
for cam in cams:
_, frame = cam.read()
# convert from BGR to RGB
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# TODO: send along to something
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment