USB Camera摄像头(UVC 与 gspca)
From: http://www.cnblogs.com/leaven/archive/2010/08/19/1802934.html
http://weijb0606.blog.163.com/blog/static/131286274201063145356429/
我的攝像頭終于出現(xiàn)圖像了!
李遲按:本文章不是教程,不是心得總結(jié),而是記錄我在做畢業(yè)設(shè)計(jì)過(guò)程中遇到的一些問(wèn)題,以及怎么去解決
(有些還是沒(méi)有解決)。可能帶有牢騷,可能帶有某些讓人不悅的話。希望大家見(jiàn)諒。
今晚很高興,搗鼓了幾天,郁悶了幾天的事,今天解決了一些了。起碼我能在linux下看到攝像頭的圖像了。
提起USB攝像在linux下的使用,無(wú)論是百度還是Google,出現(xiàn)的多數(shù)是法國(guó)人寫(xiě)的一個(gè)通用驅(qū)動(dòng)程序,即spca5xx,
我也是找了很久才找到,——因?yàn)樵诰W(wǎng)上看到的那個(gè)網(wǎng)站已經(jīng)不能登陸了,就是說(shuō)不再維護(hù)了(這個(gè)后來(lái)再作說(shuō)明),所以
找了很久。可惜不能用。因?yàn)槲襪ake都不通過(guò),出現(xiàn)的錯(cuò)誤如下:
make -C /lib/modules/`uname -r`/build SUBDIRS=/usr/local/gspcav1-20071224 CC=cc modules
make[1]: Entering directory `/usr/src/linux-2.6.30.2'
CC [M] /usr/local/gspcav1-20071224/gspca_core.o
/usr/local/gspcav1-20071224/gspca_core.c:54:27: error: asm/semaphore.h: No such file or directory
In file included from /usr/local/gspcav1-20071224/gspca_core.c:845:
/usr/local/gspcav1-20071224/utils/spcausb.h: In function ‘spca5xxRegRead’:
/usr/local/gspcav1-20071224/utils/spcausb.h:95: error: implicit declaration of function ‘info’
/usr/local/gspcav1-20071224/utils/spcausb.h: In function ‘spca_set_interface’:
/usr/local/gspcav1-20071224/utils/spcausb.h:278: error: implicit declaration of function ‘warn’
In file included from /usr/local/gspcav1-20071224/gspca_core.c:853:
/usr/local/gspcav1-20071224/Sunplus-jpeg/sp5xxfw2.h: In function ‘sp5xxfw2_init’:
/usr/local/gspcav1-20071224/Sunplus-jpeg/sp5xxfw2.h:122: error: called object ‘info’ is not a function
/usr/local/gspcav1-20071224/Sunplus-jpeg/sp5xxfw2.h:136: error: called object ‘info’ is not a function
/usr/local/gspcav1-20071224/Sunplus-jpeg/sp5xxfw2.h:141: error: called object ‘info’ is not a function
/usr/local/gspcav1-20071224/Sunplus-jpeg/sp5xxfw2.h:148: error: called object ‘info’ is not a function
/usr/local/gspcav1-20071224/Sunplus-jpeg/sp5xxfw2.h:176: error: called object ‘info’ is not a function
/usr/local/gspcav1-20071224/Sunplus-jpeg/sp5xxfw2.h: In function ‘sp5xxfw2_start’:
/usr/local/gspcav1-20071224/Sunplus-jpeg/sp5xxfw2.h:214: error: called object ‘info’ is not a function
/usr/local/gspcav1-20071224/Sunplus-jpeg/sp5xxfw2.h:230: error: called object ‘info’ is not a function
/usr/local/gspcav1-20071224/gspca_core.c: In function ‘spca5xx_ioctl’:
/usr/local/gspcav1-20071224/gspca_core.c:2463: error: implicit declaration of function ‘video_usercopy’
/usr/local/gspcav1-20071224/gspca_core.c: At top level:
/usr/local/gspcav1-20071224/gspca_core.c:2609: error: unknown field ‘owner’ specified in initializer
/usr/local/gspcav1-20071224/gspca_core.c:2609: warning: initialization from incompatible pointer type
/usr/local/gspcav1-20071224/gspca_core.c:2611: error: unknown field ‘type’ specified in initializer
/usr/local/gspcav1-20071224/gspca_core.c:2615: warning: initialization from incompatible pointer type
/usr/local/gspcav1-20071224/gspca_core.c: In function ‘spca50x_create_sysfs’:
/usr/local/gspcav1-20071224/gspca_core.c:2769: error: implicit declaration of function ‘video_device_create_file’
/usr/local/gspcav1-20071224/gspca_core.c:2780: error: implicit declaration of function ‘video_device_remove_file’
/usr/local/gspcav1-20071224/gspca_core.c: In function ‘spca5xx_probe’:
/usr/local/gspcav1-20071224/gspca_core.c:4301: error: incompatible types in assignment
make[2]: *** [/usr/local/gspcav1-20071224/gspca_core.o] Error 1
make[1]: *** [_module_/usr/local/gspcav1-20071224] Error 2
make[1]: Leaving directory `/usr/src/linux-2.6.30.2'
make: *** [default] Error 2
以我現(xiàn)在的能力,我不能解決,我google過(guò),但得不到好的解決方法。
更重要的是,現(xiàn)在想找一個(gè)幾年前驅(qū)動(dòng)支持的攝像頭很難啊!現(xiàn)在都流行免驅(qū)了——根據(jù)OS相關(guān)理論,這是不成功的,
設(shè)備沒(méi)有驅(qū)動(dòng)哪能訪問(wèn)?他們說(shuō)的是用戶免去安裝驅(qū)動(dòng)程序這一步驟,——是這個(gè)“免驅(qū)”。我買(mǎi)的攝像頭不
在spca5xx支持范圍之中。我好容易找到一個(gè),是小郭用的,攝像頭ID剛好是上述驅(qū)動(dòng)所支持的。當(dāng)時(shí)很興
奮,心想,萬(wàn)事俱備,只差編譯、測(cè)試了。可惜,以失敗告終。錯(cuò)誤如上所述。
我試的幾個(gè)版本為spca5xx-20060501和gspcav1-20071224,都不行。
在網(wǎng)上找了那么多文章看,但一個(gè)也行不通。我不知大家的感受是什么,反正我很郁悶,很無(wú)奈。
后來(lái),在插入我買(mǎi)的攝像頭時(shí),使用了lsusb,將ID那一行復(fù)制到google中,一不小心,發(fā)現(xiàn)了一個(gè)
好網(wǎng)站:http://linux-uvc.berlios.de/。上面竟然有我攝像頭的ID號(hào)!!繼續(xù)研究,發(fā)現(xiàn)有UVC這個(gè)東東,
我在配置內(nèi)核時(shí)也碰到過(guò),但沒(méi)有注意,沒(méi)想到如此有用!后來(lái)在一個(gè)網(wǎng)站中找到有關(guān)使用UVC驅(qū)動(dòng)攝像頭的
文章,地址忘了,我也不知是怎么搜索到的。此外還下載一個(gè)觀看圖像的小軟件(補(bǔ)充一下:luvcview 或者cheese[debian自帶])。
結(jié)果成了!可以顯示圖像了!下面寫(xiě)一下過(guò)程:
如果你能在http://linux-uvc.berlios.de/找到你的攝像頭的ID,即UVC支持的,那么就可以在linux下使用了。
至于從哪個(gè)版本開(kāi)始內(nèi)核支持UVC,官方的話是“Linux 2.6.26 and newer includes the Linux UVC driver natively.”
1、查看攝像頭ID:
[root@151 dev]# lsusb
Bus 002 Device 013: ID 0ac8:3313 Z-Star Microelectronics Corp.
0xc8:3313在UVC中支持了。
2、插入攝像頭后,就可以在/dev/下查看是否有video設(shè)備文件:
[root@151 dev]# ls | grep video
video
video0
其中,video是video0的連接。如果沒(méi)有再現(xiàn),可能UVC沒(méi)有配置到內(nèi)核中,重新配置就可以了
(大致在Device DriversàMultimedia devicesàVideo capture adaptersàV4L USB devices下面)。如果內(nèi)核配置了,
還是不出現(xiàn),可以使用modprobe uvcvideo來(lái)加載該模塊。
3、先看看攝像頭的相關(guān)信息:
lshal | grep Cam
出現(xiàn):
info.product = 'Vega USB 2.0 Camera.' (string)
usb_device.product = 'Vega USB 2.0 Camera.' (string)
usb.interface.description = 'Vega USB 2.0 Camera.' (string)
info.product = 'Vega USB 2.0 Camera.' (string)
input.product = 'Vega USB 2.0 Camera.' (string)
info.product = 'Vega USB 2.0 Camera.' (string)
對(duì)USB有研究的,就很熟悉這些字段。
再看一下系統(tǒng)能不能識(shí)別出攝像頭:
[root@151 log]# dmesg | grep Cam
uvcvideo: Found UVC 1.00 device Vega USB 2.0 Camera. (0ac8:3313)
input: Vega USB 2.0 Camera. as /class/input/input6
usb 2-7: Product: Vega USB 2.0 Camera.
uvcvideo: Found UVC 1.00 device Vega USB 2.0 Camera. (0ac8:3313)
input: Vega USB 2.0 Camera. as /class/input/input7
usb 2-7: Product: Vega USB 2.0 Camera.
uvcvideo: Found UVC 1.00 device Vega USB 2.0 Camera. (0ac8:3313)
input: Vega USB 2.0 Camera. as /class/input/input8
usb 2-7: Product: Vega USB 2.0 Camera.
[root@151 ~]# dmesg | grep video
pci 0000:05:00.0: Boot video device
Linux video capture interface: v2.00
usbcore: registered new interface driver uvcvideo
uvcvideo 2-7:1.0: usb_probe_interface
uvcvideo 2-7:1.0: usb_probe_interface - got id
uvcvideo: Found UVC 1.00 device Vega USB 2.0 Camera. (0ac8:3313)
uvcvideo 2-7:1.0: usb_probe_interface
uvcvideo 2-7:1.0: usb_probe_interface - got id
uvcvideo: Found UVC 1.00 device Vega USB 2.0 Camera. (0ac8:3313)
uvcvideo 2-7:1.0: usb_probe_interface
uvcvideo 2-7:1.0: usb_probe_interface - got id
uvcvideo: Found UVC 1.00 device Vega USB 2.0 Camera. (0ac8:3313)
哈哈,識(shí)別出來(lái)了!可以測(cè)試了。
4、我使用的軟件是luvcview,這個(gè)軟件google就可以找到的。安裝過(guò)程很簡(jiǎn)單,——make,make install就可以了。(哈哈,這里才說(shuō))
下面這個(gè)過(guò)程是測(cè)試過(guò)程,從看到圖像到結(jié)束的過(guò)程:
[root@151 dev]# luvcview -d /dev/video0 -f yuv -s 640x480?? (直接運(yùn)行l(wèi)uvcview也可)
uvcview verion 0.1.4
size width: 640 height: 480
Video driver: x11
A window manager is available
video /dev/video0
Stop asked
Clean Up done Quit
[root@151 dev]#
解釋命令:
-d 設(shè)備名,這里/dev/video或/dev/video0都可以,因?yàn)樗鼈兌际且粋€(gè)文件
-f 格式,有yuv和jpg兩種,后者測(cè)試不行
-s 大小,能支持的最大尺度可能由luvcview決定,也可能由攝像頭決定,(應(yīng)該是后者,暫沒(méi)有研究)
更具體的參見(jiàn)luvcview目錄下的README文件。
另外,如果沒(méi)有插入攝像頭,即使modprobe uvcvideo也不會(huì)出現(xiàn)/dev/video設(shè)備文件;插入攝像頭,即使沒(méi)有modprobe uvcvideo,
也會(huì)出現(xiàn)/dev/video設(shè)備文件,當(dāng)然這是我的測(cè)試,沒(méi)有代表性,也沒(méi)有理論根據(jù)的。
注:
1、UVC:USB Video Class
2、gspcav不是不再維護(hù),而是在某一版本開(kāi)始已經(jīng)納入內(nèi)核了,至于哪個(gè)版本(2.6.26),就不太清楚了。特此說(shuō)明。
3、這次畢業(yè)設(shè)計(jì)所不再編譯gspca到內(nèi)核中了。不支持它,直接使用UVC。
第一張圖:紅旗6.2,內(nèi)核2.6.28.8
虛擬機(jī)FC9,內(nèi)核2.6.30
發(fā)表于: 2010-03-19,修改于:
我跟作者經(jīng)歷簡(jiǎn)直太相似了,起先搞了好幾天真是有點(diǎn)摸不著頭腦,哈哈!!
總結(jié)
以上是生活随笔為你收集整理的USB Camera摄像头(UVC 与 gspca)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Linux nohup命令详解
- 下一篇: 单片机c语言 开方函数,单片机C语言求平