
新版本的内核中Linux内核中已经包含了大部分的USB摄像头驱动,因此,在高版本的linux内核系统中使用USB摄像头并不需要做很多工作。
Linux环境为Ubuntu 10.04,Linux 2.6.32内核,已经包含了大部分USB摄像头的驱动程序,插上摄像头时即可识别。直接将我们USB摄像头插上,查看系统中USB设备信息。
root@Ubuntu1004:~# lsusb //查看系统中的usb设备
Bus 002 Device 002: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 005: ID 0ac8:3450 Z-Star Microelectronics Corp.
//显示干插入的USB设备信息,ID为0ac8:3450,芯片厂商信息为Z-Star Microelectronics Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
ffmpeg编译首先解压ffmpeg-0.5.1.tar.bz2,,执行configure命令如下:
[plain] view plain copy
./configure --cc=arm-linux-gnueabihf-gcc --host-cc=arm-linux-gnueabihf --prefix=/home/***/iWork/common/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux --enable-cross-compile --arch=arm --disable-yasm
编译:
[plain] view plain copy
make
出现错误如下:
[plain] view plain copy
arm-linux-gnueabihf-gcc -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -I. -I"/home/***/iWork/lamobo/motion-3.2.12-arm-project/ffmpeg-0.5.1"
-D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112 -std=c99 -fomit-frame-pointer -g -Wdeclaration-after-statement -Wall -Wno-switch -Wdisabled-optimization
-Wpointer-arith -Wredundant-decls -Wno-pointer-sign -Wcast-qual -Wwrite-strings -Wtype-limits -Wundef -O3 -fno-math-errno -fno-signed-zeros -c -o
libavcodec/dsputil.o libavcodec/dsputil.c
/tmp/ccOmDdh7.s: Assembler messages:
/tmp/ccOmDdh7.s:51789: Error: thumb conditional instruction should be in IT block -- `movgt fp,r9'
/tmp/ccOmDdh7.s:51790: Error: thumb conditional instruction should be in IT block -- `movgt r9,r8'
/tmp/ccOmDdh7.s:51792: Error: thumb conditional instruction should be in IT block -- `movle r9,r7'
/tmp/ccOmDdh7.s:51794: Error: thumb conditional instruction should be in IT block -- `movgt fp,r9'
/tmp/ccOmDdh7.s:51889: Error: thumb conditional instruction should be in IT block -- `movgt r9,r8'
/tmp/ccOmDdh7.s:51890: Error: thumb conditional instruction should be in IT block -- `movgt r8,ip'
/tmp/ccOmDdh7.s:51892: Error: thumb conditional instruction should be in IT block -- `movle r8,r6'
/tmp/ccOmDdh7.s:51894: Error: thumb conditional instruction should be in IT block -- `movgt r9,r8'
make: *** [libavcodec/dsputil.o] Error 1
这需要修改~/ffmpeg-0.5.1/config.mak,在OPTFLAGS(line:16)选项中添加:
[plain] view plain copy
-Wa,-mimplicit-it=thumb
加入这句的意思是在使用Thumb ISA指令编译时自动产生“IT”指令。 继续编译,又报错:
[plain] view plain copy
strip: Unable to recognise the format of the input file `ffmpeg'
这是strip没有使用交叉编译的版本所致,由于此时我们需要的库文件已经编成,所以这个错误可以忽略不计,修改config.mak中的strip为arm-linux-gnueabihf-strip,继续让编译完成
motion编译
motion中的ffmpeg.c是对ffmpeg api的封装,向其他模块提供功能。如在主程序文件motion.c中
[cpp] view plain copy
//......
#ifdef HAVE_FFMPEG
/* FFMpeg initialization is only performed if FFMpeg support was found
* and not disabled during the configure phase.
*/
ffmpeg_init()
#endif /* HAVE_FFMPEG */
//......
这里ffmpeg_init就是ffmpeg.c中封装的方法:
[cpp] view plain copy
void ffmpeg_init()
{
motion_log(LOG_INFO, 0, "ffmpeg LIBAVCODEC_BUILD %d LIBAVFORMAT_BUILD %d", LIBAVCODEC_BUILD, LIBAVFORMAT_BUILD)
av_register_all()
#if LIBAVCODEC_BUILD >4680
av_log_set_callback( (void *)ffmpeg_avcodec_log )
#endif
/* Copy the functions to use for the append file protocol from the standard
* file protocol.
*/
mpeg1_file_protocol.url_read = file_protocol.url_read
mpeg1_file_protocol.url_write = file_protocol.url_write
mpeg1_file_protocol.url_seek = file_protocol.url_seek
mpeg1_file_protocol.url_close = file_protocol.url_close
/* Register the append file protocol. */
#if LIBAVFORMAT_BUILD >= (52<<16 | 31<<8)
av_register_protocol(&mpeg1_file_protocol)
#else
register_protocol(&mpeg1_file_protocol)
#endif
}
我们需要在motion的Makefile中加入对ffmpeg模块的编译,并且打开HAVE_FFMPEG等开关。首先执行configure如下:
[plain] view plain copy
./configure CC=arm-linux-gnueabihf-gcc --host=arm-linux-gnueabihf --prefix=/home/stewart/iWork/common/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux
生成Makefile,在OBJ选项中添加ffmpeg.o:
[plain] view plain copy
OBJ = ffmpeg.o motion.o conf.o draw.o jpegutils.o $(VIDEO_OBJ) netcam.o \
netcam_ftp.o netcam_jpeg.o netcam_wget.o track.o \
alg.o event.o picture.o rotate.o webhttpd.o \
webcam.o
在CFLAGS选项中添加-DHAVE_FFMPEG -DFFMPEG_NEW_INCLUDES -DHAVE_FFMPEG_NEW的定义,加入libjpeg头文件搜索目录
[plain] view plain copy
libdir = ${prefix}/lib
incdir = ${prefix}/include
[plain] view plain copy
CFLAGS = -g -O2 -DHAVE_FFMPEG -DFFMPEG_NEW_INCLUDES -DHAVE_FFMPEG_NEW -D_REENTRANT
-DMOTION_V4L2 -DMOTION_V4L2_OLD -DTYPE_32BIT="int" -DHAVE_BSWAP-Wall
-DVERSION=\"3.2.12\" -Dsysconfdir=\"$(sysconfdir)\"
在LIBS中加入对ffmpeg库的支持:
[plain] view plain copy
LIBS = -L${libdir} -static -lavformat -lavcodec -lavutil -ljpeg -lm -lpthread
预备工作完成,make,编译报错:
[plain] view plain copy
motion.h:44:28: fatal error: linux/videodev.h: No such file or directory
compilation terminated.
由于linux-2.4以上的内核已经取消了videodev.h文件,需要安装libv4l-dev,然后将motion.h,video.h中的
[plain] view plain copy
#include <linux/videodev.h>
修改为
[cpp] view plain copy
#include <libv4l1-videodev.h>
继续,又报错:
[plain] view plain copy
track.c: In function ‘uvc_center’:
track.c:587:29: error: storage size of ‘control_s’ isn’t known
track.c:589:24: error: ‘V4L2_CID_PRIVATE_BASE’ undeclared (first use in this function)
track.c:589:24: note: each undeclared identifier is reported only once for each function it appears in
track.c:592:24: error: ‘VIDIOC_S_CTRL’ undeclared (first use in this function)
track.c:601:31: error: storage size of ‘queryctrl’ isn’t known
track.c:605:24: error: ‘VIDIOC_QUERYCTRL’ undeclared (first use in this function)
track.c:601:31: warning: unused variable ‘queryctrl’ [-Wunused-variable]
track.c:587:29: warning: unused variable ‘control_s’ [-Wunused-variable]
track.c:636:25: error: storage size of ‘control_s’ isn’t known
track.c:636:25: warning: unused variable ‘control_s’ [-Wunused-variable]
track.c: In function ‘uvc_move’:
track.c:724:29: error: storage size of ‘control_s’ isn’t known
track.c:726:24: error: ‘V4L2_CID_PRIVATE_BASE’ undeclared (first use in this function)
track.c:729:24: error: ‘VIDIOC_S_CTRL’ undeclared (first use in this function)
track.c:724:29: warning: unused variable ‘control_s’ [-Wunused-variable]
track.c:779:25: error: storage size of ‘control_s’ isn’t known
track.c:779:25: warning: unused variable ‘control_s’ [-Wunused-variable]
make: *** [track.o] Error 1
在track.c中添加:
[plain] view plain copy
#include <linux/videodev2.h>
继续,报错(怎么还有啊?):
[plain] view plain copy
gcc -L/usr/local/lib -o motion motion.o conf.o draw.o jpegutils.o video.o video2.o video_common.o netcam.o netcam_ftp.o netcam_jpeg.o netcam_wget.o track.o alg.o event.o picture.o rotate.o webhttpd.o webcam.o ffmpeg.o -lm -lpthread -ljpeg -L/usr/local/lib -lavformat -lavcodec -lavutil -lm -lz
/usr/local/lib/libavformat.a(file.o):(.data+0x60): multiple definition of `file_protocol'
ffmpeg.o:(.data+0x0): first defined here
collect2: ld returned 1 exit status
原来结构体file_protocol在libavformat.a和ffmpeg.o中重复定义了,分别打开两个定义:
[cpp] view plain copy
//libavformat/file.c:85
URLProtocol file_protocol = {
"file",
file_open,
file_read,
file_write,
file_seek,
file_close,
}
[cpp] view plain copy
//ffmpeg.c
URLProtocol file_protocol = {
"file",
file_open,
file_read,
file_write,
file_seek,
file_close,
#if LIBAVFORMAT_BUILD >= (52<<16 | 31<<8)
NULL,
NULL,
NULL,
#endif
}
将libavformat/file.c中的file_protocol定义注掉,重新编译一份libavformat.a。然后继续编译motion,又报错:
[plain] view plain copy
/home/xxx/iWork/Thrid_party/ffmpeg-0.5.1/libavformat/matroskadec.c:917: undefined reference to `BZ2_bzDecompressInit'
/home/xxx/iWork/Thrid_party/ffmpeg-0.5.1/libavformat/matroskadec.c:926: undefined reference to `BZ2_bzDecompress'
/home/xxx/iWork/Thrid_party/ffmpeg-0.5.1/libavformat/matroskadec.c:929: undefined reference to `BZ2_bzDecompressEnd'
这个需要libbz2库,下载地址http://www.bzip.org/downloads.html
编译安装libbz2后将-lbz2加入motion的Makefile的LIBS选项:
[plain] view plain copy
LIBS = -lpthread -ljpeg -L/usr/lib -lavformat -lavcodec -lavutil -lm -lz -lbz2
建议条件允许的话还是使用双目摄像头,毕竟双目识别图像更稳定精准。这里推荐小觅双目摄像头,基于双目视觉的三维重建与6轴传感器矫正等,并充分利用摄像头和运动传感器的互补性,保持双目高清同帧。欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)