Chinaunix首页 | 论坛 | 博客
  • 博客访问: 481488
  • 博文数量: 42
  • 博客积分: 2100
  • 博客等级: 大尉
  • 技术积分: 580
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-07 21:07
文章分类

全部博文(42)

文章存档

2011年(1)

2010年(18)

2009年(16)

2008年(7)

分类: LINUX

2010-03-19 21:46:23

我的摄像头终于出现图像了!

 

李迟按:本文章不是教程,不是心得总结,而是记录我在做毕业设计过程中遇到的一些问题,以及怎么去解决(有些还是没有解决)。可能带有牢骚,可能带有某些让人不悦的话。希望大家见谅。

 

今晚很高兴,捣鼓了几天,郁闷了几天的事,今天解决了一些了。起码我能在linux下看到摄像头的图像了。

提起USB摄像在linux下的使用,无论是百度还是Google,出现的多数是法国人写的一个通用驱动程序,即spca5xx,我也是找了很久才找到,——因为在网上看到的那个网站已经不能登陆了,就是说不再维护了(这个后来再作说明),所以找了很久。可惜不能用。因为我make都不通过,出现的错误如下:

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

 

以我现在的能力,我不能解决,我google过,但得不到好的解决方法。

更重要的是,现在想找一个几年前驱动支持的摄像头很难啊!现在都流行免驱了——根据OS相关理论,这是不成功的,设备没有驱动哪能访问?他们说的是用户免去安装驱动程序这一步骤,——是这个“免驱”。我买的摄像头不在spca5xx支持范围之中。我好容易找到一个,是小郭用的,摄像头ID刚好是上述驱动所支持的。当时很兴奋,心想,万事俱备,只差编译、测试了。可惜,以失败告终。错误如上所述。

我试的几个版本为spca5xx-20060501gspcav1-20071224,都不行。

在网上找了那么多文章看,但一个也行不通。我不知大家的感受是什么,反正我很郁闷,很无奈。

后来,在插入我买的摄像头时,使用了lsusb,将ID那一行复制到google中,一不小心,发现了一个好网站:。上面竟然有我摄像头的ID号!!继续研究,发现有UVC这个东东,我在配置内核时也碰到过,但没有注意,没想到如此有用!后来在一个网站中找到有关使用UVC驱动摄像头的文章,地址忘了,我也不知是怎么搜索到的。此外还下载一个观看图像的小软件。结果成了!可以显示图像了!

下面写一下过程:

如果你能在找到你的摄像头的ID,即UVC支持的,那么就可以在linux下使用了。至于从哪个版本开始内核支持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设备文件:

[root@151 dev]# ls | grep video

video

video0

其中,videovideo0的连接。如果没有再现,可能UVC没有配置到内核中,重新配置就可以了(大致在Device DriversàMultimedia devicesàVideo capture adaptersàV4L USB devices下面)。如果内核配置了,还是不出现,可以使用modprobe uvcvideo来加载该模块。

3、先看看摄像头的相关信息:

lshal | grep Cam

出现:

  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)

对USB有研究的,就很熟悉这些字段。

 

再看一下系统能不能识别出摄像头:

[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)

哈哈,识别出来了!可以测试了。

4、我使用的软件是luvcview,这个软件google就可以找到的。安装过程很简单,——makemake install就可以了。

下面这个过程是测试过程,从看到图像到结束的过程:

[root@151 dev]# luvcview -d /dev/video0 -f yuv -s 640x480

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 设备名,这里/dev/video/dev/video0都可以,因为它们都是一个文件

-f 格式,有yuvjpg两种,后者测试不行

-s 大小,能支持的最大尺度可能由luvcview决定,也可能由摄像头决定,(应该是后者,暂没有研究)

更具体的参见luvcview目录下的README文件。

另外,如果没有插入摄像头,即使modprobe uvcvideo也不会出现/dev/video设备文件;插入摄像头,即使没有modprobe uvcvideo,也会出现/dev/video设备文件,当然这是我的测试,没有代表性,也没有理论根据的。

 

 

注:

1、UVCUSB Video Class

2、gspcav不是不再维护,而是在某一版本开始已经纳入内核了,至于哪个版本,就不太清楚了。特此说明。

3、这次毕业设计所不再编译gspca到内核中了。不支持它,直接使用UVC。

 

第一张图:红旗6.2,内核2.6.28.8

 

虚拟机FC9,内核2.6.30

 

阅读(12737) | 评论(6) | 转发(0) |
0

上一篇:Linux与NFS(上)

下一篇:对某两篇论文的思考

给主人留下些什么吧!~~

rekken2011-06-08 19:01:51

GuiltCool: 你好!yuv格式的我没有研究,因为我的摄像头在某种情况下是MJPEG格式的,直接保存为jpg就成图片了。
关于yuv格式,你可以看看luvcview源代码,里面有一些函数的.....
感谢,非常感谢,我去google一下 luvcview,有问题再请教你

GuiltCool2011-05-03 08:43:14

rekken: 你好,请问如何摄像头采集到的yuv格式的数据,保存成可以读取的图片。我的摄像头的数据格式为yuv422,但是不知道如何讲采集到的数据保存为图片。保存的图片什么扩.....
你好!yuv格式的我没有研究,因为我的摄像头在某种情况下是MJPEG格式的,直接保存为jpg就成图片了。
关于yuv格式,你可以看看luvcview源代码,里面有一些函数的。
如果需要,我不妨也复习一下这个源代码。

GuiltCool2011-05-03 08:42:35

rekken: 你好,请问如何摄像头采集到的yuv格式的数据,保存成可以读取的图片。我的摄像头的数据格式为yuv422,但是不知道如何讲采集到的数据保存为图片。保存的图片什么扩.....
你好!yuv格式的我没有研究,因为我的摄像头在某种情况下是MJPEG格式的,直接保存为jpg就成图片了。
关于yuv格式,你可以看看luvcview源代码,里面有一些函数的。
如果需要,我不妨也复习一下这个源代码。

rekken2011-04-29 20:58:02

你好,请问如何摄像头采集到的yuv格式的数据,保存成可以读取的图片。我的摄像头的数据格式为yuv422,但是不知道如何讲采集到的数据保存为图片。保存的图片什么扩展名,另外是不是需要插入文件头呀

chinaunix网友2010-05-09 08:50:18

我的意思就是加载uvcvideo,videodev,v4l1_compat这三个驱动后,能够用cheese(一款摄像头拍照软件)捕捉到摄像头图像了。。。 我自己用Qt+OpenCV写了一个小软件,也可以捕捉到摄像头图像并拍照保存成jpg图片,但是我的课题是摄像头驱动设计。。。所以答辩的话,重点还是要分析uvcvideo这个驱动模块的。。。现在正犯愁呢。。。