Use OpenCV in your source code!

Solution

There are many ways to include OpenCV in your projects. I describe my way here which has the following advantages:

Setup your workstation:

Test your workstation by compiling a Hello World program

You probably know CMake by now, but I provide a full hello world program here. You have to make two files: hw.cxx is your program code, and CMakeLists.txt defines your configuration for compilation.

prog.cxx looks like this:

#include <cv.h>
#include <highgui.h>

int main ( int argc, char **argv )
{
  cvNamedWindow( "My Window", 1 );
  IplImage *img = cvCreateImage( cvSize( 640, 480 ), IPL_DEPTH_8U, 1 );
  CvFont font;
  double hScale = 1.0;
  double vScale = 1.0;
  int lineWidth = 1;
  cvInitFont( &font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC,
              hScale, vScale, 0, lineWidth );
  cvPutText( img, "Hello World!", cvPoint( 200, 400 ), &font,
             cvScalar( 255, 255, 0 ) );
  cvShowImage( "My Window", img );
  cvWaitKey();
  return 0;
}

CMakeLists.txt looks like this:

PROJECT( pr )
FIND_PACKAGE( OpenCV REQUIRED )
INCLUDE_DIRECTORIES( ${OPENCV_INCLUDE_DIR} )
ADD_EXECUTABLE( hw hw.cxx )
TARGET_LINK_LIBRARIES( hw ${OPENCV_LIBRARIES} )

Having these files in a directory, make it your current directory, configure and compile your program.

On Linux:

$> cmake .
$> make

On Windows, use the graphical config tool of CMake and select MinGW for compiler.

$> CMakeSetup .
$> make

If you get an executable hw program, you are ready to move on and have fun with OpenCV!

Getting_started (last edited 2008-05-28 14:02:34 by localhost)

SourceForge.net Logo