安裝opencv2.4.9


 首先如果你的運氣足夠好,你完全可以按照 :

https://my.oschina.net/u/1757926/blog/293976

或者OpenCV中文論壇上的Linux下opencv的安裝方法

但是我的運氣不好,上述兩種方法安裝不了,參考這個:鏈接


我把過程分析如下.

  1. 由於opencv的cmakelist里依賴一些庫,所有要先配置好這些庫,我主要是ffmpeg和x264很煩人: 保險起見,先去除你電腦上的這些重新裝.

    sudo apt-get remove ffmpeg x264 libx264-dev

  2. 安裝其他依賴庫.

    sudo apt-get update
    sudo apt-get install build-essential checkinstall Git cmake libfaac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html yasm zlib1g-dev

  3. 安裝gstreamer,主要是opencv里頭的相機模塊用到

    sudo apt-get install libgstreamer0.10-0 libgstreamer0.10-dev gstreamer0.10-tools gstreamer0.10-plugins-base libgstreamer-plugins-base0.10-dev gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad gstreamer0.10-ffmpeg

  4. 安裝,接着安裝

    sudo apt-get install libgtk2.0-0 libgtk2.0-dev

  5. sudo apt-get install libjpeg8 libjpeg8-dev

  6. 安裝 install x264
    1. Download a recent stable snapshot of x264 from ftp://ftp.videolan.org/pub/videolan/x264/snapshots/. The exact version does not seem to matter. To write this guide, I used version x264-snapshot-20120528-2245-stable.tar.bz2, but I have used previous versions too.

      cd ~/src

      wget ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20120528-2245-stable.tar.bz2

      tar xvf x264-snapshot-20120528-2245-stable.tar.bz2

      cd x264-snapshot-20120528-2245-stable

    2.  

      ./configure --enable-shared --enable-pic
      make
      sudo make install

      PS:由於我的電腦是64,所以要加上 --enable-shared --enable-pic ,否則就會報錯:
      /usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet' can not be used when making a shared object; recompile with -fPIC
      /usr/local/lib/libavcodec.a: could not read symbols: Bad value
  7. 安裝ffmpeg
    1. Download ffmpeg version 1.2 from http://ffmpeg.org/download.html.PS:裝ffmpeg-0.11.1編譯不通過,報錯:
    2. /usr/local/lib/libswscale.a(swscale_unscaled.o): relocation R_X86_64_32S against `av_pix_fmt_descriptors@@LIBAVUTIL_52' can not be used when making a shared object; recompile with -fPIC
      /usr/local/lib/libswscale.a: error adding symbols: 錯誤的值
      collect2: error: ld returned 1 exit status
      make[2]: *** [lib/libopencv_highgui.so.2.4.9] 錯誤 1
      make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] 錯誤 2
      make: *** [all] 錯誤 2

      猜可能是opencv249依賴的ffmpeg版本不對照

      cd ~/src
      wget http://ffmpeg.org/releases/ffmpeg-1.2.tar.bz2
      tar xvf ffmpeg-1.2.tar.bz2
      cd ffmpeg-1.2

    3.     

      ./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 --enable-shared --enable-pic

      make
      sudo make install


  8. 安裝v4l (video for linux) from http://www.linuxtv.org/downloads/v4l-utils/.
    報錯:dvb-v5.h:69:9: error: ‘NULL’ undeclared here ........原因是v4l的版本不對,於是我裝了v4l 1.0.0
    wget http://www.linuxtv.org/downloads/v4l-utils/v4l-utils-1.0.0.tar.bz2
  9. tar xvf v4l-utils-1.0.0.tar.bz2
    cd v4l-utils1.0.0
    make
    sudo make install

  10. 安裝OpenCV 2.4.9.
    1. Download OpenCV version 2.4.2 from http://sourceforge.net/projects/opencvlibrary/files/

      cd ~/src

      wget http://downloads.sourceforge.Net/project/opencvlibrary/opencv-unix/2.4.9/OpenCV-2.4.9.tar.bz2

      tar xvf OpenCV-2.4.9.tar.bz2

    2. Create a new build directory and run cmake:

      cd OpenCV-2.4.9/
      mkdir build
      cd build
      cmake -D CMAKE_BUILD_TYPE=RELEASE ..

    3. 驗證指定的輸出包括以下內容:
      • found gstreamer-base-0.10
      • GTK+ 2.x: YES
      • FFMPEG: YES
      • GStreamer: YES
      • V4L/V4L2: Using libv4l
    4. Build and install OpenCV.

      make
      sudo make install

  11. Configure  配置 Linux.
    1. Tell linux where the shared libraries for OpenCV are located by entering the following shell command:[告訴Linux的共享庫OpenCV是通過輸入下面的shell命令,也就是其庫文件存放的位置]:

      export LD_LIBRARY_PATH=/usr/local/lib 

      Add the command to your .bashrc file so that you don’t have to enter every time your start a new terminal.該命令添加到你的.bashrc文件,這樣你就不需要進入你的每一次開始一個新的終端。

      Alternatively, you can configure the system wide library search path. Using your favorite editor, add a single line containing the text /usr/local/lib to the end of a file named /etc/ld.so.conf.d/opencv.conf. In the standard Ubuntu install, the opencv.conf file does not exist; you need to create it. Using vi, for example, enter the following commands:[或者,您可以配置系統范圍的庫搜索路徑。用你喜歡的編輯器,添加一行文本/usr/local/lib...to the end of a file named/ etc / ld.so.conf.d/opencv.conf。在標准的Ubuntu的安裝,opencv.conf文件不存在;你需要創建它。例如,使用VI,輸入以下命令:]

      sudo vi /etc/ld.so.conf.d/opencv.conf
      G
      o
      /usr/local/lib
      <Esc>
      :wq!

      After editing the opencv.conf file, enter the following command:

      sudo ldconfig /etc/ld.so.conf

    2. Using your favorite editor, add the following two lines to the end of /etc/bash.bashrc:

      PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
      export PKG_CONFIG_PATH

 

c.After completing the previous steps, your system should be ready to compile code that uses the OpenCV libraries. The following example shows one way to compile code for OpenCV:

   g++ `pkg-config opencv --cflags` my_code.cpp  -o my_code `pkg-config opencv --libs`

就這樣吧.....最好按照步驟來,先裝好依賴庫再搞別的...


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM