1:opencv下載源碼
在下面網址下載linux版本的源碼
http://opencv.org/downloads.html
Qt環境的安裝配置自行完成(見本博文第7部分)
2:源碼解壓編譯
cd opencv-2.1.0
mkdir release && cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -DWITH_FFMPEG=OFF ..
make
sudo make install
安裝目錄爲/usr/local
opencv的庫文件則在 /usr/local/lib目錄下
3:常見編譯錯誤解決辦法
1:error ‘ptrdiff_t’ does not name a type opencv
解決方法:
在/include/opencv/cxcore.hpp文件中添加以下一行
using std::vector;
using std::string;
+using std::ptrdiff_t; //這是加的一行 在56行
2: error: ‘unlink’ was not declared in this scope
解決方法:
在src/highgui/loadsave.cpp中加入以下一行
#include<unistd.h>
3:error: ‘CODEC_ID_H264’ was not declared in this scope
解決方法:
方法1:
sudo apt-get install libopencv-dev
而後如下面的方法從新編譯ffmpeg:
./configure --enable-shared --disable-static
make
sudo make install
方法2:
不使用ffmpeg,直接在cmake時禁掉FFMPEG這一項
-DWITH_FFMPEG=OFF
4:undefined reference to `cvCreateCameraCapture_V4L(int)'
vim opencv-2.1.0/src/highgui/cvcap_v4l.cpp
217 #ifdef HAVE_CAMV4L
218 #include <linux/videodev.h>
219 #endif
vim opencv-2.1.0/src/highgui/cvcap.cpp
把
164 #if defined (HAVE_CAMV4L) || defined (HAVE_CAMV4L2)
改成
164 #if defined (HAVE_CAMV4L)
5:其它的幾個錯誤都是unlike不找不到declare,只面要在相應的源文件中加入unistd.h頭文件便可解決
最後終於編譯經過:
Linking CXX shared library ../../lib/cv.so
[100%] Built target cvpy
4:將本身生成的動態連接庫的路徑加入系統可找到的路徑中
sudo -s
echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf
sudo ldconfig
5:編譯Qt+opencv項目以前,在.pro文件中加入以下內容便可
//加入頭文件的路徑 編譯時使用
INCLUDEPATH +=../opencv-2.1.0/include/opencv2
//加入須要用到的庫,連接時使用
unix:!macx: LIBS += -lcv
unix:!macx: LIBS += -lcvaux
unix:!macx: LIBS += -lcxcore
unix:!macx: LIBS += -lhighgui
unix:!macx: LIBS += -lml
6:上一張陰影去除程序的圖
7:Qt環境的安裝配置
1:下載官方的qt-creator文件
qt-creator-opensource-linux-x86_64-3.2.0.run
2:從源中安裝qt4 or qt5
sudo apt-get install qt4-default
sudo apt-get install qt5-default
sudo apt-get install qtcreator
3:使用qt-creator 新建qt工程
在kits-->Qt Versions中,add /usr/bin/qmake-qt4 就能夠了