OpenCV and CMake
From OpenCV 2.1 version we can use CMake to create and manage our OpenCV projects.
CMake is a cross-platform and open-source build system, and it’s used to control our compilation process, using a simple text files for define compilation process with independent platform and compiler.
Thanks to CMake we can create our project in our operating system as linux compile and work in it, and then use it to compile a new version in other os as windows, osx, …, even create a visual studio project, xcode project or eclipse.
To create a basic project with 1 main.c file with cmake and opencv we must create a new file called CMakeList.txt.
In this file we go to define the compiler process and his requeriments.
First we need create a project name:
PROJECT( project_name )
We need find OpenCV libraries. OpenCV is required by our project and it’s defined with REQUIRED statement:
FIND_PACKAGE( OpenCV REQUIRED )
Then we must defined our executable, his name and the dependent files, in our example only main.c, and we go to use the project name for the executable name. This name is stored in ${PROJECT_NAME} variable.
ADD_EXECUTABLE( ${PROJECT_NAME} main.c )
To finish, we must link OpenCV to our executable, to do this only need call TARGET_LINK_LIBRARIES statement, with the project name and OpenCV library.
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} {OpenCV_LIBS} )
The CMakeList.txt was defined, then we can compile our project. To do this only need create a directory where we want get our executable. Then we call cmake with the directory where CMakeList.txt and main.c files are saved.
When cmake finish whe can call make to compile our project under unix.
If we want create a VisualStudio project under Windows, only need open CMake Gui and select the source code and build directories and cmake detect our visualstudio version and with generate button create our VisualStudio project.
Sample Code:
PROJECT( Nombre_del_proyecto )
FIND_PACKAGE( OpenCV REQUIRED )
ADD_EXECUTABLE( ${PROJECT_NAME} main.c )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} {OpenCV_LIBS} )
7 Comments + Add Comment
Got anything to say? Go ahead and leave a comment!
Category
- blenderocv (1)
- Personal (2)
- Tutorials (24)
- ActionScript (1)
- Blender (2)
- CSS (1)
- Java and Netbeans (1)
- Linux/Unix (7)
- OpenCV (15)
- OpenGL (1)
- other (4)
- Uncategorized (2)
- Works (2)
Last comments
Tag cloud
Twitter: damiles3D
- Finishing coding a card marker AR functions in API. Next step, facedetection.
- Que tardecita. Después de correr 5km para recoger el coche acabo haciendo un duatlon cogiendo bici para volver en tren. X(
- En el tren de camino al trabajo. Lunes lunero....
- @Neoxisme do you want this list of camera features to set http://t.co/jCqNnWct
- Finished QR integration, and first basic UI OpenGL framework.
- Review Finished, I like this chapter. Now continue developing OpenGL user interfaces and Events management
- Reviwing a book... only review 30 pages and 15 gnuplot scripts.
- @pipotux Siempre que puedas evitar pagar la licencia ;)
- @pipotux Suena dificil! :S
- @joshis_tweets Check this first. Read it http://t.co/3AEMSxRa




Posted under:
And if you need to check the OpenCV version you can use this
IF (${OpenCV_VERSION} VERSION_LESS 2.0.0)
MESSAGE(FATAL_ERROR “OpenCV version is not compatible : ${OpenCV_VERSION}”)
ENDIF()
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} {OpenCV_LIBS} )
should be:
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${OpenCV_LIBS} )
and CMakeList.txt needs to be CMakeLists.txt
Mark
how to create a trainning data into file xml using boosting? I really appreciate you for helping me.
If possible, can you send me some document to do.
Thank you
You use the cvMat for train boosting, then when you have this mat created, save it in xml or yaml with opencv functions http://opencv.willowgarage.com/documentation/cpp/core_xml_yaml_persistence.html
On linux in a GTK environment I use Anjuta. It is a young IDE, but has potential and integrates well with Gnome. It is written in C/C++ so its not a slow Java IDE.
Is this can run on ios
[...] you through the process of using CMake to compile and build OpenCV projects. It is based on the tutorial made by Damilesbut has some minor [...]