进来需要在linux下用到opencv,虽然linux中自带的python自带了opencv类似的图像处理函数,但是如果在linux中写C++ 就不好玩了,所以今天琢磨了好久才弄明白linux下怎么使用opencv。
参考链接:
http://www.linuxidc.com/Linux/2015-05/116960.htm
http://jingyan.baidu.com/article/14bd256e466474bb6d2612db.html
http://blog.csdn.net/keith_bb/article/details/52685231
http://www.it165.net/pro/html/201407/17019.html
1.从官网下载opencv(http://opencv.org/),选择自己需要的opencv版本;
2.将opencv 解压,比如解压后的opencv地址是:/home/lily/software/opencv-3.2.0,在这个地址下有一个CMakeLists.txt文件;
3.在目录 /home/lily/software/opencv-3.2.0下面打开一个linux终端,输入 (cmake . ),注意括号里面的输入是cmake+空格+黑点,输入后按enter键,会出现一大串的执行命令;
4.配置opencv相关路径
4.1)在linux系统中打开/etc/ld.so.conf.d/opencv.conf,如果这个opencv.conf不存在,可以新建一个,然后在opencv.conf中加入一句:/usr/local/lib,这样子系统就可以找到opencv了,在/etc/ld.so.conf.d中打开终端,然后执行:sudoldconfig
4.2)在linux系统中打开/etc/bash.bashrc,这个文件是已经存在的,在它的末尾加上一下两句,然后保存并关闭:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/videoio.hpp"
#include <iostream>
using namespace std;
{
cout << "Read an image and display " << endl;
Mat image = imread("lena.jpg");
imshow("lena",image);
waitKey(0);
return 0;
}
cmake_minimum_required(VERSION 2.8)
project(opencv_hello_project)
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV required)
# be set,you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
# Add OpenCV headers location to your include paths
include_directories(${OpenCV_INCLUDE_DIRS})
endif()
add_executable(opencv_hello hello.cpp)
target_link_libraries(opencv_hello ${OpenCV_LIBS})