How to Build Development Environment for OpenCV

What is it?

OpenCV is open source library for computer vision.
OpenCV contains the various processing for image that retrieved from camera and image files.

Features

The features are contained in the OpenCV as follows.
It also have the contribution modules in addition these core modules.

  • core functionality
  • image processing
  • video processing
  • calibration
  • features
  • object detection
  • image/video io
  • gui
  • gpu

Development Environment

OpenCV supported OS is Linux, Windows, MacOS X, Android, iOS.
Supported development language is C++, Python and Java.*1

*1 C API was already end of support.

Versions

Currently, OpenCV have release two versions that developing in parallel.
OpenCV 3.x is latest version.
OpenCV 2.4.x is LTS (Long Term Support) version.

Download

OpenCV has been distributed pre-built library.
You can download OpenCV for Windows version from following.

Install

Please extract self-extracting compressed file that downloaded.
Then, You need replace opencv folder to any directory.
(e.g. C:Program Filesopencv)

Generate Your Own Project using CMake

You will create own project to use OpenCV.
I will show how to generate a project using the CMake in here.

What is CMake?

CMake is cross-platform build tool that is widely used in open source software.
You can generate build file for variety development environments from simple configuration script (CMakeLists.txt).

Please refer how to wrtiting CMakeLists.

Basic CMakeLists for OpenCV

Please refer basic CMakeLists for setting OpenCV.
OpenCV_DIR will specify directory where includ OpenCVConfig.cmake.

  • Basic CMakeLists for OpenCV | GitHub Gist
  • cmake_minimum_required( VERSION 3.6 )
    
    # Create Project
    project( solution )
    add_executable( project main.cpp )
    set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "project" )
    
    # Find OpenCV
    set( OpenCV_DIR "C:/Program Files/opencv/build" )
    find_package( OpenCV REQUIRED )
    
    # Project Settings for OpenCV
    if( OpenCV_FOUND )
      # Additional Include Directories
      # [C/C++]>[General]>[Additional Include Directories]
      include_directories( ${OpenCV_INCLUDE_DIRS} )
    
      # Additional Library Directories
      # [Linker]>[General]>[Additional Library Directories]
      link_directories( ${OpenCV_LIB_DIR} )
    
      # Additional Dependencies
      # [Linker]>[Input]>[Additional Dependencies]
      target_link_libraries( project ${OpenCV_LIBS} )
    endif()
    

Set Environment Variables

The following message will displayed in output when generated project CMake.
Please set path to environment variable Path in accordance with message.
(e.g. C:Program Filesopencvbuildx64vc14bin)

You might need to add C:Program Filesopencvbuildx64vc14bin to your PATH to be able to run your applications.

Reference

If you want to learn OpenCV, Please refer to following.

Web

Book


Leave a Reply

Your email address will not be published. Required fields are marked *