美文网首页
opencv源码安装

opencv源码安装

作者: sudocloud | 来源:发表于2019-11-18 01:03 被阅读0次

参考

1. 依赖库下载

  [compiler] sudo apt-get install build-essential
  [required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
  [optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

2. 源码下载

git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

3. 编译安装

cd ~/opencv
git pull
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..
make -j8
cd ~/opencv/build/doc/
make -j8 doxygen
sudo make install

4.代码测试

main.cpp

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, char** argv )
{
    if ( argc != 2 )
    {
        printf("usage: DisplayImage.out <Image_Path>\n");
        return -1;
    }

    Mat image;
    image = imread( argv[1], 1 );
    if ( !image.data )
    {
        printf("No image data \n");
        return -1;
    }

    namedWindow("Display Image", WINDOW_AUTOSIZE );
    imshow("Display Image", image);
    waitKey(0);
   
    return 0;
}

CMakeLists.txt

project(opencv_test)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_STANDARD 11)

find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})
aux_source_directory(. DIR_SRCS)
add_executable(opencv_test ${DIR_SRCS})

target_link_libraries(opencv_test ${OpenCV_LIBS})

相关文章

网友评论

      本文标题:opencv源码安装

      本文链接:https://www.haomeiwen.com/subject/mrzmictx.html