opencv安裝過程中的問題與解決

一直想找時間研究下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沒安裝成功等,沒一次錯誤,都會學到很多東西。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章