How do I apply cv2 capture to my actual camera for other apps? Like for example for google meet, I want to troll my teacher by applying effects to my camera with cv2, I already have the effects I wanted to do, but now I don't know how to apply it to my actual camera.
For this, you would need to create a fake camera
For Windows: you can use a module called pyvirtualcam
You have to install it using pip
Now we have to create a fake camera, For this you have to go to this link and download the OBS-VirtualCam[version].zip
Unzip it and navigate to \\bin[your computer's bittedness]
Open command prompt in that directory and type
regsvr32 /n /i:1 "obs-virtualsource.dll"
This will register a fake camera to your computer
Now you can send it frames using pyvirtualcam
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()
For Linux: you can use pyfakewebcam
To create a fake camera you have to run modprobe v4l2loopback devices=2
. This will create 2 fake cameras
Then you can send frames to it using pyfakewebcam
import time
import pyfakewebcam
import numpy as np
blue = np.zeros((480,640,3), dtype=np.uint8)
blue[:,:,2] = 255
red = np.zeros((480,640,3), dtype=np.uint8)
red[:,:,0] = 255
camera = pyfakewebcam.FakeWebcam('/dev/video1', 640, 480)
while True:
camera.schedule_frame(red)
time.sleep(1/30.0)
camera.schedule_frame(blue)
time.sleep(1/30.0)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.