Using Opencv Output as Webcam

How to make a virtual camera with python?

This may be late but check this out pyvirtualcam

install it first:

pip install pyvirtualcam

You can make it like this:

import pyvirtualcam
import numpy as np

with pyvirtualcam.Camera(width=1280, height=720, fps=30) as cam:
while True:
frame = np.zeros((cam.height, cam.width, 4), np.uint8) # RGBA
frame[:,:,:3] = cam.frames_sent % 255 # grayscale animation
frame[:,:,3] = 255
cam.send(frame)
cam.sleep_until_next_frame()
cam.sleep_until_next_frame()

Output OpenCv to virtual camera in Python

OpenCV uses BGR. pyvirtualcam by default accepts RGB but also supports BGR and others.

The following should work:

fmt = pyvirtualcam.PixelFormat.BGR
with pyvirtualcam.Camera(1280, 720, 20, fmt=fmt) as camera:

See also the webcam_filter.py sample which is similar to what you try to do.

OpenCV2 Write to webcam python

Note that the VideoCapture object is strictly responsible for capturing(read) an image from the stream(webcam, video file, RTSP, e.t.c.).
Then you can do any further processing with any of the opencv functions

Now, the webcam hardware is a device you read from, not write to.



Related Topics



Leave a reply



Submit