OpenCV安裝(Linux)相關(guān)問題及解決

一、OpenCV的安裝: 選擇Ubuntu14.04LFS + opencv2.4.11 ,具體參考官方提供的安裝教程

1.先安裝個叫cmake 的工具,使用 sudo apt-get install cmake ,安裝的應(yīng)該是最新版;另外可以安裝cmake的圖形界面
$ sudo apt-get install cmake-gui
輸入cmake-gui 即可打開圖形界面,可以updatedb 一下軟件更新。

2.安裝好cmake 后接著下一步,這步很重要,你需要解決很多依賴關(guān)系,比如支持jpg,jpeg,png等圖形格式、movies等的讀寫。看操作:在命令行輸入以下一串東西:
$ sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev

3.下載OpenCV的安裝包
3.1 $ cd ~ # 切換到用戶目錄 /home/user_name/
3.2 使用 wget 命令下載安裝到當(dāng)前工作目錄;也可以去官網(wǎng)點擊下載你所需版本。
3.3 解壓
.zip的解壓 unzip xxxxxxx.zip ;
.tar.bz2的解壓 tar -xvf xxxxxx.tar.bz2
3.4.進(jìn)入解壓后的文件目錄下,例如 cd opencv2.4.11/

  1. 執(zhí)行以下三個命令
    $ mkdir release
    $ cd release
    $ cmake ..

5.上一步執(zhí)行成功后,接著進(jìn)行
$ make
$ sudo make install

  1. 等待上一步執(zhí)行成功需要一些時間,等待上一步執(zhí)行成功。以上執(zhí)行成功后進(jìn)行一些路徑、環(huán)境變量的配置。
    6.1 $ sudo vim /etc/ld.so.conf.d/opencv.conf 寫入 /usr/local/lib 保存
    6.2 $ sudo ldconfig
    6.3 $ sudo vim /etc/bash.bashrc 在末尾寫入
    PKG_CONFIG_PATH=$ PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
    Export PKG_CONFIG_PATH
  1. 最后,restart 重啟電腦,否則OpenCV 可能不會正常工作,如果不這么做的話!

  2. 完成以上所有步驟后,接下來就是check一些opencv自帶的demos
    $ cd ~
    $ mkdir openCV_samples
    $ cp OpenCV-2.1.0/samples/c/* openCV_samples
    $ cd openCV_samples/
    $ chmod +x build_all.sh
    $ ./build_all.sh

接著輸入
$ ./facedetect --cascade="/usr/local/share/opencv/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg


1.png

$ ./bgfg_segm tree.avi
2.png
3.png

如果以上步驟都成功執(zhí)行,那就成功安裝了opencv。

二、不能夠成功編譯

我的實例:
4.png
5.png

Can't compile opencv in linux問題的解決
詳見鏈接:https://stackoverflow.com/questions/11532963/cant-compile-opencv-in-linux

Try this:
g++ pkg-config --cflags opencv -o hello hello.cpp pkg-config --libs opencv

You can call pkg-config like pkg-config --cflags --libs opencv, too.

According to the [GCC manual] (https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html#Link-Options)

It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded.

So the pkg-config --libs opencv has to come at the end of the the filename, else gcc will not be able to resolve the symbols.

g++ hello.cpp -o hello pkg-config --cflags --libs opencv

By Comma.He
Date 2015/07/07

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容