Friday, April 22, 2011

Episode_2_Getting_Started_With_OpenCV

Believe it or Not!! Your computer can see and know what you are doing in front of your monitor.

it's really cool, isn't it ?
What are you waiting for, let's try how to make it !!

This episode will teach you how to make a simple OpenCV project "HelloWorld" in Visual C++ Express 2010.

  • File // New // Project.
  • Choose Win32ConsoleApplication // Next // Check at Empty Project. Name: HelloWorld -> Click 'OK' and 'Finish'.
picture 0_create_new_project

picture 1_make_helloworld_in_console_application

Before it, we must configure OpenCV directories and include OpenCV library to the Linker input.
  • Project->HelloWorld Properties... Configuration Properties->VC++ Directories.
(These link addresses are in my computer, so you need to change these if you have different folder addresses)
Include Directories... add: 'C:\OpenCV2.1\include\opencv;'
Library Directories... add: 'C:\OpenCV2.1\build\lib\debug;'
Linker -> Input -> Additional Dependencies... add: 'cv210d.lib; cxcore210d.lib; highgui210d.lib;'

picture 2_configure_opencv_directories

picture 3_include_opencv_library



Make the listing program of 'HelloWorld' such as:

#include "cv.h"
#include "cxcore.h"
#include "highgui.h"

int main(int argc, char* argv[])
{
IplImage *img = cvLoadImage("FunyCat.jpg"); // to load image from your folder
cvNamedWindow("Image:",1); // give a name to your console windows
cvShowImage("Image:",img); // show your image

cvWaitKey(); //it waits for the given number of miliseconds for a key press
cvDestroyWindow("Image:"); // close your console windows
cvReleaseImage(&img); // releases the memory allocated to an image

return 0;
}
  • Debug -> Build Solution
  • Remember to copy your image to 'C:\Users\Tiger\Documents\Visual Studio 2010\Projects\HelloWorld\HelloWorld'. (in my computer)
  • Debug -> Start Debugging
  • Done
picture 4_the_result
  • If you get something error like " the program can't start because cv210d.dll is missing from your computer "
    picture 5_missing dll

  • Ok.. it's couse you just need some configuration with your environment variable.
    Right Click Computer // Properties // Advanced system settings // Environment variable // Path // Edit... and add "C:\OpenCV2.1\build\bin\Debug"

    picture 6_environment_variable
This is the basic project that you should know before you do image processing. Especially setting up those directories that will come in handy later on. Remember you must release the memory you have allocated to an image. Otherwise, you might end up using HUGE amounts of memory (memory leak) -the scariest nightmare for a programmer.

Oh, and if you have any further questions or suggestions, leave your comment(s) below!


0 comments:

Post a Comment