Skip to content

Instantly share code, notes, and snippets.

@minons1
Created September 4, 2021 10:38
Show Gist options
  • Save minons1/4bf33f94fc117654d2b11bce48200346 to your computer and use it in GitHub Desktop.
Save minons1/4bf33f94fc117654d2b11bce48200346 to your computer and use it in GitHub Desktop.
Access camera and make virtual camera using python
import pyvirtualcam
import cv2
fmt = pyvirtualcam.PixelFormat.BGR
cap = cv2.VideoCapture(0)
with pyvirtualcam.Camera(width=1280, height=720, fps=20, fmt=fmt) as cam:
while True:
ret_val, frame = cap.read()
frame = cv2.resize(frame, (1280, 720), interpolation=cv2.BORDER_DEFAULT)
# cv2.imshow('my webcam', frame)
cam.send(frame)
cam.sleep_until_next_frame()
if cv2.waitKey(1) == 27:
break # esc to quit
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment