I'm trying to send a video feed from my physical camera to a virtual camera in Python so I can perform certain effects on it.
This is my code so far:
import pyvirtualcam
import numpy as np
cam = pyvirtualcam.Camera(width=1280, height=720, fps=30)
cvCam = cv2.VideoCapture(0)
while True:
try:
_, frame = cvCam.read()
cam.send(frame)
cam.sleep_until_next_frame()
except KeyboardInterrupt:
cam.close()
cvCam.close()
break
print("Done")
After I ran this code, I got an error saying that I also needed to add an alpha channel. I copied some code from this post. This was my new code that added an alpha channel to the code:
import pyvirtualcam
import numpy as np
cam = pyvirtualcam.Camera(width=1280, height=720, fps=30)
cvCam = cv2.VideoCapture(0)
while True:
_, frame = cvCam.read()
b_channel, g_channel, r_channel = cv2.split(frame)
alpha_channel = np.ones(b_channel.shape, dtype=b_channel.dtype) * 50
frame = cv2.merge((b_channel, g_channel, r_channel, alpha_channel))
cam.send(frame)
cam.sleep_until_next_frame()
print("Done")
After running this code, it just suddenly exits the program without any error message even though it is in a while True
loop. I am unable to debug this problem. What is the issue?