我遵循了本教程:https://github.com/dorssel/usbipd-win/wiki/WSL-support#usbip-client-tools
我成功地将我的USB摄像头与我的WSL2连接起来,但无法打开相机。
$lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 046d:08cb Logitech, Inc. Mic (Notebooks Pro)
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
我的摄像头是Logitech公司的麦克风(笔记本专业),我的程序:
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
if ret:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv2.destroyAllWindows()
它显示了
[ WARN:0@0.009] global /io/opencv/modules/videoio/src/cap_v4l.cpp (889) open VIDEOIO(V4L2:/dev/video0): can't open camera by index
我使用v4l-utils查询容器的视频设备。
v4l2-ctl --list-devices
Failed to open /dev/video0: No such file or directory
我在设备驱动程序中添加了一些配置,比如@NotTheDr01ds说,现在我的相机用命令显示在WSL2中
v4l2-ctl --list-devices
UVC Camera (046d:08c9) (usb-vhci_hcd.0-1):
/dev/video0
/dev/video1
但是当我试图运行我的程序时,它显示了
[ WARN:0@10.310] global /io/opencv/modules/videoio/src/cap_v4l.cpp (1000) tryIoctl VIDEOIO(V4L2:/dev/video0): select() timeout.
照相机的光线是开着的,但不能捕捉到任何东西。我尝试了以下命令:
lsmod
rmmod uvcvideo
modprobe uvcvideo nodrop=1 timeout=5000
但它所显示的错误
rmmod uvcvideo
rmmod: ERROR: Module uvcvideo is builtin.
我还没有找到任何解决办法。有什么建议吗?
发布于 2022-05-16 12:57:46
到目前为止,我还不能给出一个完整的答案,但到目前为止,我对WSL2下的摄像头支持的了解如下:
- Select Device Drivers -> Enable Multimedia support
- Select Multimedia support -> Media Drivers: Enable Media USB Adapters
- Select Media USB Adapters: Enable USB Video Class (UVC)
- Save the config to "Microsoft/config-wsl.uvc" (or whatever you want to call it)
- Exit menuconfig
让KCONFIG_CONFIG=Microsoft/config-wsl.uvc
- (A bit fuzzy on the details here since it's been a few weeks since I did it) Copy the platform `bzImage` to a location on your Windows drive.
- Update the `.wslconfig` file in your _Windows_ user profile directory to point to the new kernel (see [here](https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configuration-setting-for-wslconfig) for starters).
- `wsl --shutdown` and restart to load the new kernel
- Confirm it is in play with `uname -a`
- Still working on this part, but it seems to help if you disable the device driver for the camera in Windows. Otherwise Linux and Windows will be fighting for control.
即使有了所有这些,我还没能捕捉到视频。我至少可以让相机出现在WSL2之后,就像v4l2-ctl --list-devices
所证明的那样。
希望这至少能帮你取得一些进展。我想知道你是否完全解决了这个问题。
https://stackoverflow.com/questions/72255353
复制相似问题