WSL-网络摄像头USB:无法通过索引打开相机

发布于 2025-01-29 02:02:01 字数 2081 浏览 3 评论 0原文

我遵循了本教程: htttps:// 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

我的相机USB是 Logitech,Inc。麦克风(笔记本pro)和我的程序:

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:[email protected]] 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:[email protected]] 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.

我尚未找到任何解决方案。有任何建议吗?

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??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月竹挽风 2025-02-05 02:02:01

我目前无法提供一个完整的答案,但这是我到目前为止对wsl2下的相机支持的了解:

  • 您通过通过USB/ip共享摄像机的第一步是正确的,但不幸的是,这只是其中的一部分过程。

  • WSL2的内核也不包括任何媒体驱动程序,因此您肯定需要将它们添加到内核:

      sudo apt安装构建flex bison矮人libssl-dev libelf-dev 
    libncurses-dev
    mkdir〜/src
    cd〜/src
    git克隆 -  depth = 1 https://github.com/microsoft/wsl2-linu
    X-Kernel.git
    使KCONFIG_CONFIG = Microsoft/config-wsl menuconfig
     

    启用以下选项。所有这些都应作为内置,而不是模块启用。该选项旁边应具有“*”,而不是“ M”:

    • 选择设备驱动程序 - >启用多媒体支持

    • 选择多媒体支持 - >媒体驱动程序:启用媒体USB适配器

    • 选择媒体USB适配器:启用USB视频类(UVC)

    • 将配置保存到“ Microsoft/config-wsl.uvc”(或任何您想调用的内容)

    • 退出menuconfig

      make kconfig_config = microsoft/config-wsl.uvc
     
    • (在此处的详细信息上有点模糊,因为我这样做已经有几周了)将平台bzimage复制到Windows驱动器上的位置。

    • 在您的 Windows 用户配置文件目录中更新.wslConfig文件,以指向新内核(请参阅在这里 for Parters)。

      )。

    • wsl -shutdown并重新启动以加载新内核

    • 确认它正在使用UNAME -A

    • 仍在此部分工作,但是如果您禁用Windows中相机的设备驱动程序,这似乎会有所帮助。否则Linux和Windows将争取控制。

即使所有这些都到位,我也无法捕获视频。此后,我至少可以将相机显示在WSL2中,这证明了v4l2-ctl -list-devices

希望至少可以帮助您取得一些进步。我有兴趣知道您是否完全解决。

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.

硬不硬你别怂 2025-02-05 02:02:01

flyingtiger的解决方案修复了问题的解决方案我到达与OP相同的位置后。

Python解决方案是添加此行:

cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))

C ++具有相同的解决方案:

cap.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'));

Flyingtiger's solution fixed the issue for me after I reached the same point as the OP.

Python solution was to add this line:

cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))

C++ had the same solution:

cap.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文