ubuntu14下更简单的安装opencv

首先下载opencv3.1.0的源码: https://github.com/Itseez/opencv/archive/3.1.0.zip
编译之前,需要安装opencv的依赖项

sudo apt-get install build-essential libgtk2.0-dev libvtk5-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev libtbb-dev

之后进入源码的文件夹进行编译

cd ~/opencv  #源码的文件夹路径
mkdir build
cd build
cmake ..
make

最后,不仅仅是编译,还需要安装它

sudo make install

测试代码:
找到cmakelist.txt和cpp文件的目录,
选中cmakelist.txt进行编译

cmake_minimum_required( VERSION 2.8 )

project( imageBasics )

# 添加c++ 11标准支持

set( CMAKE_CXX_FLAGS "-std=c++11" )

# 寻找OpenCV库

find_package( OpenCV REQUIRED )

# 添加头文件

include_directories( ${OpenCV_INCLUDE_DIRS} )

add_executable( imageBasics imageBasics.cpp )

# 链接OpenCV库

target_link_libraries( imageBasics ${OpenCV_LIBS} )

 

显示图像程序imageBasics.cpp

 

#include

#include

int main( int argc, char** argv ) {

    cv::Mat image;

  image = cv::imread("sample.jpeg" , CV_LOAD_IMAGE_COLOR);

    if(! image.data ) {

      std::cout <<  "Could not open or find the image" << std::endl ;

      return -1;

    }

   cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE );

  cv::imshow( "Display window", image );

   cv::waitKey(0);

  return 0;

}

mkdir build

cd build

cmake ..

make

 

运行 ./imageBasics


 

你可能感兴趣的:(openCV,linux,opencv)