OPENCV configuration, never so simple!

Source: Internet
Author: User

Configure your own OPENCV program with CMake---configuration OpenCV is never so simple!

This article needs certain cmake knowledge, the recommendation reads the Chinese CMake practice.pdf , as to what CMake is, I can only say that he is a cross-platform project management tools, specifically please Sir Baidu. Here is a hypothesis that you have read the PDF, you do not know also please self-turn book.

Yesterday in the online learned, with CMake write their own OPENCV program only need to use a CMakeLists.txt, with the Almighty CMake command can generate omnipotent makefile file, automatic configuration header file contains, library contains, automatically connect Lib file.

For details, see the Official document using OpenCV with GCC and CMake, but the official documents were carried out in GCC, and I used VS2013, so after a morning struggle, the way to configure the Windows platform was resolved. The following is an overview:

Configuring OPENCV requires only one CMakeLists.txt

Cmake_minimum_required (VERSION 2.8) Project (displayimage) Find_package (OpenCV required) add_executable (displayimage DisplayImage.cpp) target_link_libraries (DisplayImage ${opencv_libs})

which

cmake_minimum_required (version 2.8) specifies the minimum cmake version, which means that more than 2.8 versions must be used

Project (displayimage) defines a project (vs solution) called displayimage

find_package (OpenCV REQUIRED) key sentence, find OpenCV configuration, and automatically configure

add_executable (displayimage DisplayImage.cpp) add an executable file, the VC in the project, called DisplayImage, the source file used is DisplayImage.cpp

target_link_libraries (DisplayImage ${opencv_libs}) key to the second sentence, specify the link library, where opencv_libs is the key sentence in the generated

Personal guess: On platforms such as Linux and Mac, you need to install OPENCV with make install, and then execute it in the OpenCV source directory:

mkdir BUILDCD Buildcmake. /makemake Install

Test, confirmed:

On the Windows platform, you need to add an environment variable cmake_prefix_path its contents as:

Your OpenCV directory/build

The aim is for CMake to find

Opencvconfig.cmake

Opencvconfig-version.cmake

Two files, then CMake will follow it to determine the correct build platform and mode, so that vs can be like GCC and so can be used to build CMake project files!

* Do not add cmake_prefix_path variable sometimes can also work, just sometimes can not, specifically unclear why

* Of course, you will have to include the CMake Bin directory in path so you can use the CMake command directly

The OpenCV configuration file (Opencvconfig.cmake) generates a series of cmake quantities:

#-Opencv_libs:the List of libraries to links against.

#-Opencv_lib_dir:the directory (es) where LIB files are. Calling Link_directories

# with the This path was not needed.

#-Opencv_include_dirs:the OpenCV INCLUDE directories.

#-Opencv_compute_capabilities:the version of COMPUTE capability

#-Opencv_android_native_api_level:minimum required level of ANDROID API

#-Opencv_version:the VERSION of this OpenCV build. Example: "2.4.0"

#-Opencv_version_major:major VERSION part of Opencv_version. Example: "2"

#-Opencv_version_minor:minor VERSION part of Opencv_version. Example: "4"

#-Opencv_version_patch:patch VERSION part of Opencv_version. Example: "0"

#

# Advanced Variables:

#-Opencv_shared

#-Opencv_config_path

#-Opencv_lib_components

#

# ===================================================================================

#

# Windows Pack Specific options:

#-Opencv_static

#-Opencv_cuda



OPENCV configuration, never so simple!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.