Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
  • Using command line

Use below command to build binary from your source file directory.

g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib/ -g -o binary  main.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_stitching

where

binary -> The binary file to be created.

main.cpp -> Source file.

Note: Instead for running all these command every time, just create a file named build.sh , put the above command to it and change the file permission to executable by running chmod 777 build.sh, and from next time run this file instead of running the whole command.

  • Using Camke

See OpenCV Documentation about OpenCV with gcc and CMake

  • Using Eclipse

See OpenCV Documentation about OpenCV with Eclipse (plugin CDT)

  • Using CodeBlocks
  1. Open CodeBlocks and create new C++ project.

  2. Now right click on your project->Buid Options.

  3. On the po-up window select Search directories tab

    -> In that select Compiler tab and add OpenCV include directory, usually /usr/local/include

Screen shot:-

image description

-> Now open Linker tab and set OpenCV bin directory, usually /usr/local/bin

Screen shot:-

image description

4.Finally Open Linker setting tab and on Other linker options add below libraries

-lopencv_calib3d
-lopencv_contrib
-lopencv_core
-lopencv_features2d
-lopencv_flann
-lopencv_highgui
-lopencv_imgproc
-lopencv_legacy
-lopencv_ml
-lopencv_nonfree
-lopencv_objdetect
-lopencv_photo
-lopencv_stitching
-lopencv_superres
-lopencv_ts
-lopencv_video
-lopencv_videostab

Screen shot:-

image description

Done !

Now click ok and build your project.