Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring an c++ OpenCV project with Cmake

Tags:

opencv

cmake

I consider this a fundamental step for creating projects that use OpenCV libraries so you don't need to manually include all the libraries. There is not detailed information on this topic, at least for a newbie that just wants to use OpenCV as soon as posible, so:

Which is the easiest and scalable way to create a multiplatform c++ OpenCV with Cmake?

like image 281
Jav_Rock Avatar asked Dec 20 '12 10:12

Jav_Rock


People also ask

Is CMake necessary for OpenCV?

It's not required to compile OpenCV if you don't need the latest version of OpenCV. Please note that some parts of this procedure are slightly outdated but still you will find your way to the successful installation of the library.


1 Answers

First: create a folder Project containing two subfolders src and include, and a file called CMakeLists.txt.

Second: Put your cpp inside the src folder and your headers in the include folders.

Third: Your CMakeLists.txt should look like this:

cmake_minimum_required(VERSION 2.8)  PROJECT (name) find_package(OpenCV REQUIRED ) set( NAME_SRC     src/main.cpp     )  set( NAME_HEADERS             include/header.h )  INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include ) link_directories( ${CMAKE_BINARY_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) add_executable( name ${NAME_SRC} ${NAME_HEADERS} )  target_link_libraries( sample_pcTest ${OpenCV_LIBS} ) 

Fourth: Open CMake GUI and select the root folder as input and create a build folder for the output. Click configure, then generate, and choose the generator (VisualStudio, Eclipse, ...)

like image 195
Jav_Rock Avatar answered Sep 28 '22 05:09

Jav_Rock