我正在试着修复我的网络摄像头,它里面有一条水平的绿线,我使用OpenCV来嵌入这条线,使用pyVirtualcam来创建一个虚拟摄像头,并在Discorde和Google Meet等应用程序中使用它. 使用OpenCV的图像处理工作正常,但在try 创建虚拟凸轮时出现以下错误:
Traceback (most recent call last):
File "...\webcamfix\camfix.py", line 37, in <module>
cam.send(frame)
File "...\pyvirtualcam\camera.py", line 349, in send
self._backend.send(frame)
^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'send'
以下是我的代码:
import cv2
import pyvirtualcam
from pyvirtualcam import PixelFormat
# Read webcam
webcam = cv2.VideoCapture(0)
# Set width to 1280 and height to 720
webcam.set(3, 1280)
webcam.set(4, 720)
# Read mask
mask = cv2.imread('mask.jpg', cv2.IMREAD_GRAYSCALE)
# Start virtual cam with 1280x720 30fps
with pyvirtualcam.Camera(1280, 720, 30, fmt=PixelFormat.BGR) as cam:
print('Virtual camera device: ' + cam.device)
if webcam.isOpened():
sucess, frame = webcam.read()
while sucess:
sucess, frame = webcam.read()
# Inpainting frame where mask limits using TELEA technique
frame = cv2.inpaint(frame, mask, 3, cv2.INPAINT_NS)
# Fliping image
frame = cv2.flip(frame, 1)
# Displaying video and closing the window if ESC is pressed
cv2.imshow("webcamfix", frame)
key = cv2.waitKey(5)
if key == 27: # ESC
break
cam.send(frame)
cam.sleep_until_next_frame()
正如pyVirtualcam文档建议的那样,我使用的是OBS虚拟摄像头和Unity Video Capture.如果有什么更简单的方法可以在Windows上用python创建一个虚拟相机,我会很高兴知道的.