martedì 13 novembre 2012

Compilare un programma per OpenCV

Per compilare un programma OpenCV in linux è necessario, da riga di comando, scrivere

g++ hello-world.cpp -o hello-world \
-I /usr/local/include/opencv -L /usr/local/lib \
-lm -lcv -lhighgui -lcvaux

Compilatore
g++ o gcc, fare attenzione al tipo di file per non avere errori stupidi!

Librerie
Dopo aver installato OpenCV nella propria macchina, gli header dovrebbero trovarsi in
 /usr/local/include/opencv
Mentre i .so dovrebbero trovarsi in
/usr/local/include/opencv

Con cmake basta fare il CMakeLists.txt in questo modo:
project( DisplayImage ) 
find_package( OpenCV REQUIRED ) 
add_executable( DisplayImage DisplayImage.cpp ) 
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

Per opencv dal 2.2 in poi:
 You need to pass the libraries which are part of the new version of OpenCV (which have been listed through pkg-config command). You can make use of pkg-config to pass the compiler & linker flags something on these lines : g++ cv.cpp -o cv $(pkg-config --cflags --libs opencv)

Dal sito di willowgarage:

cd /where/you/have/the/source/code
PKG_CONFIG_PATH=/where/you/have/installed/opencv/lib/pkgconfig:${PKG_CONFIG_PATH}
export PKG_CONFIG_PATH
You can check that the PKG_CONFIG_PATH is correct by doing either:
pkg-config --cflags opencv
pkg-config --libs opencv
You must have something like:
$ pkg-config --cflags opencv
-I/where/you/have/installed/opencv/include/opencv  
$ pkg-config --libs opencv
-L/where/you/have/installed/opencv/lib -lcxcore -lcv -lhighgui -lcvaux  

[Linux, MacOSX] Then you can optionally run "sudo make install" (on Linux or MacOSX). Note, that if you are using CMake (and, therefore, OpenCVConfig.cmake) for your projects, it is not necessary to run "make install". Just use OpenCV from where you built it. And actually this is recommended approach, since it does not pollute system directories with potentially conflicting OpenCV versions.

References
http://www.bo.cnr.it/corsi-di-informatica/corsoCstandard/Lezioni/16Linuxgcc.html
http://www.cs.iit.edu/~agam/cs512/index.html
http://www.jestinstoffel.com/?q=node/112
http://opencv.willowgarage.com/wiki/CompileOpenCVUsingLinux
http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html#linux-gcc-usage

https://www.ibm.com/developerworks/mydeveloperworks/blogs/theTechTrek/entry/computer_vision_getting_started_with_opencv4?lang=en

http://jayrambhia.wordpress.com/2012/06/20/install-opencv-2-4-in-ubuntu-12-04-precise-pangolin/

http://stackoverflow.com/questions/1712899/what-is-the-memory-structure-of-opencvs-cvmat

Nessun commento:

Posta un commento