创建视频捕获的常规方法是:
cam = cv2.VideoCapture(n)
其中n对应于/dev/video0
,dev/video1
的个数
但是因为我正在构建一个机器人,它使用多个摄像头来完成不同的任务,所以我需要确保它被分配给正确的摄像头,我创建了udev规则,每当插入特定的摄像头时,都会创建具有指向正确端口的符号链接的设备。
它们似乎在工作,因为当我查看/dev
目录时,可以看到链接:
/dev/front_cam -> video1
但是我不知道现在该怎么用。
我以为我可以从文件名打开它,就好像它是一个视频一样,但是cam = cv2.VideoCapture('/dev/front_cam')
不起作用。
也不是cv2.VideoCapture('/dev/video1')
它不会抛出错误,而是返回一个VideoCapture对象,而不是打开的对象(cam.isOpened()
返回False
)。
我的每个video4linux设备创建2个设备节点。例如,
/dev/video0
和/dev/video1
都与我的内部网络摄像头相关。当我插入第二个USB摄像头时,/dev/video2
和/dev/video3
都会出现。但是,我只能使用每对中编号较低的设备进行视频捕获(即/dev/video0
和/dev/video2
)。我用
udevadm monitor
观看设备到达,然后用udevadm info --path=$PATH_FROM_UDEVADM_MONITOR --attribute-walk
检查每个相机设备。用于视频捕获的设备有ATTR{index}=="0"
。也许你只需要打开
/dev/video0
,而不是试图打开/dev/video1
:我没有找到建议的解决方案,而是找到了一个短一点的,感觉有点粗糙。
我只是看看符号链接点的位置,找到其中的整数,然后使用它。
首先在USB设备列表中搜索所需的字符串。获取总线和设备号。
在video4linux目录下找到符号链接。从realpath中提取设备索引并将其传递给VideoCapture方法。
相关问题 更多 >
编程相关推荐