Skip to content

Instantly share code, notes, and snippets.

@saiccoumar
Created January 5, 2024 05:35
Show Gist options
  • Save saiccoumar/7e19e0b345286d3aa173d9f4f44f5b22 to your computer and use it in GitHub Desktop.
Save saiccoumar/7e19e0b345286d3aa173d9f4f44f5b22 to your computer and use it in GitHub Desktop.
OpenCV with virtual cameras
import cv2
# Replace 1 with whatever camera you want
cap = cv2.VideoCapture(1)
if not cap.isOpened():
print("Error: Could not open camera.")
exit()
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
while True:
ret, frame = cap.read()
if not ret:
print("Error: Could not read frame.")
break
cv2.imshow('Camera', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment