OPENCV_PATH = C:/opencv/build # 你的opencv folder
INCLUDEPATH += $${OPENCV_PATH}/include \
$${OPENCV_PATH}/include/opencv \
$${OPENCV_PATH}/include/opencv2
CONFIG(release, debug|release) {
LIBS += $${OPENCV_PATH}/x64/vc11/lib/opencv_highgui249.lib \
$${OPENCV_PATH}/x64/vc11/lib/opencv_imgproc249.lib \
$${OPENCV_PATH}/x64/vc11/lib/opencv_core249.lib
# .... 你想用的库 release 版本 /x64, /vc11 对应你的编译器版本
}
CONFIG(debug, debug|release) {
LIBS += $${OPENCV_PATH}/x64/vc11/lib/opencv_highgui249d.lib \
$${OPENCV_PATH}/x64/vc11/lib/opencv_imgproc249d.lib \
$${OPENCV_PATH}/x64/vc11/lib/opencv_core249d.lib
# .... 你想用的库 debug 版本, /x64, /vc11 同上
}
OpenCV 2.4.3同样适用,1.安装必要的依赖包
这一步我略去了,因为原文中提到的ffmepg1我并不需要安装,并且我是从第一种方式转过来的,就没有安装这些包,不过还是列在下面:
sudo apt-get install build-essential libgtk2.0-dev libjpeg62-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev
2.安装OpenCV
(1)下载OpenCV 2.4.3
(2) tar -xvf OpenCV-2.4.3.tar.bz2
(3)将其复制到 “ home/你的计算机名/”下;
(4)cd OpenCV-2.4.3
(5)mkdir release
(6)cd release
(7)
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_TBB=ON -D WITH_V4L=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON ..
如果没有cmake,apt-get install就行
(8) make
(9)sudo make install
3.添加库的路径
(1)sudo gedit /etc/ld.so.conf.d/opencv.conf
文件可能需要创建,添加下面内容并保存
/usr/local/lib
(2)sudo ldconfig
(3) sudo gedit /etc/environment
添加下面内容
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
这时,再回到OpenCV-2.4.3/sample/cpp下时,用第一种方式的测试方法,drawing.cpp文件就能正确编译,而且也可以通过生成的文件看到效果了。
2013.1.6更新:QT调用openCV库
QT的安装过程就略去了,注意需要QT设计器和QTcreator,前者我是下源码编译的,后者用软件中心装的。
配置QT, sudo gedit /usr/share/qt4/mkspecs/default/qmake.conf
在文件内添加了下面两句:
QMAKE_INCDIR = /usr/include/opencv
QMAKE_LIBS = -lcvaux -lcv -lcxcore -lhighgui -lml
实例程序,创建一个QT4 Console Application,代码如下:
#include <cv.h>
#include <highgui.h>
int main()
{
IplImage *img = 0
img = cvLoadImage("Lena.bmp",-1)//Lena.bmp在所建工程的目录下
cvNamedWindow("lena", 1)
cvShowImage("lena", img)
cvWaitKey(0)
return 0
}
关键的一步,在工程的.pro文件添加下面的内容:
INCLUDEPATH += /usr/include/opencv
LIBS += /usr/lib/libcv.so \
/usr/lib/libcvaux.so \
/usr/lib/libcxcore.so \
/usr/lib/libhighgui.so \
/usr/lib/libml.so
这时就能编译运行了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)