ubantu14.04+ opencv-2.4.9+QT
總結一些大佬的經驗,加上自己親測可行。
一、永恆的第一步,先祭系統
sudo apt-get update
sudo apt-get upgrade
二、工具準備
安裝cmake
sudo apt-get install cmake
sudo apt-get install cmake-curses-gui
安裝gtk
sudo apt-get install gnome-core-devel
sudo apt-get install pkg-config
pkg-config –modversion gtk+-2.0
新增依賴項
sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev
三、安裝 OpenCV
建立opencv資料夾
mkdir opencv
cd /opencv/
解除安裝任何以前安裝的ffmpeg和x264軟體
sudo apt-get -qq remove ffmpeg x264 libx264-dev
安裝一些依賴關係
sudo apt-get -qq install libopencv-dev build-essential checkinstall cmake pkg-config yasm libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils
安裝ffmpeg
sudo add-apt-repository ppa:mc3man/trusty-media
sudo apt-get update
sudo apt-get install ffmpeg gstreamer0.10-ffmpeg
將從官網下載的原始碼 opencv2.4.9.zip 複製到 /home/own 下,cd到該目錄,執行
unzip opencv2.4.9.zip
cd opencv2.4.9
mkdir release
cd release
ccmake ../
進入ccmake後,按 c 就會彈出如下介面
我基本什麼都沒改,就把 BUILD_JPEG 和 BUILD_PNG 這兩項改成了 ON ,其餘全部都預設,鍵盤按c,然後按g,然後就回到命令列介面,
make
sudo make install
到了這一步,opencv就已經安裝得差不多了,接下來,
四、配置檔案
sudo vim/etc/ld.so.conf.d/opencv.conf
sudo apt-get install vim
切換到root
sudo su
注意:很多時候可能機器不存在conf檔案,可以切換到root使用者許可權用vim opencv.conf建立新檔案,包括下面
按i插入/usr/local/lib。ESC鍵->:wq->回車退回命令列
sudo ldconfig
cd /etc
vim bash.bashrc
新增下面兩行到檔案的末尾並儲存(:wq)
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
sudo ldconfig
四,重啟測試
reboot
cd/home/own/opencv-2.4.9/samples/c
./build_all.sh
./find_obj
QT
1、下載地址:http://download.qt.io/archive/qt/
選擇合適的版本,好像5.0後的版本才支援C++11。具體參考官方文件。
2.QtTest.pro
注意這裡的配置內容就像在Windows+VS+OpenCV環境下配置安裝檔案一樣的,新增包含目錄,附加依賴項,要根據opencv的安裝目錄編寫引用路徑
INCLUDEPATH += /usr/local/include \
/usr/local/include/opencv \
/usr/local/include/opencv2
LIBS += /usr/local/lib/libopencv_highgui.so \
/usr/local/lib/libopencv_core.so \
/usr/local/lib/libopencv_imgproc.so