Created
January 5, 2024 05:35
-
-
Save saiccoumar/7e19e0b345286d3aa173d9f4f44f5b22 to your computer and use it in GitHub Desktop.
OpenCV with virtual cameras
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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