In real life we are dealing with lot of images. Especially after advancement of computers and processing capabilities of computers image processing become more easy. For easy processing of images we can use lot of image processing libraries like Open CV, Emgu CV or well known MATLAB. In this tutorial I will demonstrate how to use Open CV for image processing.
Software requirements:
1. Open CV
2. Visual studio
To process any image first we need to load it into the computer memory. This is very easy. Open CV provides lot of functions among those we have one function which helps us to load the image into the program. Basically Open CV supports C,C++,Java as well as Python. we can use any programming language along with Open CV based on your comfort.
I will use C and C++ to demonstrate the loading of image into the program.
The basic program to display the image using Open CV is
void main()
{
IplImage* image=cvLoadImage("E:\\Capture.jpg");
cvShowImage("Image",image);
cvWaitKey(1);
getch();
}
IplImage* is a structure holding the image data. It points to the memory location of the image. cvLoadImage function is useful for loading the image. Generally it takes to arguments first one is the path to the image to be loaded second one specifies weather the image to be loaded as color image or gray scale image or unchanged.
CV_LOAD_IMAGE_COLOR the loaded image is forced to be a 3-channel color imageCV_LOAD_IMAGE_GRAYSCALE the loaded image is forced to be grayscale
CV_LOAD_IMAGE_UNCHANGED the loaded image will be loaded as is.
cvShowImage is useful for displaying the image on a window. the first argument takes the name of the window. and second argument takes the variable of type iplImage*. We can generate the image explicitly and we can pass the name of that window to the function other wise the function generates it for us implicitly.
cvWaitKey is the delay function which gives the time for the processor to load the image on to the window.
if forget to specify this function image can not be displayed. it takes the integer as the argument and returns the ASCII key value of the pressed key.
In next post i will try to explain the process in detail with more detailed code and its explanation and examples.
No comments:
Post a Comment