因此,我最近尝试使用 PyFakeWebcam,但遇到了一些问题。每当我尝试用它做任何事情时,我都会遇到这个错误:
Traceback (most recent call last):
File "fakecam.py", line 13, in <module>
fake1 = pyfakewebcam.FakeWebcam('/dev/video1', IMG_W, IMG_H)
File "/home/user/.local/lib/python3.6/site-packages/pyfakewebcam/pyfakewebcam.py", line 54, in __init__
fcntl.ioctl(self._video_device, _v4l2.VIDIOC_S_FMT, self._settings)
OSError: [Errno 22] Invalid argument
作为参考,我正在使用以下代码:
import cv2
import time
import pyfakewebcam
import numpy as np
IMG_W = 1280
IMG_H = 720
cam = cv2.VideoCapture(0)
cam.set(cv2.CAP_PROP_FRAME_WIDTH, IMG_W)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, IMG_H)
fake1 = pyfakewebcam.FakeWebcam('/dev/video1', IMG_W, IMG_H)
fake2 = pyfakewebcam.FakeWebcam('/dev/video2', IMG_W, IMG_H)
while True:
ret, frame = cam.read()
flipped = cv2.flip(frame, 1)
# Mirror effect
frame[0 : IMG_H, IMG_W//2 : IMG_W] = flipped[0 : IMG_H, IMG_W//2 : IMG_W]
fake1.schedule_frame(frame)
fake2.schedule_frame(flipped)
time.sleep(1/15.0)
是什么导致了这个错误,它可以解决吗?