[Robotvision-commit] SF.net SVN: robotvision:[27] vision
Brought to you by:
phildavidson
From: <phi...@us...> - 2010-06-08 00:08:28
|
Revision: 27 http://robotvision.svn.sourceforge.net/robotvision/?rev=27&view=rev Author: phildavidson Date: 2010-06-08 00:08:21 +0000 (Tue, 08 Jun 2010) Log Message: ----------- Some small additions - mostly delay bar to speed up video... Modified Paths: -------------- vision/src/main.cpp vision/src/test2.cpp vision/src/test5.cpp vision/testimg.png Added Paths: ----------- vision/vision.exe Modified: vision/src/main.cpp =================================================================== --- vision/src/main.cpp 2010-06-07 23:12:24 UTC (rev 26) +++ vision/src/main.cpp 2010-06-08 00:08:21 UTC (rev 27) @@ -32,97 +32,131 @@ } elipse; -int sthresholdbuoy=0, hupperbuoy=0, hlowerbuoy=0, erodebuoy=0, dilatebuoy=0; -int sthresholdpipe=0, hupperpipe=0, hlowerpipe=0, erodepipe=0, dilatepipe=0; -int sthresholdhedge=0, hupperhedge=0, hlowerhedge=0, erodehedge=0, dilatehedge=0; -int sthreshold=0, hupper=0, hlower=0, erode=0, dilate=0; // for slider +int sthresholdbuoy = 0, hupperbuoy = 0, hlowerbuoy = 0, erodebuoy = 0, + dilatebuoy = 0; +int sthresholdpipe = 0, hupperpipe = 0, hlowerpipe = 0, erodepipe = 0, + dilatepipe = 0; +int sthresholdhedge = 0, hupperhedge = 0, hlowerhedge = 0, erodehedge = 0, + dilatehedge = 0; +int sthreshold = 0, hupper = 0, hlower = 0, erode = 0, dilate = 0; // for slider //the following function is used by all of the find functions //in order to set their threshold values on the fly //using a config file //type 1 is the buoy, type 2 is the pipe, type 3 is the hedge, type 4 is slider -void readFile(char* filename, int type){ +void readFile(char* filename, int type) { FILE* filereader; filereader = fopen(filename, "r"); char line[100]; - char* line2 = (char*)malloc(sizeof(char)*100); + char* line2 = (char*) malloc(sizeof(char) * 100); char var[100]; char value[100]; - if(filereader!=NULL){ + if (filereader != NULL) { - while(fgets(line, sizeof(line), filereader)!=NULL){ + while (fgets(line, sizeof(line), filereader) != NULL) { strcpy(line2, line); - strcpy(var,""); - strcpy(value,""); + strcpy(var, ""); + strcpy(value, ""); sscanf(line, "%s %s", var, value); - if(strncmp("sthreshold ", line, 11)==0){ + if (strncmp("sthreshold ", line, 11) == 0) { - switch(type){ + switch (type) { - case(1):sthresholdbuoy=atoi(value);break; - case(2):sthresholdpipe=atoi(value);break; - case(3):sthresholdhedge=atoi(value);break; - case(4):sthreshold=atoi(value);break; + case (1): + sthresholdbuoy = atoi(value); + break; + case (2): + sthresholdpipe = atoi(value); + break; + case (3): + sthresholdhedge = atoi(value); + break; + case (4): + sthreshold = atoi(value); + break; } + } else if (strncmp("hupper ", line, 7) == 0) { - } - else if(strncmp("hupper ", line, 7)==0){ + switch (type) { + case (1): + hupperbuoy = atoi(value); + break; + case (2): + hupperpipe = atoi(value); + break; + case (3): + hupperhedge = atoi(value); + break; + case (4): + hupper = atoi(value); + break; - switch(type){ - - case(1):hupperbuoy=atoi(value);break; - case(2):hupperpipe=atoi(value);break; - case(3):hupperhedge=atoi(value);break; - case(4):hupper=atoi(value);break; - } - } - else if(strncmp("hlower ", line, 7)==0){ + } else if (strncmp("hlower ", line, 7) == 0) { + switch (type) { - switch(type){ + case (1): + hlowerbuoy = atoi(value); + break; + case (2): + hlowerpipe = atoi(value); + break; + case (3): + hlowerhedge = atoi(value); + break; + case (4): + hlower = atoi(value); + break; - case(1):hlowerbuoy=atoi(value);break; - case(2):hlowerpipe=atoi(value);break; - case(3):hlowerhedge=atoi(value);break; - case(4):hlower=atoi(value);break; - } + } else if (strncmp("erode ", line, 6) == 0) { - } - else if(strncmp("erode ", line, 6)==0){ - - switch(type){ - case(1):erodebuoy=atoi(value);break; - case(2):erodepipe=atoi(value);break; - case(3):erodehedge=atoi(value);break; - case(4):erode=atoi(value);break; + switch (type) { + case (1): + erodebuoy = atoi(value); + break; + case (2): + erodepipe = atoi(value); + break; + case (3): + erodehedge = atoi(value); + break; + case (4): + erode = atoi(value); + break; } + } else if (strncmp("dilate ", line, 7) == 0) { - } - else if(strncmp("dilate ", line, 7)==0){ + switch (type) { - switch(type){ + case (1): + dilatebuoy = atoi(value); + break; + case (2): + dilatepipe = atoi(value); + break; + case (3): + dilatehedge = atoi(value); + break; + case (4): + dilate = atoi(value); + break; - case(1):dilatebuoy=atoi(value);break; - case(2):dilatepipe=atoi(value);break; - case(3):dilatehedge=atoi(value);break; - case(4):dilate=atoi(value);break; - } } @@ -130,20 +164,18 @@ }//end while - } - else{ + } else { printf("Can't read from file.\n"); } } - void saveFile(char* filename) { FILE* filewriter; filewriter = fopen(filename, "w"); - if(filewriter!=NULL){ + if (filewriter != NULL) { fprintf(filewriter, "sthreshold %d\n", sthreshold); fprintf(filewriter, "hlower %d\n", hlower); fprintf(filewriter, "hupper %d\n", hupper); @@ -152,7 +184,6 @@ } } - //need to show the method headers /*point findBuoy(IplImage* img); point findPipe(IplImage* img); @@ -179,19 +210,14 @@ //we will return our values //as an ellipse elipse retElipse; - retElipse.angle=-1; - retElipse.total=0; + retElipse.angle = -1; + retElipse.total = 0; //these are the threshold values - //this is a copy of src - IplImage* img = cvCreateImage( - cvGetSize(src), - IPL_DEPTH_8U, - 3 - ); + IplImage* img = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 3); //we smooth the image and store the smooth img back in img //cvSmooth(img, img, CV_GAUSSIAN, 3, 3, 0, 0); @@ -200,12 +226,16 @@ cvCvtColor(src, img, CV_RGB2HSV); //initialization of properties of the actual image - int height; int width; int step; int channels; + int height; + int width; + int step; + int channels; //initialization of properties of the thresholded image - int heightmono; int widthmono; int stepmono; int nChannelsmono; + int heightmono; + int widthmono; + int stepmono; + int nChannelsmono; - - //these are the properties of the image //we will use them to loop through the data array (the image buffer) height = img->height; @@ -213,61 +243,49 @@ step = img->widthStep; channels = img->nChannels; - //this is the image buffer of the current unchanged image uchar *data = (uchar*) img->imageData; //this is the going to hold the binary image formed //by thresholding the image img - IplImage* monoimgbot = cvCreateImage( - cvGetSize(img), - IPL_DEPTH_8U, - 1 - ); + IplImage* monoimgbot = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); heightmono = monoimgbot->height; widthmono = monoimgbot->width; stepmono = monoimgbot->widthStep; nChannelsmono = monoimgbot->nChannels; - uchar *datamono = (uchar *)monoimgbot->imageData; + uchar *datamono = (uchar *) monoimgbot->imageData; - - int i, j; //this part makes a thresholded image out of img //and stores it in the image buffer called datamono - for( i = 0 ; i < height ; i++ ) { + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { - for( j = 0 ; j < width ; j++ ) { + if ((data[i * step + j * channels] <= hlowerbuoy) && (data[i * step + + j * channels] >= hupperbuoy)) { + if ((data[i * step + j * channels + 1]) > sthresholdbuoy) { - if((data[i*step + j*channels]<=hlowerbuoy) && ( data[i*step + j*channels]>=hupperbuoy)){ + datamono[i * stepmono + j * nChannelsmono + 0] = 255; - if( ( data[i*step + j*channels + 1] ) >sthresholdbuoy){ + } else { + datamono[i * stepmono + j * nChannelsmono + 0] = 0; - datamono[i*stepmono + j*nChannelsmono + 0] = 255; - - } - else{ - datamono[i*stepmono + j*nChannelsmono + 0] = 0; - - - } - - } - else{ - datamono[i*stepmono + j*nChannelsmono + 0] = 0; - } + } else { + datamono[i * stepmono + j * nChannelsmono + 0] = 0; - }//end inner for loop + } + }//end inner for loop + }//end outer for loop cvErode(monoimgbot, monoimgbot, 0, erodebuoy); @@ -278,75 +296,74 @@ //and the center of the ellipse will represent //the approximate center of the buoy - CvMemStorage* storage; - CvSeq* contour; + CvMemStorage* storage; + CvSeq* contour; // Create dynamic structure and sequence. storage = cvCreateMemStorage(0); - contour = cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvSeq), sizeof(CvPoint) , storage); + contour = cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvSeq), sizeof(CvPoint), + storage); cvShowImage("processed", monoimgbot); // Find all contours. - cvFindContours( monoimgbot, storage, &contour, sizeof(CvContour), - CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cvPoint(0,0)); + cvFindContours(monoimgbot, storage, &contour, sizeof(CvContour), + CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cvPoint(0, 0)); // This cycle draw all contours and approximate it by ellipses. - for(;contour;contour = contour->h_next){ + for (; contour; contour = contour->h_next) { int count = contour->total; // This is number point in contour - CvPoint center; - CvSize size; - CvBox2D box; + CvPoint center; + CvSize size; + CvBox2D box; // Number point must be more than or equal to 6 (for cvFitEllipse_32f). - if( count < 6 ) + if (count < 6) continue; - CvMat* points_f = cvCreateMat( 1, count, CV_32FC2 ); - CvMat points_i = cvMat( 1, count, CV_32SC2, points_f->data.ptr ); - cvCvtSeqToArray( contour, points_f->data.ptr, CV_WHOLE_SEQ ); + CvMat* points_f = cvCreateMat(1, count, CV_32FC2 ); + CvMat points_i = cvMat(1, count, CV_32SC2, points_f->data.ptr); + cvCvtSeqToArray(contour, points_f->data.ptr, CV_WHOLE_SEQ ); cvConvert( &points_i, points_f ); // Fits ellipse to current contour. - box = cvFitEllipse2( points_f ); + box = cvFitEllipse2(points_f); //we draw an ellipse from these points //iff there are more points in this current contour //than for the last one to which we fit an ellipse - if(count>retElipse.total) { + if (count > retElipse.total) { retElipse.total = count; retElipse.angle = box.angle; retElipse.center = cvPointFrom32f(box.center); - retElipse.size.width = cvRound(box.size.width*0.5); - retElipse.size.height = cvRound(box.size.height*0.5); + retElipse.size.width = cvRound(box.size.width * 0.5); + retElipse.size.height = cvRound(box.size.height * 0.5); } cvReleaseMat(&points_f); }//end for - if(retElipse.angle!=-1) { - cvLine(monoimgbot, cvPoint(monoimgbot->width / 2, monoimgbot->height / 2), - cvPoint((monoimgbot->width / 2) + (100 * (sin((-retElipse.angle) - * 3.14159265 / 180))), (monoimgbot->height / 2) + (100 - * (cos(-retElipse.angle * 3.14159265 / 180)))), - CV_RGB(0,0,255), 5); + if (retElipse.angle != -1) { + cvLine(monoimgbot, cvPoint(monoimgbot->width / 2, monoimgbot->height + / 2), cvPoint((monoimgbot->width / 2) + (100 * (sin( + (-retElipse.angle) * 3.14159265 / 180))), (monoimgbot->height + / 2) + (100 * (cos(-retElipse.angle * 3.14159265 / 180)))), + CV_RGB(0,0,255), 5); - cvCircle(monoimgbot, cvPoint(monoimgbot->width / 2, monoimgbot->height / 2), 10, - CV_RGB(0,0,255), 10); + cvCircle(monoimgbot, cvPoint(monoimgbot->width / 2, monoimgbot->height + / 2), 10, CV_RGB(0,0,255), 10); - // Draw ellipse. - cvEllipse(monoimgbot, retElipse.center, retElipse.size, -retElipse.angle, 0, 360, CV_RGB(255,0,255), - 1, CV_AA, 0); + // Draw ellipse. + cvEllipse(monoimgbot, retElipse.center, retElipse.size, + -retElipse.angle, 0, 360, CV_RGB(255,0,255), 1, CV_AA, 0); + cvCircle(monoimgbot, retElipse.center, 20, CV_RGB(0,255,0), 3); - cvCircle(monoimgbot, retElipse.center, 20, CV_RGB(0,255,0), 3); + } - - } - cvReleaseMemStorage(&storage); cvReleaseImage(&monoimgbot); @@ -414,7 +431,6 @@ } } - //crosscheck all are either black or white for (i = 0; i < (heighthsv); i++) { for (j = 0; j < (widthhsv); j++) { @@ -424,7 +440,6 @@ } } - // get rid of noise cvErode(monoimgbot, monoimgbot, 0, erodehedge); cvDilate(monoimgbot, monoimgbot, 0, dilatehedge); @@ -437,22 +452,19 @@ contour = cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvSeq), sizeof(CvPoint), storage); - cvShowImage("processed", monoimgbot); // Find all contours. - cvFindContours(monoimgbot, storage, &contour, sizeof(CvContour), CV_RETR_LIST, - CV_CHAIN_APPROX_NONE, cvPoint(0, 0)); + cvFindContours(monoimgbot, storage, &contour, sizeof(CvContour), + CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cvPoint(0, 0)); elipse retElipse; - retElipse.total=0; - retElipse.angle=-1; + retElipse.total = 0; + retElipse.angle = -1; // This cycle draw all contours and approximate it by ellipses. - for(;contour;contour = contour->h_next) - { + for (; contour; contour = contour->h_next) { - int count = contour->total; // This is number point in contour CvBox2D box; @@ -474,41 +486,37 @@ // Convert ellipse data from float to integer representation. - if(count>retElipse.total) { + if (count > retElipse.total) { retElipse.total = count; retElipse.angle = box.angle; retElipse.center = cvPointFrom32f(box.center); - retElipse.size.width = cvRound(box.size.width*0.5); - retElipse.size.height = cvRound(box.size.height*0.5); + retElipse.size.width = cvRound(box.size.width * 0.5); + retElipse.size.height = cvRound(box.size.height * 0.5); } cvReleaseMat(&points_f); } + if (retElipse.angle != -1) { + // cvLine(monoimgbot, cvPoint(monoimgbot->width / 2, monoimgbot->height / 2), + // cvPoint((monoimgbot->width / 2) + (100 * (sin((-retElipse.angle) + // * 3.14159265 / 180))), (monoimgbot->height / 2) + (100 + // * (cos(-retElipse.angle * 3.14159265 / 180)))), + // CV_RGB(0,0,255), 5); - if(retElipse.angle!=-1) { -// cvLine(monoimgbot, cvPoint(monoimgbot->width / 2, monoimgbot->height / 2), -// cvPoint((monoimgbot->width / 2) + (100 * (sin((-retElipse.angle) -// * 3.14159265 / 180))), (monoimgbot->height / 2) + (100 -// * (cos(-retElipse.angle * 3.14159265 / 180)))), -// CV_RGB(0,0,255), 5); + // cvCircle(monoimgbot, cvPoint(monoimgbot->width / 2, monoimgbot->height / 2), 10, + // CV_RGB(0,0,255), 10); -// cvCircle(monoimgbot, cvPoint(monoimgbot->width / 2, monoimgbot->height / 2), 10, -// CV_RGB(0,0,255), 10); + // Draw ellipse. + cvEllipse(monoimgbot, retElipse.center, retElipse.size, + -retElipse.angle, 0, 360, CV_RGB(255,0,255), 1, CV_AA, 0); - // Draw ellipse. - cvEllipse(monoimgbot, retElipse.center, retElipse.size, -retElipse.angle, 0, 360, CV_RGB(255,0,255), - 1, CV_AA, 0); + cvCircle(monoimgbot, retElipse.center, 20, CV_RGB(0,255,0), 3); - - cvCircle(monoimgbot, retElipse.center, 20, CV_RGB(0,255,0), 3); - - } - // Show image. HighGUI use. @@ -584,7 +592,6 @@ } } - //crosscheck all are either black or white for (i = 0; i < (heighthsv); i++) { for (j = 0; j < (widthhsv); j++) { @@ -594,7 +601,6 @@ } } - // get rid of noise cvErode(monoimgbot, monoimgbot, 0, erodepipe); cvDilate(monoimgbot, monoimgbot, 0, dilatepipe); @@ -607,22 +613,19 @@ contour = cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvSeq), sizeof(CvPoint), storage); - cvShowImage("processed", monoimgbot); // Find all contours. - cvFindContours(monoimgbot, storage, &contour, sizeof(CvContour), CV_RETR_LIST, - CV_CHAIN_APPROX_NONE, cvPoint(0, 0)); + cvFindContours(monoimgbot, storage, &contour, sizeof(CvContour), + CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cvPoint(0, 0)); elipse retElipse; - retElipse.total=0; - retElipse.angle=-1; + retElipse.total = 0; + retElipse.angle = -1; // This cycle draw all contours and approximate it by ellipses. - for(;contour;contour = contour->h_next) - { + for (; contour; contour = contour->h_next) { - int count = contour->total; // This is number point in contour CvBox2D box; @@ -644,41 +647,37 @@ // Convert ellipse data from float to integer representation. - if(count>retElipse.total) { + if (count > retElipse.total) { retElipse.total = count; retElipse.angle = box.angle; retElipse.center = cvPointFrom32f(box.center); - retElipse.size.width = cvRound(box.size.width*0.5); - retElipse.size.height = cvRound(box.size.height*0.5); + retElipse.size.width = cvRound(box.size.width * 0.5); + retElipse.size.height = cvRound(box.size.height * 0.5); } cvReleaseMat(&points_f); } + if (retElipse.angle != -1) { + cvLine(monoimgbot, cvPoint(monoimgbot->width / 2, monoimgbot->height + / 2), cvPoint((monoimgbot->width / 2) + (100 * (sin( + (-retElipse.angle) * 3.14159265 / 180))), (monoimgbot->height + / 2) + (100 * (cos(-retElipse.angle * 3.14159265 / 180)))), + CV_RGB(0,0,255), 5); - if(retElipse.angle!=-1) { - cvLine(monoimgbot, cvPoint(monoimgbot->width / 2, monoimgbot->height / 2), - cvPoint((monoimgbot->width / 2) + (100 * (sin((-retElipse.angle) - * 3.14159265 / 180))), (monoimgbot->height / 2) + (100 - * (cos(-retElipse.angle * 3.14159265 / 180)))), - CV_RGB(0,0,255), 5); + cvCircle(monoimgbot, cvPoint(monoimgbot->width / 2, monoimgbot->height + / 2), 10, CV_RGB(0,0,255), 10); - cvCircle(monoimgbot, cvPoint(monoimgbot->width / 2, monoimgbot->height / 2), 10, - CV_RGB(0,0,255), 10); + // Draw ellipse. + cvEllipse(monoimgbot, retElipse.center, retElipse.size, + -retElipse.angle, 0, 360, CV_RGB(255,0,255), 1, CV_AA, 0); - // Draw ellipse. - cvEllipse(monoimgbot, retElipse.center, retElipse.size, -retElipse.angle, 0, 360, CV_RGB(255,0,255), - 1, CV_AA, 0); + cvCircle(monoimgbot, retElipse.center, 20, CV_RGB(0,255,0), 3); - - cvCircle(monoimgbot, retElipse.center, 20, CV_RGB(0,255,0), 3); - - } - // Show image. HighGUI use. @@ -691,29 +690,27 @@ int slider(char* functionName, char* imageFile) { - if(strcmp(functionName, "findBuoy") == 0) { + if (strcmp(functionName, "findBuoy") == 0) { readFile("config/buoy.txt", 4); - } - else if(strcmp(functionName, "finalFindPipe") == 0) { + } else if (strcmp(functionName, "finalFindPipe") == 0) { readFile("config/pipe.txt", 4); - } - else{ + } else { readFile("config/hedge.txt", 4); } cvNamedWindow("original", CV_WINDOW_AUTOSIZE); - cvNamedWindow("Monochrome Of red Blob", CV_WINDOW_AUTOSIZE); + cvNamedWindow("Processed", CV_WINDOW_AUTOSIZE); - cvCreateTrackbar("sthreshold", "Monochrome Of red Blob", &sthreshold, 255, - 0); - cvCreateTrackbar("hlower", "Monochrome Of red Blob", &hlower, 255, 0); - cvCreateTrackbar("hupper", "Monochrome Of red Blob", &hupper, 255, 0); - cvCreateTrackbar("erode", "Monochrome Of red Blob", &erode, 20, 0); - cvCreateTrackbar("dilate", "Monochrome Of red Blob", &dilate, 20, 0); + cvCreateTrackbar("sthreshold", "Processed", &sthreshold, 255, 0); + cvCreateTrackbar("hlower", "Processed", &hlower, 255, 0); + cvCreateTrackbar("hupper", "Processed", &hupper, 255, 0); + cvCreateTrackbar("erode", "Processed", &erode, 20, 0); + cvCreateTrackbar("dilate", "Processed", &dilate, 20, 0); int i, j, k;//for iterations int temp = 0;//if we use a temporary var + /*here lets look at the word \x93heighthsv\x94 \x85now lets breadk up this word\x85here height means height as a regular IplImage Structure has now the addition \x93hsv\x94 to the word heigh means this @@ -733,11 +730,10 @@ i = j = k = 0;/*initializing the iteraiton variables to be zero*/ - //frame = cvLoadImage("images/3dballs.jpg", 1); //frame=cvLoadImage("images/flipper.png",1); //frame=cvLoadImage("images/test7.png",1); - frame=cvLoadImage(imageFile,1); + frame = cvLoadImage(imageFile, 1); if (frame == NULL) { puts("unable to load the frame"); @@ -807,7 +803,7 @@ cvShowImage("original", frame); //cvSaveImage("red-ballmonochrome.jpg",monoimgbot);/*if you want to save the image*/ - cvShowImage("Monochrome Of red Blob", monoimgbot); + cvShowImage("Processed", monoimgbot); int c = cvWaitKey(0); if ((char) c == 27) break; @@ -816,48 +812,43 @@ check the other posts on this blog*/ } - cvDestroyWindow("Monochrome Of red Blob"); + cvDestroyWindow("Processed"); cvDestroyWindow("original"); - if(strcmp(functionName, "findBuoy") == 0) { + if (strcmp(functionName, "findBuoy") == 0) { saveFile("config/buoy.txt"); - } - else if(strcmp(functionName, "finalFindPipe") == 0) { + } else if (strcmp(functionName, "finalFindPipe") == 0) { saveFile("config/pipe.txt"); - } - else{ + } else { saveFile("config/hedge.txt"); } return 0; } -int showImage(char* functionName, char* img){ +int showImage(char* functionName, char* img) { - cvNamedWindow("original", CV_WINDOW_AUTOSIZE); cvNamedWindow("processed", CV_WINDOW_AUTOSIZE); - IplImage* image = cvLoadImage( img, CV_LOAD_IMAGE_COLOR ); + IplImage* image = cvLoadImage(img, CV_LOAD_IMAGE_COLOR ); if (image == NULL) { puts("unable to load the image"); exit(0); } - //display the original image + //display the original image cvShowImage("original", image); - if(strcmp(functionName, "findBuoy")==0){ + if (strcmp(functionName, "findBuoy") == 0) { findBuoy(image); - } - else if(strcmp(functionName, "finalFindPipe")==0){ + } else if (strcmp(functionName, "finalFindPipe") == 0) { finalFindPipe(image); - } - else if (strcmp(functionName, "findHedge") == 0) { + } else if (strcmp(functionName, "findHedge") == 0) { findHedge(image); } @@ -866,137 +857,125 @@ cvDestroyWindow("processed"); cvDestroyWindow("original"); - - } -int playVideo(char* functionName, char* video){ +int playVideo(char* functionName, char* video) { cvNamedWindow("original", CV_WINDOW_AUTOSIZE); cvNamedWindow("processed", CV_WINDOW_AUTOSIZE); - //CvCapture* capture = cvCreateFileCapture("videos/pipe3.avi"); - //CvCapture* capture = cvCreateFileCapture("videos/ets2007pipe.avi"); - //CvCapture* capture = cvCreateFileCapture("videos/ets2007buoy.avi"); - //CvCapture* capture = cvCreateFileCapture("videos/cuauvFinalForward.avi"); + int delay = 150; - CvCapture* capture = cvCreateFileCapture(video); + cvCreateTrackbar("Delay", "original", &delay, 150, 0); - IplImage *frame; + //CvCapture* capture = cvCreateFileCapture("videos/pipe3.avi"); + //CvCapture* capture = cvCreateFileCapture("videos/ets2007pipe.avi"); + //CvCapture* capture = cvCreateFileCapture("videos/ets2007buoy.avi"); + //CvCapture* capture = cvCreateFileCapture("videos/cuauvFinalForward.avi"); + CvCapture* capture = cvCreateFileCapture(video); + IplImage *frame; - if (!capture) { + if (!capture) { - printf("Cannot open video file!\n"); + printf("Cannot open video file!\n"); - exit(0); + exit(0); - } + } + for (;;) {/*keep looping till we are out of frames...*/ - for (;;) {/*keep looping till we are out of frames...*/ + if (!cvGrabFrame(capture)) { - if (!cvGrabFrame(capture)) { + break; - break; + } - } + frame = cvRetrieveFrame(capture); + if (frame == NULL) { + puts("unable to load the frame"); + exit(0); + } - frame = cvRetrieveFrame(capture); + elipse retElipse; + //elipse retElipse = finalFindPipe(frame); - if (frame == NULL) { - puts("unable to load the frame"); - exit(0); - } + if (strcmp("findBuoy", functionName) == 0) { - elipse retElipse; - //elipse retElipse = finalFindPipe(frame); + retElipse = findBuoy(frame); + } else if (strcmp("finalFindPipe", functionName) == 0) { - if(strcmp("findBuoy",functionName)==0){ + retElipse = finalFindPipe(frame); + } else if (strcmp("findHedge", functionName) == 0) { + retElipse = findHedge(frame); + } - retElipse = findBuoy(frame); - } - else if(strcmp("finalFindPipe",functionName)==0){ + if (retElipse.angle != -1) { + cvLine(frame, cvPoint(frame->width / 2, frame->height / 2), + cvPoint((frame->width / 2) + (100 * (sin((-retElipse.angle) + * 3.14159265 / 180))), (frame->height / 2) + (100 + * (cos(-retElipse.angle * 3.14159265 / 180)))), + CV_RGB(0,0,255), 5); - retElipse = finalFindPipe(frame); - } - else if (strcmp("findHedge", functionName) == 0) { - retElipse = findHedge(frame); - } + cvCircle(frame, cvPoint(frame->width / 2, frame->height / 2), 10, + CV_RGB(0,0,255), 10); - if(retElipse.angle!=-1) { - cvLine(frame, cvPoint(frame->width / 2, frame->height / 2), - cvPoint((frame->width / 2) + (100 * (sin((-retElipse.angle) - * 3.14159265 / 180))), (frame->height / 2) + (100 - * (cos(-retElipse.angle * 3.14159265 / 180)))), - CV_RGB(0,0,255), 5); + // Draw ellipse. + cvEllipse(frame, retElipse.center, retElipse.size, + -retElipse.angle, 0, 360, CV_RGB(255,0,255), 1, CV_AA, 0); - cvCircle(frame, cvPoint(frame->width / 2, frame->height / 2), 10, - CV_RGB(0,0,255), 10); + cvCircle(frame, retElipse.center, 10, CV_RGB(0,255,0), 5); - // Draw ellipse. - cvEllipse(frame, retElipse.center, retElipse.size, -retElipse.angle, 0, 360, CV_RGB(255,0,255), - 1, CV_AA, 0); + } + cvShowImage("original", frame); - cvCircle(frame, retElipse.center, 10, CV_RGB(0,255,0), 5); + int c = cvWaitKey(delay); + if ((char) c == 27) + break; + } - } + /* free memory */ + cvDestroyWindow("processed"); + cvDestroyWindow("original"); - cvShowImage("original", frame); + cvReleaseCapture(&capture); + return 1; - int c = cvWaitKey(150); - if ((char) c == 27) - break; - - } - - /* free memory */ - - - cvDestroyWindow("processed"); - cvDestroyWindow("original"); - - cvReleaseCapture(&capture); - - return 1; - } - - int main(int argc, char** argv) { readFile("config/buoy.txt", 1); readFile("config/pipe.txt", 2); readFile("config/hedge.txt", 3); + if (argc <= 1) { - if(argc<=1){ - char readuser[100]; char functionName[100]; char fileName[100]; int type = 1; - while(true){ + while (true) { - printf("\nMenu\n\n1: Video\n2: Image\n3: Config\n4: List of media\n5: Slider\n6: Exit\n\n"); + printf( + "\nMenu\n\n1: Video\n2: Image\n3: Config\n4: List of media\n5: Slider\n6: Exit\n\n"); printf("%**>"); gets(readuser); - if(strcmp(readuser, "q")==0||strcmp(readuser, "6")==0){ + if (strcmp(readuser, "q") == 0 || strcmp(readuser, "6") == 0) { //we exit the program exit(0); - } - else if(strcmp(readuser, "1")==0){ + } else if (strcmp(readuser, "1") == 0) { printf("Type 1 for findBuoy, 2 for findPipe, 3 for findHedge\n"); printf("%**>"); @@ -1007,17 +986,21 @@ type = atoi(functionName); - switch(type){ + switch (type) { - case(1): playVideo("findBuoy", fileName); break; - case(2): playVideo("finalFindPipe", fileName); break; - case(3): playVideo("findHedge", fileName); break; + case (1): + playVideo("findBuoy", fileName); + break; + case (2): + playVideo("finalFindPipe", fileName); + break; + case (3): + playVideo("findHedge", fileName); + break; } + } else if (strcmp(readuser, "2") == 0) { - } - else if(strcmp(readuser, "2")==0){ - printf("Type 1 for findBuoy, 2 for findPipe, 3 for findHedge\n"); printf("%**>"); gets(functionName); @@ -1027,46 +1010,49 @@ type = atoi(functionName); - switch(type){ + switch (type) { - case(1): showImage("findBuoy", fileName); break; - case(2): showImage("finalFindPipe", fileName); break; - case(3): showImage("findHedge", fileName); break; + case (1): + showImage("findBuoy", fileName); + break; + case (2): + showImage("finalFindPipe", fileName); + break; + case (3): + showImage("findHedge", fileName); + break; } + } else if (strcmp(readuser, "3") == 0) { - } - else if(strcmp(readuser, "3")==0){ - printf("Type 1 for findBuoy, 2 for findPipe, 3 for findHedge\n"); printf("%**>"); gets(functionName); type = atoi(functionName); - if(type==1){ + if (type == 1) { readFile("config/buoy.txt", type); - } - else if(type==2){ + } else if (type == 2) { readFile("config/pipe.txt", type); - } - else{ + } else { readFile("config/hedge.txt", type); } - } - else if(strcmp(readuser, "4")==0){ + } else if (strcmp(readuser, "4") == 0) { - printf("\nVideos\n******\nets2007buoy.avi\nets2007pipe.avi\npipe3.avi\ncuauvFinalForward.avi\nwire2.avi\n"); - printf("\nImages\n******\nbuoy.jpg\npipe.png\ntest2.png\ntest3.png\ntest4.png\ntest5.png\ntest6.png\nwire.png\nwire2.png\nwire3.png\nwire4.png\nwire5.png\n"); - printf("\nConfig Files\n************\npipe.txt\nhedge.txt\nbuoy.txt\n"); - } - else if(strcmp(readuser, "5")==0){ + printf( + "\nVideos\n******\nets2007buoy.avi\nets2007pipe.avi\npipe3.avi\ncuauvFinalForward.avi\nwire2.avi\n"); + printf( + "\nImages\n******\nbuoy.jpg\npipe.png\ntest2.png\ntest3.png\ntest4.png\ntest5.png\ntest6.png\nwire.png\nwire2.png\nwire3.png\nwire4.png\nwire5.png\n"); + printf( + "\nConfig Files\n************\npipe.txt\nhedge.txt\nbuoy.txt\n"); + } else if (strcmp(readuser, "5") == 0) { printf("Image file? Remember: images/...\n"); printf("%**>"); @@ -1078,23 +1064,20 @@ type = atoi(functionName); - if(type==1){ + if (type == 1) { slider("findBuoy", fileName); - } - else if(type==2){ + } else if (type == 2) { slider("finalFindPipe", fileName); - } - else{ + } else { slider("findHedge", fileName); } - } - else{ + } else { printf("\n You must choose an option from the menu\n"); @@ -1102,66 +1085,59 @@ }//end while - } - else{ + } else { readFile("config/buoy.txt", 1); readFile("config/pipe.txt", 2); readFile("config/hedge.txt", 3); - if(strcmp(argv[1], "-v")==0){ + if (strcmp(argv[1], "-v") == 0) { //then the person wants to play a video //make sure that the person puts the name of the method //as well as the name of the video - if(argc<4){ + if (argc < 4) { printf("Insufficient number of arguments.\n"); - } - else{ + } else { playVideo(argv[2], argv[3]); } - } - else if(strcmp(argv[1], "-i")==0){ + } else if (strcmp(argv[1], "-i") == 0) { - //then the person wants to play a video - //make sure that the person puts the name of the method - //as well as the name of the video + //then the person wants to play a video + //make sure that the person puts the name of the method + //as well as the name of the video - if(argc<4){ + if (argc < 4) { - printf("Insufficient number of arguments.\n"); - } - else{ + printf("Insufficient number of arguments.\n"); + } else { - showImage(argv[2], argv[3]); - } + showImage(argv[2], argv[3]); + } - } - else if(strcmp(argv[1], "-s")==0){ + } else if (strcmp(argv[1], "-s") == 0) { //then the person wants to play a video //make sure that the person puts the name of the method //as well as the name of the video - if(argc<4){ + if (argc < 4) { printf("Insufficient number of arguments.\n"); - } - else{ + } else { slider(argv[2], argv[3]); } - } - else{ + } else { printf("To view a video type vision.exe -v functionName video\n " - "To view an image type vision.exe -i functionName image\n" - "To view the slider utility type vision.exe -s functionName image\n"); + "To view an image type vision.exe -i functionName image\n" + "To view the slider utility type vision.exe -s functionName image\n"); } Modified: vision/src/test2.cpp =================================================================== --- vision/src/test2.cpp 2010-06-07 23:12:24 UTC (rev 26) +++ vision/src/test2.cpp 2010-06-08 00:08:21 UTC (rev 27) @@ -9,9 +9,9 @@ #define CONFIG "config/hedge.txt" #define IMAGE "images/wire5.png" -int sthreshold=0, hupper=0, hlower=0, erode=0, dilate=0; +int sthreshold1=0, hupper1=0, hlower1=0, erode1=0, dilate1=0; -void readFile(char* filename){ +void readFile1(char* filename){ FILE* filereader; @@ -33,15 +33,15 @@ sscanf(line, "%s %s", var, value); if(strncmp("sthreshold ", line, 11)==0) - sthreshold=atoi(value); + sthreshold1=atoi(value); else if(strncmp("hupper ", line, 7)==0) - hupper=atoi(value); + hupper1=atoi(value); else if(strncmp("hlower ", line, 7)==0) - hlower=atoi(value); + hlower1=atoi(value); else if(strncmp("erode ", line, 6)==0) - erode=atoi(value); + erode1=atoi(value); else if(strncmp("dilate ", line, 7)==0) - dilate=atoi(value); + dilate1=atoi(value); }//end while @@ -52,34 +52,34 @@ } } -void saveFile(char* filename) { +void saveFile1(char* filename) { FILE* filewriter; filewriter = fopen(filename, "w"); if(filewriter!=NULL){ - fprintf(filewriter, "sthreshold %d\n", sthreshold); - fprintf(filewriter, "hlower %d\n", hlower); - fprintf(filewriter, "hupper %d\n", hupper); - fprintf(filewriter, "erode %d\n", erode); - fprintf(filewriter, "dilate %d\n", dilate); + fprintf(filewriter, "sthreshold %d\n", sthreshold1); + fprintf(filewriter, "hlower %d\n", hlower1); + fprintf(filewriter, "hupper %d\n", hupper1); + fprintf(filewriter, "erode %d\n", erode1); + fprintf(filewriter, "dilate %d\n", dilate1); } } int nmain() { - readFile(CONFIG); + readFile1(CONFIG); cvNamedWindow("original", CV_WINDOW_AUTOSIZE); cvNamedWindow("Monochrome Of red Blob", CV_WINDOW_AUTOSIZE); - cvCreateTrackbar("sthreshold", "Monochrome Of red Blob", &sthreshold, 255, + cvCreateTrackbar("sthreshold", "Monochrome Of red Blob", &sthreshold1, 255, 0); - cvCreateTrackbar("hlower", "Monochrome Of red Blob", &hlower, 255, 0); - cvCreateTrackbar("hupper", "Monochrome Of red Blob", &hupper, 255, 0); - cvCreateTrackbar("erode", "Monochrome Of red Blob", &erode, 20, 0); - cvCreateTrackbar("dilate", "Monochrome Of red Blob", &dilate, 20, 0); + cvCreateTrackbar("hlower", "Monochrome Of red Blob", &hlower1, 255, 0); + cvCreateTrackbar("hupper", "Monochrome Of red Blob", &hupper1, 255, 0); + cvCreateTrackbar("erode", "Monochrome Of red Blob", &erode1, 20, 0); + cvCreateTrackbar("dilate", "Monochrome Of red Blob", &dilate1, 20, 0); int i, j, k;//for iterations int temp = 0;//if we use a temporary var @@ -136,10 +136,10 @@ for (i = 0; i < (heighthsv); i++) { for (j = 0; j < (widthhsv); j++) { - if ((datahsv[(i) * stephsv + j * channelshsv] <= hlower) - && (datahsv[(i) * stephsv + j * channelshsv] >= hupper)) { + if ((datahsv[(i) * stephsv + j * channelshsv] <= hlower1) + && (datahsv[(i) * stephsv + j * channelshsv] >= hupper1)) { if ((datahsv[(i) * stephsv + j * (channelshsv) + 1]) - > sthreshold) { + > sthreshold1) { datamono[i * stepmono + j * channelsmono] = 255; } else /*A very simple concept with the loops here if the hue values are in the aforementioned range and the @@ -165,8 +165,8 @@ or erosion*/ - cvErode(monoimgbot, monoimgbot, 0, erode); - cvDilate(monoimgbot, monoimgbot, 0, dilate); + cvErode(monoimgbot, monoimgbot, 0, erode1); + cvDilate(monoimgbot, monoimgbot, 0, dilate1); /*here i have experimented with the values by changing them\x85and i have found that i come to a good result by applying erosion 6 times and dilation 15 times you can comment/uncomment play with the values and see what is going on @@ -188,7 +188,7 @@ cvDestroyWindow("Monochrome Of red Blob"); cvDestroyWindow("original"); - saveFile(CONFIG); + saveFile1(CONFIG); return 0; } Modified: vision/src/test5.cpp =================================================================== --- vision/src/test5.cpp 2010-06-07 23:12:24 UTC (rev 26) +++ vision/src/test5.cpp 2010-06-08 00:08:21 UTC (rev 27) @@ -164,7 +164,7 @@ //cvReleaseImage( &cpy ); } -int zmain(int argc, char** argv) +int mmain(int argc, char** argv) { int sthreshold = 86, erode = 4, dialate = 8; Modified: vision/testimg.png =================================================================== (Binary files differ) Added: vision/vision.exe =================================================================== (Binary files differ) Property changes on: vision/vision.exe ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |