ubuntu下编译 安装opencv和demo

2017-04-19  本文已影响710人  liouville

[TOC]

编译

上官网:http://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html
注意:cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

设置环境

如果你的opencv不是安装在/usr/local/下,而是在自己的home目录下的话,还需要设置环境变量

vim ~/.bashrc
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:XXXX/lib/pkgconfig
export OpenCV_INCLUDE_DIRS=XXXX/inlcude:$OpenCV_INCLUDE_DIRS

其中XXXX代表opencv的安装路径

source ~/.bashrc使其生效

验证安装成功

在build目录下,进入../samples/cpp/example_cmake
执行以下三步:

cmake .
make
./opencv_example

eclipse配置opencv

新建c++工程

复制一下代码

#include "highgui.h"

int main(int argc, char** argv) {
   IplImage* img = cvLoadImage("/home/liouville/devres/闲乐/切图/main_new.jpg");
   cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE);
   cvShowImage( "Example1", img);
   cvWaitKey(0);
   cvReleaseImage(&img);
   cvDestroyWindow ("Example1");


}

配置

property -> c/c++ build ->Settings-> ToolSettings
选择c++ compile tab,include -> include
添加三个值:

<opencv_home>/include
<opencv_home>/include/opencv
<opencv_home>/include/opencv2

再选择c++ Linker -> Libraies,在search path中添加
<opencv_home/lib>
在Libraies中添加

opencv_highgui
opencv_core

编译,运行

 cd ld.so.conf.d/
 vim opencv.conf
 add path of libopencv_core.so.2.4 file in that file (without "libopencv_core.so.2.4").
 sudo ldconfig -v

最后终于还是看到图像了

参考:
http://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html
https://huanglu.me/2016/12/29/ubuntu-opencv-complie/#make
http://answers.opencv.org/question/46755/first-example-code-error/
https://ubuntuforums.org/showthread.php?t=2109967
http://blog.csdn.net/tingyuanss/article/details/45021159

上一篇下一篇

猜你喜欢

热点阅读