Revision: 8
http://robotvision.svn.sourceforge.net/robotvision/?rev=8&view=rev
Author: brendasegal
Date: 2010-05-17 19:11:17 +0000 (Mon, 17 May 2010)
Log Message:
-----------
just added thresholding. It's not amazing yet or anything. That's all for me for today.
Modified Paths:
--------------
robotVision/main.c
Modified: robotVision/main.c
===================================================================
--- robotVision/main.c 2010-05-17 15:29:04 UTC (rev 7)
+++ robotVision/main.c 2010-05-17 19:11:17 UTC (rev 8)
@@ -49,6 +49,12 @@
p.x = 0.0;
p.y = 0.0;
+
+ //these are the threshold values
+ int sthreshold=194;//210;
+ double hlower=178;
+ double hupper=3;
+
//create the windows:
//this is for the original image
cvNamedWindow("orig", CV_WINDOW_AUTOSIZE);
@@ -66,8 +72,78 @@
//display the smoothed image
cvShowImage("smooth", img);
+ //these are the properties of the image
+ //we will use them to loop through the data array (the image buffer)
+ int height = img->height;
+ int width = img->width;
+ int step = img->widthStep;
+ int nChannels = img->nChannels;
+
+ //this is the image buffer
+ uchar *data = ( uchar* )img->imageData;
+
+ int i; int j;
+
+ for( i = 0 ; i < height ; i++ ) {
+
+ for( j = 0 ; j < width ; j++ ) {
+
+ if((data[i*step + j*nChannels+2]>=hlower) && ( data[i*step + j*nChannels + 2]>=hupper)){
+
+
+ if( ( data[i*step + j*nChannels + 2] ) >sthreshold){
+
+ data[i*step + j*nChannels + 0] = 255;
+
+ data[i*step + j*nChannels + 1] = 255;
+
+ data[i*step + j*nChannels + 2] = 255;
+
+ }
+ else{
+ data[i*step + j*nChannels + 0] = 0;
+
+ data[i*step + j*nChannels + 1] = 0;
+
+ data[i*step + j*nChannels + 2] = 0;
+
+ }
+
+
+ }
+ else{
+
+ data[i*step + j*nChannels + 0] = 0;
+
+ data[i*step + j*nChannels + 1] = 0;
+
+ data[i*step + j*nChannels + 2] = 0;
+
+ }
+
+
+
+ }//end inner for loop
+
+}//end outer for loop
+
+ cvErode(img,img,0,6);
+ cvDilate(img, img,0,10);
+
+ //display the binary image
+ cvShowImage("binary", img);
+
cvWaitKey(0);
+ cvDestroyWindow("orig");
+ cvDestroyWindow("smooth");
+ cvDestroyWindow("binary");
+
+
+
+
+ cvWaitKey(0);
+
return p;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|