I have followed this tutorial: https://github.com/dorssel/usbipd-win/wiki/WSL-support#usbip-client-tools
I successfully connect my USB camera with my WSL2, but can not open the camera.
$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
My camera USB is Logitech, Inc. Mic (Notebooks Pro) and my program:
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()
it shows
[ WARN:[email protected]] global /io/opencv/modules/videoio/src/cap_v4l.cpp (889) open VIDEOIO(V4L2:/dev/video0): can't open camera by index
I’ve used v4l-utils to query my container’s video devices
v4l2-ctl --list-devices
Failed to open /dev/video0: No such file or directory
I have added some config in Device Driver like @NotTheDr01ds said and now my camera show up in WSL2 with command
v4l2-ctl --list-devices
UVC Camera (046d:08c9) (usb-vhci_hcd.0-1):
/dev/video0
/dev/video1
But when I tried to run my program, its showed
[ WARN:[email protected]] global /io/opencv/modules/videoio/src/cap_v4l.cpp (1000) tryIoctl VIDEOIO(V4L2:/dev/video0): select() timeout.
The light of camera is on but can not capture anything. I have tried these command below:
lsmod
rmmod uvcvideo
modprobe uvcvideo nodrop=1 timeout=5000
but its showed error
rmmod uvcvideo
rmmod: ERROR: Module uvcvideo is builtin.
I have not find any solutions yet. Any suggestion??
I can't provide a complete answer at this point, but here's what I know so far about camera support under WSL2:
You have the first step correct by sharing the camera via USB/IP, but that's unfortunately only part of the process.
WSL2's kernel does not include any media drivers by default either, so you'll definitely need to add those to your kernel:
sudo apt install build-essential flex bison dwarves libssl-dev libelf-dev
libncurses-dev
mkdir ~/src
cd ~/src
git clone --depth=1 https://github.com/microsoft/WSL2-Linu
x-Kernel.git
make KCONFIG_CONFIG=Microsoft/config-wsl menuconfig
Enable the following options. All should be enabled as built-in, not modules. The option should have an "*" next to it rather than an "M":
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
make 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 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.
Even with all that in place, I have not been able to capture video yet. I can at least get the camera to show up in WSL2 after that as evidenced with v4l2-ctl --list-devices.
Hope that helps you at least make some progress. I'd be interested in knowing if you solve it completely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With