Sunday, December 28, 2008

Creating simple image using INTEL'S OPENCV

Hi Everyone
In future there are going to be no robots without a vision system .Computer vision is going to be a main and integral part of future robots .Even at present there are lots of robots using image processing to navigate and identify objects .

Now to explore this science MATLAB is a very good tool .But for real time applications and applications that are fast MATLAB is no good .MATLAB consumes a lot of your computers resources .

Now here I found a neat blog for tutorials on openCV . myopencv has tutorials at beginner levels .
Here I have tweaked one of his code to create an image with black and white striped pattern .Do look at the site for more information .Here is the source code for generating black and white striped pattern .

#include "cv.h"
#include "highgui.h"
#include "stdio.h"
int main()
{
/*Creates an image size 600 by 600 ,IPL_DEPTH _8U
means each data Element has a pixel depth 8 bits
1 means one channel*/
IplImage *img = cvCreateImage(cvSize(600, 600), IPL_DEPTH_8U, 1);

int i, j,k,l;
uchar *data;
data = (uchar *) img->imageData;//pointer to the Image data
/*consider a 2d array here, we go to the first horizontal line
process it and then we go to the next horizontal line.
The above for loop goes to the next line after a line is processed*/
for (i = 0; i < (img->width); i++)
{/*This for goes length wise(means it works horizontally on the Image.*/
for (j = 0; j < (img->height); j++)
{
for(k=0;k<5;k++){ one="255”" style="color: rgb(255, 0, 0);">data[i * (img->widthStep) + j * (img->nChannels)] = 255;
j++ ;
}
/*else assign zero, image should not contain garbage values it
is always good to force assignment*/
for(k=0;k<5;k++){ style="color: rgb(255, 102, 102);"> data[i * (img->widthStep) + j * (img->nChannels)] = 0;
j++ ;

}
}
}
/*This function creates an image with name ‘image’*/
cvNamedWindow("image", CV_WINDOW_AUTOSIZE);
//showing the image
cvShowImage("image", img);
/*saving the image parameters name with Extension*/
cvSaveImage("testimg for_prog.jpg", img);
//wait for any key and Exit
cvWaitKey(0);
//release img
cvReleaseImage(&img);
//destroy the window
cvDestroyWindow("image");
return (0);
}
The important lines ,I have highlighted in red .

3 comments:

Manimaran said...

Hi
Hey great work here man...
Have u actually tried opencv for some competition in techfests?

Unknown said...

Hi!
VIT PUNE IS HOSTING AN IMAGE PROCESSING EVENT AT VIT,PUNE
ON 27-28 JAN'10.
BUILD A COMPUTER CONTROLLED NAVIGATOR WHICH CAN DUMP BALLS OF
2 COLORS(RED AND BLUE) USING AN OVERHEAD CAMERA.
PRIZES WORTH-Rs 31,000/-TO BE WON!!!
TO REGISTER/PROB STAT-
www.enjoyvit.com/melange
OR
CONTACT-
VEERAJ 9850300242

Anonymous said...

i'm new... expectancy to brief around more regularly!