1、运行一个.py项目文件

运行后系统提示如下
[ WARN:0] global /tmp/pip-req-build-6amqbhlx/opencv/modules/videoio/src/cap_v4l.cpp (893) open VIDEOIO(V4L2:/dev/video0): can't open camera by index

2、原因

报错的意思是摄像头打不开啊或者说是找不到设备

我在博客上找了很多教程,发现都只是改项目文件里某某行代码,但是如果只把.py项目文件中的cv.VideoCapture(args.input if args.input else 0)改为cv.VideoCapture(0)或者-1、1等,只能解决部分人遇到的问题。
在这里插入图片描述

3、 解决办法一:

我们先打开device目录,看有没有我们摄像头设备

(ai-learn368) dsk@DSK$   ls /dev/

查询结果如下:
在这里插入图片描述
我们发现以v字符开头的设备中并没有与摄像头有关的信息(应该有videoX设备)。

解决办法:

我又在度娘上搜了一下相关的问题,找到了有效的解决办法
主要原因是没有启动 虚拟机->可移动设备->关于摄像头设备的选项
我用的是虚拟机是Vmware Workstation 16 Player,相关操作如下

在这里插入图片描述
第4步之后,点击[确定]
其版本的虚拟机也都一样,只是按键位置不一样而已,耐心找一下。
这个时候我们在查看以下

在这里插入图片描述
这个时候和第一次ls /dev/ 目录就会明显的发现多了video0和video1的设备项
这个时候我们就可以通过修改上面提到的.py文件的cv.VideoCapture(0)括号里的值来启动摄像头设备了,值赋值为0或1。
在这里插入图片描述
这个时候我们调用指令运行一下⬇(允许我打个马赛克🤣)

在这里插入图片描述
成功运行!!!!!

4、注意事项

如果已经可见video0和vedio1设备但还是调不了摄像头的解决办法

  1. 打开虚拟机设置
    在这里插入图片描述

  2. 在USB兼容性选项里进行版本的切换,2不行就3,3不行就2…在这里插入图片描述
    然后再运行一下你的项目程序


希望这篇博客对你有用。

GitHub 加速计划 / opencv31 / opencv
238
21
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:4 个月前 )
1f47f5ba imgproc: replace assertion in cornerSubPix with descriptive error #28404 Replace CV_Assert with explicit bounds check for initial corners in cornerSubPix. This provides a descriptive runtime error instead of abrupt termination, improving error handling for Python and C++ users. No algorithmic or behavioral change for valid inputs. Fixes #25139 (Related to #7276). ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake 10 小时前
fba658b9 Improve precision of RotatedRect::points 1 天前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐