linux usb摄像头设备信息查看方式
linux usb摄像头设备信息查看
linux下usb摄像头操作,离不开v4l2框架
V4L2是Video for linux2的简称,为linux中关于视频设备的内核驱动。
在Linux中,视频设备是设备文件,可以像访问普通文件一样对其进行读写,摄像头在/dev/video0下。
查看linux 摄像头设备,如果存在有效的摄像头设备,则可以在dev目录下查看
?1 2 3 | eric@eric-PC:/$ ls dev /video * -l crw-rw----+ 1 root video 81, 0 11月 8 13:37 dev /video0 crw-rw----+ 1 root video 81, 1 11月 8 13:37 dev /video1 |
也可以查看启动信息,是否存在有效usb摄像头设备
?1 2 3 4 5 6 7 8 | eric@eric - PC: / $ dmesg | grep video [ 1849.908486 ] videodev: Linux video capture interface: v2. 00 [ 1850.022954 ] uvcvideo: Found UVC 1.00 device hm1091_techfront ( 0408 : 1020 ) [ 1850.061899 ] uvcvideo 1 - 1 : 1.0 : Entity type for entity Extension 4 was not initialized! [ 1850.061903 ] uvcvideo 1 - 1 : 1.0 : Entity type for entity Extension 3 was not initialized! [ 1850.061905 ] uvcvideo 1 - 1 : 1.0 : Entity type for entity Processing 2 was not initialized! [ 1850.061907 ] uvcvideo 1 - 1 : 1.0 : Entity type for entity Camera 1 was not initialized! [ 1850.062579 ] usbcore: registered new interface driver uvcvideo |
v4l2-ctl命令查看video设备参数信息,如果提示如下未找到v4l2-ctl命令,则需要安装v4l-utils
?1 2 3 | eric@eric - PC: / dev$ v4l2 - ctl - d / dev / video0 - - all bash: v4l2 - ctl:未找到命令 eric@eric - PC: / dev$ sudo apt - get install v4l - utils |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | eric@eric - PC: / $ v4l2 - ctl - d / dev / video0 - - all Driver Info: Driver name : uvcvideo Card type : hm1091_techfront: hm1091_techfr Bus info : usb - 0000 : 02 : 04.0 - 1 Driver version : 5.4 . 50 Capabilities : 0x84a00001 Video Capture Metadata Capture Streaming Extended Pix Format Device Capabilities Device Caps : 0x04200001 Video Capture Streaming Extended Pix Format Priority: 2 Video input : 0 (Camera 1 : ok) Format Video Capture: Width / Height : 1280 / 720 Pixel Format : 'MJPG' (Motion - JPEG) Field : None Bytes per Line : 0 Size Image : 1843200 Colorspace : sRGB Transfer Function : Default (maps to sRGB) YCbCr / HSV Encoding: Default (maps to ITU - R 601 ) Quantization : Default (maps to Full Range ) Flags : Crop Capability Video Capture: Bounds : Left 0 , Top 0 , Width 1280 , Height 720 Default : Left 0 , Top 0 , Width 1280 , Height 720 Pixel Aspect: 1 / 1 Selection: crop_default, Left 0 , Top 0 , Width 1280 , Height 720 , Flags: Selection: crop_bounds, Left 0 , Top 0 , Width 1280 , Height 720 , Flags: Streaming Parameters Video Capture: Capabilities : timeperframe Frames per second: 30.000 ( 30 / 1 ) Read buffers : 0 brightness 0x00980900 ( int ) : min = - 64 max = 64 step = 1 default = 0 value = 0 contrast 0x00980901 ( int ) : min = 0 max = 95 step = 1 default = 0 value = 0 saturation 0x00980902 ( int ) : min = 0 max = 100 step = 1 default = 64 value = 64 hue 0x00980903 ( int ) : min = - 2000 max = 2000 step = 1 default = 0 value = 0 white_balance_temperature_auto 0x0098090c ( bool ) : default = 1 value = 1 gamma 0x00980910 ( int ) : min = 100 max = 300 step = 1 default = 100 value = 100 power_line_frequency 0x00980918 (menu) : min = 0 max = 2 default = 1 value = 1 white_balance_temperature 0x0098091a ( int ) : min = 2800 max = 6500 step = 1 default = 4600 value = 4600 flags = inactive sharpness 0x0098091b ( int ) : min = 0 max = 7 step = 1 default = 2 value = 2 backlight_compensation 0x0098091c ( int ) : min = 0 max = 1 step = 1 default = 1 value = 1 exposure_auto 0x009a0901 (menu) : min = 0 max = 3 default = 3 value = 3 exposure_absolute 0x009a0902 ( int ) : min = 10 max = 2047 step = 1 default = 384 value = 384 flags = inactive exposure_auto_priority 0x009a0903 ( bool ) : default = 0 value = 1 |
有以上信息可以看出,设备支持分辨率1280×720,支持MJPEG格式。
linux usb摄像头索引的获取
一般情况下,笔记本自带的摄像头的索引号为0,而通过USB插入的摄像头一般为1(只有两个摄像头的情况下)。
但是,当笔记本插着USB摄像头开机时,有可能USB的索引变为0,如果还是使用原来的索引,便会产生错误或者结果误差。为此,我写了个程序自动获取USB摄像头的索引。
原理与实现
在Linux系统下,所有设备的均被当作文件的形式进行管理和交互(不是很懂),而摄像头对应的文件在/sys/class/video4linux/下,而每个摄像头均有name文件记录摄像头的名字。
因此,可以根据该文件得到摄像头的名称,而摄像头所在的文件夹(如video0)可以得到索引。
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | def get_usb_camera_index(): # 获取USB摄像头的索引 camera_path = Path( '/sys/class/video4linux/' ) camera_list = list (camera_path.glob( 'video*' )) camera_list.sort() index = 0 for i in range ( len (camera_list)): camera = camera_list[i] name_file = camera.joinpath( 'name' ) with open (name_file, 'r' ) as f: info = f.readline() if 'USB' in info: index = i break return index |
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/pyt1234567890/article/details/109558644
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。