opencv安装过程中的问题与解决

来源:互联网 发布:店铺淘宝客怎么做 编辑:程序博客网 时间:2024/06/05 11:31

一直想找时间研究下opencv,趁这段时间不是很忙,就开始着手了,以下记录在安装配置opencv环境时遇到的问题:

1.在安装opencv源文件的时候,make出现了问题,大致如下:

a)error ptrdiff_t does not name a type:这个问题的解决办法是在出现该问题的文件中加入using std::ptrdiff_t,这样就认识了。

b)error no such instruction:'swpb %cl,%dl,[%edi]',类似于这类问题,是因为不认识汇编的原因,将出现该问题的文件中汇编代码用c表示即可,如我在修改过程中碰到的问题,可以修改qatomic_arm.h。
inline char q_atomic_swp(volatile char *ptr, char newval)
{
register char ret;
/*asm volatile("swpb %0,%2,[%3]"
: "=&r"(ret), "=m" (*ptr)
: "r"(newval), "r"(ptr)
: "cc", "memory");*/
ret=*ptr;
*ptr=newval;
return ret;
}


2.安装ffmpeg播视频的支持,详细依赖库的下载安装如下(来自guiru的博文http://blog.csdn.net/guiru/article/details/6023691)


a)1、lame
lame-3.97.tar.gz
Url:http://sourceforge.net/project/showfiles.php?group_id=290&package_id=309
安装方法如下:


  1. tar -zxvf lame-3.97.tar.gz  
  2. cd lame-3.97  
  3. ./configure --enable-shared --prefix=/usr  
  4. make  
  5. make install  


2、libogg
libogg-1.1.3.tar.gz
Url:http://downloads.xiph.org/releases/ogg/libogg-1.1.3.tar.gz
安装方法如下:


  1. ./configure --prefix=/usr  
  2. make  
  3. make install 


3、libvorbis
libvorbis-1.1.2.tar.gz
Url:http://downloads.xiph.org/releases/vorbis/libvorbis-1.1.2.tar.gz
安装方法如下:


  1. ./configure --prefix=/usr  
  2. make  
  3. make install  


4、xvid
xvidcore-1.1.3.tar.gz
Url:http://downloads.xvid.org/downloads/xvidcore-1.1.3.tar.gz
安装方法如下:


  1. tar zvxf xvidcore-1.1.3.tar.gz  
  2. cd xvidcore-1.1.3/build/generic  
  3. ./configure --prefix=/usr  
  4. make  
  5. make install  



5、x264
x264-snapshot-20071107-2245.tar.bz2
Url:http://www.videolan.org/developers/x264.html
ftp://ftp.videolan.org/pub/videolan/x264/snapshots/
安装方法如下:


  1. bunzip2 x264-snapshot-20070913-2245.tar.bz2  
  2. tar xvf x264-snapshot-20070913-2245.tar  
  3. ./configure --prefix=/usr --enable-shared  
  4. make  
  5. make install  



6、libdts
libdts-0.0.2.tar.gz
[url]http://download.videolan.org/pub/videolan/libdca/0.0.2/libdca-0.0.2.tar.gz [/url]

安装方法:

  1. tar zxvf libdts-0.0.2.tar.gz  
  2. cd libdts-0.0.2  
  3. ./configure --prefix=/usr  
  4. make  
  5. make install  



7、a52
a52dec-0.7.4.tar.gz
http://liba52.sourceforge.net/downloads.html
安装方法:


  1. ./configure --prefix=/usr  
  2. make  
  3. make install  


8、faad2
faad2-2.6.1.tar.gz
http://www.audiocoding.com/downloads.html
安装方法


  1. autoreconf -vif  
  2. ./configure --prefix=/usr --with-mp4v2 --enable-shared  
  3. make  
  4. make install  


9、faac
faac-1.26.tar.gz
http://linux.softpedia.com/progDownload/FAAC-Download-554.html
安装方法:

  1. tar zxvf faac-1.26.tar.gz  
  2. cd faac  
  3. ./bootstrap  
  4. ./configure --prefix=/usr  
  5. make   
  6. make install  


10、amr-nb
amrnb-6.1.0.4.tar.bz2
http://ftp.penguin.cz/pub/users/utx/amr/amrnb-6.1.0.4.tar.bz2
安装方法:


  1. ./configure --prefix=/usr  
  2. make  
  3. make install  

这一步要连接网络

11、amr-wb
amrwb-7.0.0.1.tar.bz2
http://ftp.penguin.cz/pub/users/utx/amr/amrwb-7.0.0.1.tar.bz2
安装方法:


  1. ./configure --prefix=/usr  
  2. make  
  3. make install  


这一步要连接网络
12、lib52
a52dec-0.7.4.tar.gz
http://liba52.sourceforge.net/downloads.html

如果前面的安装一切顺利的话,恭喜你,可以安装ffmpeg了

b.在安装faac的过程中,出现了

/usr/include/string.h:369:28: error: previous declaration of ‘const char* strcasestr(const char*, const char*)’ with ‘C++’ linkage

mpeg4ip.h:126:64: error: conflicts with new declaration with ‘C’ linkage

修改faac下的common/mp4v2/mpeg4ip.h 加上const,即将函数的参数类型和返回类型都改成与系统的一致。(不要去修改系统下的string.h),再将那个大红字C->C++就可以了。


c)./configure --prefix=/usr --enable-gpl --enable-shared --enable-libmp3lame --enable-libogg --enable-libvorbis --enable-libamr-nb --enable-libamr-wb --enable-libxvid --enable-libx264 --enable-liba52 --enable-liba52bin --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-pp --enable-pthreads --disable-ffserver --disable-ffplay 
在ffmpeg执行这句时,如有报错,则按照报错信息修改,增删即可。

最新:改为./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab --disable-ffserver


3.opt/opencv/opencv-2.4.9/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘void CvVideoWriter_FFMPEG::close()’:
/opt/opencv/opencv-2.4.9/modules/highgui/src/cap_ffmpeg_impl.hpp:1445:29: error: ‘avformat_free_context’ was not declared in this scope
make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.cpp.o] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error
opencv2.2.0的版本,所以ffmpeg要0.8版本以下

4.modules/highgui/CMakeFiles/opencv_highgui.dir/all这个问题,

在cmake-gui时取消掉INSTALL-OPENXER和WITH-OPENXER,再重新编译就好了。(参考http://blog.sina.com.cn/s/blog_92942dba0101d1wj.html)

5.出现类似undefined reference to `cvCreateCameraCapture_V4L(int)'错误.的语句,解决:(参考:http://blog.csdn.net/dayeshisir/article/details/6625400)

在下载的源代码里面找到OpenCV-2.2.0/modules/highgui/src/cap_v4l.cpp,171171            if (capture) 172172                return capture; 173173        #endif 174         //把本行后面的删掉,就变成本行下面的一行#if defined (HAVE_CAMV4L) || defined (HAVE_CAMV4L2)  174        #if defined (HAVE_CAMV4L) 175175            capture = cvCreateCameraCapture_V4L (index); 176176            if (capture) 177177                return capture; 

6./usr/local/include/libavutil/common.h:175:47: error: ‘UINT64_C’ was not declared in this scope问题:

解决:

在头文件中加入:

#ifndef   UINT64_C


#define   UINT64_C(value)__CONCAT(value,ULL)


#endif


7.libhighgui.so.2.0.0: undefined reference to `cvCreateCameraCapture_V4L(int)'

我这边试的版本是2.0.0的opencv,所以是这么改的OpenCV-2.0.0/src/highgui/cvcap.cpp:(红色部分)

        case CV_CAP_VFW:
        #ifdef HAVE_VFW
            capture = cvCreateCameraCapture_VFW (index);
            if (capture)
                return capture;
        #endif
        /*#if defined (HAVE_CAMV4L) || defined (HAVE_CAMV4L2)*/修改为
#if defined HAVE_LIBV4L || (defined (HAVE_CAMV4L) && defined (HAVE_CAMV4L2))

            capture = cvCreateCameraCapture_V4L (index);
            if (capture)
                return capture;

然后修改: OpenCV-2.0.0/src/highgui/OpenCV-2.0.0/src/highgui(205行):(红色部分)(可参考:https://code.ros.org/trac/opencv/changeset/5099)

/*#if !defined WIN32 && defined HAVE_CAMV4L && defined HAVE_CAMV4L2*/修改为
#if !defined WIN32 && defined HAVE_LIBV4L 

8.执行

./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg
时,出现了问题:./facedetect: error while loading shared libraries: libcxcore.so.2.0: cannot open shared object file: No such file or directory
解决:在终端执行export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib


总结:以上为我安装配置opencv过程中遇到的部分问题,有些问题当时改了没来得及记下来,承认说,在配置过程中遇到了很多问题,版本不匹配,ffmpeg没安装成功等,没一次错误,都会学到很多东西。

0 0
原创粉丝点击