Skip to content

Instantly share code, notes, and snippets.

@saknarak
Created January 17, 2024 11:06
Show Gist options
  • Save saknarak/7d24743b42c9cf5c333498d6241759fb to your computer and use it in GitHub Desktop.
Save saknarak/7d24743b42c9cf5c333498d6241759fb to your computer and use it in GitHub Desktop.
Raspberry Pi with multiple USB webcams at high resolution
The secret is mode must be MJPG instead of default YUYV
```python
import cv2
cap0 = cv2.VideoCapture('/dev/video0')
cap0.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))
cap0.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap0.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
cap2 = cv2.VideoCapture('/dev/video2')
cap2.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))
cap2.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap2.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
while True:
ok, frame = cap0.read()
if not ok:
break
cv2.imshow('cap0', frame)
ok, frame = cap2.read()
if not ok:
break
cv2.imshow('cap2', frame)
key = cv2.waitKey(1)
if key == 27:
break
cap0.release()
cap2.release()
cv2.destroyAllWindows()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment