Primary Object Detection using Subjugator Images  

Posted by shashank in


After significant trial and error on morphological operations the following results were achieved:


The Program:

#include

#include

#include

#include

#include

IplImage *img=0; //the pointer is assigned value zero;

//thus it points to nothing untill something is loaded

IplImage *img2=0;

int main(void){

img=cvLoadImage("sg (25).jpg");

if(img==0){

fprintf(stderr,"Cannot load file.");

getchar();

return(1);

}

int i,j,height,width, step, channels;

int temp;

height=img->height;

width=img->width;

channels=img->nChannels;

step=img->widthStep;

unsigned char *data=(unsigned char *)img->imageData; //Since it's an IPL_DEPTH_8U image

for(i=0;i

for(j=0;j

temp=2*data[i*step+j*channels+2]

-data[i*step+j*channels+1]

-data[i*step+j*channels+0]; //temp=2*red - sum of blue and green

//thus the current range of temp is -510 to 510

temp=temp/4; //this reduces the range to -127 to 127

temp=temp+127; //this shifts the range to 0 to 254

data[i*step+j*channels+0]=temp;

data[i*step+j*channels+1]=temp;

data[i*step+j*channels+2]=temp;

}

}

//once the image is rendered into gray scale we don't modify img

//hence img2 - the dummy - is used

img2=cvCreateImage(cvGetSize(img),img->depth,img->nChannels);

unsigned char *data2=(unsigned char *)img2->imageData;

cvErode(img,img2,NULL,5);

cvDilate(img2,img2,NULL,5);

cvThreshold(img2,img2,100,255,CV_THRESH_BINARY);

cvNamedWindow("image",CV_WINDOW_AUTOSIZE);

cvShowImage("image",img2);

cvSaveImage("obj.jpg",img2);

cvWaitKey(0);

cvDestroyWindow("image");

cvReleaseImage(&img);

}

Accessing Image Data  

Posted by shashank in


After wasting a lot of time over trying to manipulate the individual pixels of an image, Rushi pointed out that the image was not a float image but rather had unsigned char elements. The following is the code (without the header files included) and which had the effect on "sg (25).jpg" as shown above:

IplImage *img=0; //the pointer is assigned value zero;
//thus it points to nothing untill something is loaded

int main(void){
img=cvLoadImage("sg (25).jpg");
if(img==0){
fprintf(stderr,"Cannot load file.");
getchar();
return(1);
}

printf("%u",img->depth);
getchar();
int i,j,height,width, step, channels;
height=img->height;
width=img->width;
channels=img->nChannels;
step=img->widthStep;
unsigned char *data=(unsigned char *)img->imageData;

for(i=30;i<90;i++){ j="30;j<120;j++){" class="descname">cvSaveImage(const char* filename, const CvArr* image) is also demonstrated in the above example.

The first program for OpenCV  

Posted by shashank in

Due to midsems, for a few days I was unable to touch OpenCV. Hence just to open and display an image I took me quite some time. The following program may serve as a brush up in case such a thing happens again:

#include
#include
#include
#include
#include


int main(void){
IplImage *img =0;
img=cvLoadImage("Moon.jpg");
if(img == 0){
fprintf(stderr,"Cannot Load File.");
getchar();
return(1);
}

cvNamedWindow("image",CV_WINDOW_AUTOSIZE);
cvShowImage("image",img);
cvWaitKey(0);
cvDestroyWindow("image");
cvReleaseImage(&img);
return 0;
}


To the reader it will be obvious the exe file compiled should co-exist with a file named "Moon.jpg" in order for the same to be displayed. The header files are not visible due to html. To read the same the source code of this page can be viewed and you can search for "include".


One important function that deserves a mention for beginning with OpenCV programming is:
cvCreateImage(CvSize size, int depth, int channels)

Configuring Visual Studio for OpenCV  

Posted by shashank in

August 11, 2009

Software in consideration:
Visual Studio 2005 (esp. VC++) and OpenCV Library

After being unable to do much with the library myself (primarily owing to the arcane structure of software tools) I sought help from my friends Hari and Avdhut. Hari linked me to www.dreamspark.com which allowed me to download VS2005 [I am a UF Gator] and Avdhut's instructions are what are noted down below.

In Tools>Options make the changes equivalent to those shown below:
Include Files:


Library files:


These changes are apart from the changes that have to be made to "executable files" category - to prevent the "cmd spawning" error {focus on the last 3 lines beginning with $(System Root)}:


But the idiocy of compsci guys doesn't end here. You need to do more arcane stuff. Once you create a new project, in the solution explorer (expected to be the leftmost column in the Visual Studio Window) right click on the solution name(I might be wrong here in that you might need to right on the project name). Follow this route: Configuration Properties>>Linker>>Input>>Additional Dependencies. Add this string to the same: "cv.lib cvaux.lib cxcore.lib highgui.lib cvcam.lib"
The changes should be similar to those shown below:


I hope this is complete. If I discover I have forgotten to include a critical step, I will correct this post later.

Note: The images are unclear. Hence explore the paths to find the correct spellings of the folders. Or right click on the images and open in a new tab.

Error spawning 'cmd.exe'  

Posted by shashank

August 11, 2009

In spite of compiling the program correctly the above error - the topic - used to pop up. Finally I found the solution on the following address:

http://social.msdn.microsoft.com/Forums/en-US/Vsexpressinstall/thread/adc6e067-60a4-4914-9673-571b047d9376

The solution is:

In the Options go into Projects and Solutions -> VC++ Directories page and place this rows:

$(SystemRoot)\System32
$(SystemRoot)
$(SystemRoot)\System32\wbem

Surprisingly it worked!

The classpath problem  

Posted by shashank in

July 8, 2009
The same image can be seen in detail at:


When I instruct to compile the program into the adat folder, the class files are created. From being anywhere in the directory - true at least for the cases I have tried yet - I can execute the program with the instruction:
>java -cp C:\jtemp\adat MyPack.AccountBalance

But when I go to the actual location the following command fails to execute:
C:\jtemp\adat>java MyPack.AccountBalance

and yields a "NoClassDefFoundError".

The conclusion I have derived from this is that the "classpath" variable is locked by default and hence the programs don't execute unless the same is explicitly changed. Perhaps such a conclusion is wrong, but at present it enables me to execute the simple programs I am writing.

Summer Solstice!  

Posted by shashank in

June 21, 2009

Today is the first day in the 24 years of my life that I am consciously aware that (maybe somebody sometimes must have reminded me in my school days but I don't remember a case of having paid attention) its the day of Summer Solstice. The Reason? It was a God damn hot day on the field of Archery.

Today I was accompanied to the field by my friend Nileshwar (alias Anna). For his first day he outperformed my first day by miles. Indulging in a bit of self-adoration, I would say, that unlike me, he had a very good teacher! After finding his anchor point and gun point (actually its equivalent for the bow) he landed his arrows in a very close group near the target and scored a hit in his first 20 rounds - which I am guessing to be the first 20 of his life. It was also the first time I saw my bow in action and its good to see it work in third person. For my record - I fired 40 arrows (20 with each hand) and was pretty satisfied with my own group. I wouldn't say it was a marked progress (or for that matter any progress at all) over my last session.

I certainly regret of not capturing Anna's first hit on my cellphone cam. Nevertheless, for reference, following is the picture of footballers practicing in the region a bit away from where we practiced archery.