在ubuntu下使用UVC的摄像头
本文可自由转载,但请遵循“署名-非商业用途-保持一致”的创作共用协议。 永久链接:JoeCen's 小猫窝-----------------------------
买了一个摄像头,打算在ubuntu里面使用。
插上usb口,dmsg可以看到下面的信息:
[ 4521.267892] uvcvideo: Found UVC 1.00 device DEF-299A Camera (1871:0603)
[ 4522.264089] uvcvideo: Failed to query (1) UVC control 2 (unit 0) : -110 (exp. 26).
[ 4522.264099] uvcvideo: Failed to initialize the device (-5).
[ 4522.264153] usbcore: registered new interface driver uvcvideo
[ 4522.264157] USB Video Class driver (v0.1.0)
[ 4522.264089] uvcvideo: Failed to query (1) UVC control 2 (unit 0) : -110 (exp. 26).
[ 4522.264099] uvcvideo: Failed to initialize the device (-5).
[ 4522.264153] usbcore: registered new interface driver uvcvideo
[ 4522.264157] USB Video Class driver (v0.1.0)
可以看到,这个是一个UVC的摄像头,系统可以认出来,那么应该也有它的驱动了。
lsmod |grep uvc
uvcvideo 58116 0
compat_ioctl32 2304 1 uvcvideo
videodev 29440 1 uvcvideo
v4l2_common 18304 2 uvcvideo,videodev
v4l1_compat 15492 2 uvcvideo,videodev
usbcore 146028 8 uvcvideo,snd_usb_audio,snd_usb_lib,hci_usb,usbhid,ehci_hcd,uhci_hcd
compat_ioctl32 2304 1 uvcvideo
videodev 29440 1 uvcvideo
v4l2_common 18304 2 uvcvideo,videodev
v4l1_compat 15492 2 uvcvideo,videodev
usbcore 146028 8 uvcvideo,snd_usb_audio,snd_usb_lib,hci_usb,usbhid,ehci_hcd,uhci_hcd
果然可以看到,uvcvideo模块已经load到内存里面了。不过摄像头还不可以用,
ls /dev/video0
结果是
file not found
如果是正常的话,会在dev生成一个video0的设备。应该是dmsg里面那几句"Failed"的原因。
网上说这个事情的并不多,而且都比较旧,但是终归还是被我找到一篇有用的。
里面说:
The webcam audio interface must be initialised before the video interface.Linux will by default initialise the video interface first, so you need to
remove the uvcvideo.ko module from the /lib/modules subdirectory where it gets loaded automatically, and load it manually after plugging the webcam.
remove the uvcvideo.ko module from the /lib/modules subdirectory where it gets loaded automatically, and load it manually after plugging the webcam.
大概意思是uvc的模块uvcvideo.ko在load之前需要先load其他的模块。那么我们需要不让uvc模块自动load:
mkdir /home/joe/module/
mv /lib/modules/$(uname -r)/ubuntu/media/usbvideo/uvcvideo.ko /home/joe/module/
vi /lib/modules/$(uname -r)/modules.dep
mv /lib/modules/$(uname -r)/ubuntu/media/usbvideo/uvcvideo.ko /home/joe/module/
vi /lib/modules/$(uname -r)/modules.dep
将里面有"uvcvideo"的一行删除,保存。
插入摄像头以后,用下面这个脚本来load模块。
#!/bin/sh
sudo modprobe videodev
sudo modprobe compat_ioctl32
sudo insmod /home/joe/module/uvcvideo.ko
sudo modprobe videodev
sudo modprobe compat_ioctl32
sudo insmod /home/joe/module/uvcvideo.ko
正常情况下的dmsg:
[ 6503.835612] uvcvideo: Found UVC 1.00 device DEF-299A Camera (1871:0603)
[ 6503.839053] usbcore: registered new interface driver uvcvideo
[ 6503.839064] USB Video Class driver (v0.1.0)
[ 6503.839053] usbcore: registered new interface driver uvcvideo
[ 6503.839064] USB Video Class driver (v0.1.0)
如果使用
ls /dev/video0
可以找到该设备
使用cheese可以看到图像就大功告成了。另外camorama似乎还是不能用,可能和它的设置有关,不过我找不到地方设置,那就算了,用cheese也不错。