[Robotvision-commit] SF.net SVN: robotvision:[22] vision
Brought to you by:
phildavidson
From: <luc...@us...> - 2010-06-03 03:50:31
|
Revision: 22 http://robotvision.svn.sourceforge.net/robotvision/?rev=22&view=rev Author: lucyyuan Date: 2010-06-03 03:50:24 +0000 (Thu, 03 Jun 2010) Log Message: ----------- Added AutomatedTask entity class. Modified Paths: -------------- vision/.cproject vision/config/hedge.txt vision/src/main.cpp vision/src/test2.cpp Added Paths: ----------- vision/images/wire.png vision/images/wire2.png vision/images/wire3.png vision/images/wire4.png vision/images/wire5.png vision/videos/wire2.avi Modified: vision/.cproject =================================================================== --- vision/.cproject 2010-06-03 03:37:42 UTC (rev 21) +++ vision/.cproject 2010-06-03 03:50:24 UTC (rev 22) @@ -60,7 +60,7 @@ </folderInfo> <sourceEntries> <entry excluding="src" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/> -<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/> +<entry excluding="ellipse.cpp|findBuoy.c|pipe.cpp|squares.c" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src"/> </sourceEntries> </configuration> </storageModule> @@ -607,7 +607,7 @@ <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.exe.release.1039220343" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.exe.release"> <option id="gnu.cpp.compiler.mingw.exe.release.option.optimization.level.630178120" name="Optimization Level" superClass="gnu.cpp.compiler.mingw.exe.release.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/> <option id="gnu.cpp.compiler.mingw.exe.release.option.debugging.level.1662296820" name="Debug Level" superClass="gnu.cpp.compiler.mingw.exe.release.option.debugging.level" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/> -<option id="gnu.cpp.compiler.option.include.paths.1558332788" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath"> +<option id="gnu.cpp.compiler.option.include.paths.1558332788" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath"> <listOptionValue builtIn="false" value=""C:\OpenCV2.1\include\opencv""/> </option> <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.394920570" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> @@ -615,21 +615,21 @@ <tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release.1960648874" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release"> <option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.mingw.exe.release.option.optimization.level.201552392" name="Optimization Level" superClass="gnu.c.compiler.mingw.exe.release.option.optimization.level" valueType="enumerated"/> <option id="gnu.c.compiler.mingw.exe.release.option.debugging.level.89770317" name="Debug Level" superClass="gnu.c.compiler.mingw.exe.release.option.debugging.level" value="gnu.c.debugging.level.none" valueType="enumerated"/> -<option id="gnu.c.compiler.option.include.paths.1683514941" superClass="gnu.c.compiler.option.include.paths" valueType="includePath"> +<option id="gnu.c.compiler.option.include.paths.1683514941" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath"> <listOptionValue builtIn="false" value=""C:\OpenCV2.1\include\opencv""/> </option> <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.425612201" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> </tool> <tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.release.1609582156" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.release"/> <tool id="cdt.managedbuild.tool.gnu.cpp.linker.mingw.exe.release.1364150050" name="MinGW C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.mingw.exe.release"> -<option id="gnu.cpp.link.option.libs.1043700432" superClass="gnu.cpp.link.option.libs" valueType="libs"> +<option id="gnu.cpp.link.option.libs.1043700432" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs"> <listOptionValue builtIn="false" value="cv210"/> <listOptionValue builtIn="false" value="cvaux210"/> <listOptionValue builtIn="false" value="cxcore210"/> <listOptionValue builtIn="false" value="highgui210"/> <listOptionValue builtIn="false" value="ml210"/> </option> -<option id="gnu.cpp.link.option.paths.452181845" superClass="gnu.cpp.link.option.paths" valueType="libPaths"> +<option id="gnu.cpp.link.option.paths.452181845" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths"> <listOptionValue builtIn="false" value=""C:\OpenCV2.1\bin""/> </option> <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.162577737" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> Modified: vision/config/hedge.txt =================================================================== --- vision/config/hedge.txt 2010-06-03 03:37:42 UTC (rev 21) +++ vision/config/hedge.txt 2010-06-03 03:50:24 UTC (rev 22) @@ -1,5 +1,5 @@ -sthreshold 0 -hupper 0 -hlower 0 -erode 0 -dilate 0 +sthreshold 158 +hlower 60 +hupper 43 +erode 1 +dilate 5 Added: vision/images/wire.png =================================================================== (Binary files differ) Property changes on: vision/images/wire.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: vision/images/wire2.png =================================================================== (Binary files differ) Property changes on: vision/images/wire2.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: vision/images/wire3.png =================================================================== (Binary files differ) Property changes on: vision/images/wire3.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: vision/images/wire4.png =================================================================== (Binary files differ) Property changes on: vision/images/wire4.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: vision/images/wire5.png =================================================================== (Binary files differ) Property changes on: vision/images/wire5.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: vision/src/main.cpp =================================================================== --- vision/src/main.cpp 2010-06-03 03:37:42 UTC (rev 21) +++ vision/src/main.cpp 2010-06-03 03:50:24 UTC (rev 22) @@ -34,7 +34,6 @@ CvPoint center; CvSize size; - } elipse; int sthresholdbuoy=0, hupperbuoy=0, hlowerbuoy=0, erodebuoy=0, dilatebuoy=0; @@ -345,17 +344,166 @@ //as finding the heading of the pipe? //will we need to make a new struct then for this return value? -/*point? findHedge(IplImage* img){ +elipse findHedge(IplImage *src) { + int i, j, k;//for iterations + int temp = 0;//if we use a temporary var - } - */ + int heighthsv, widthhsv, stephsv, channelshsv; + int heightmono, widthmono, stepmono, channelsmono; + uchar *datahsv, *datamono; -//The findPipe function works in quite the same way as findBuoy + IplImage *colimgbot; + IplImage *monoimgbot; + //printf("frame loaded"); + colimgbot = cvCreateImage(cvGetSize(src), 8, 3); + monoimgbot = cvCreateImage(cvGetSize(src), 8, 1); + + cvCvtColor(src, colimgbot, CV_RGB2HSV); + + //\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97 + + heighthsv = colimgbot->height; + widthhsv = colimgbot->width; + stephsv = colimgbot->widthStep; + channelshsv = colimgbot->nChannels; + datahsv = (uchar *) colimgbot->imageData; + //\x97\x97\x97\x97\x97\x97\x97\x97\x96 + + heightmono = monoimgbot ->height; + widthmono = monoimgbot->width; + stepmono = monoimgbot->widthStep; + channelsmono = monoimgbot->nChannels; + datamono = (uchar *) monoimgbot->imageData; + + for (i = 0; i < (heighthsv); i++) { + for (j = 0; j < (widthhsv); j++) { + if ((datahsv[(i) * stephsv + j * channelshsv] <= hlowerhedge) + && (datahsv[(i) * stephsv + j * channelshsv] >= hupperhedge)) { + if ((datahsv[(i) * stephsv + j * (channelshsv) + 1]) + > sthresholdhedge) { + 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 + threshold is met then logic one else logic zero*/ + + datamono[i * stepmono + j * channelsmono] = 0; + } + } + } + + + //crosscheck all are either black or white + for (i = 0; i < (heighthsv); i++) { + for (j = 0; j < (widthhsv); j++) { + if (!(datamono[i * stepmono + j * channelsmono] == 0 || datamono[i + * stepmono + j * channelsmono] == 255)) + datamono[i * stepmono + j * channelsmono] = 0; + } + } + + + // get rid of noise + cvErode(monoimgbot, monoimgbot, 0, erodehedge); + cvDilate(monoimgbot, monoimgbot, 0, dilatehedge); + + CvMemStorage* storage; + CvSeq* contour; + + // Create dynamic structure and sequence. + storage = cvCreateMemStorage(0); + 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)); + + elipse retElipse; + retElipse.total=0; + retElipse.angle=-1; + + // This cycle draw all contours and approximate it by ellipses. + for(;contour;contour = contour->h_next) + { + + + int count = contour->total; // This is number point in contour + + CvBox2D box; + + // Number point must be more than or equal to 6 (for cvFitEllipse_32f). + 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 ); + cvConvert( &points_i, points_f ); + + // Fits ellipse to current contour. + box = cvFitEllipse2(points_f); + + // Draw current contour. + //cvDrawContours(image04,contour,CV_RGB(255,255,255),CV_RGB(255,255,255),0,1,8,cvPoint(0,0)); + + // Convert ellipse data from float to integer representation. + + 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); + } + + 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); + +// 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); + + + cvCircle(monoimgbot, retElipse.center, 20, CV_RGB(0,255,0), 3); + + + } + + + // Show image. HighGUI use. + + + cvReleaseImage(&colimgbot); + cvReleaseImage(&monoimgbot); + cvReleaseMemStorage(&storage); + + return retElipse; +} + +//The findPipe function works in quite the same way as findBuoy + + elipse finalFindPipe(IplImage *src) { //int sthreshold = 86, erode = 4, dialate = 8; @@ -560,9 +708,6 @@ for (;;) { - - - i = j = k = 0;/*initializing the iteraiton variables to be zero*/ @@ -678,6 +823,9 @@ finalFindPipe(image); } + else if (strcmp(functionName, "findHedge") == 0) { + findHedge(image); + } cvWaitKey(0); @@ -739,6 +887,9 @@ retElipse = finalFindPipe(frame); } + else if (strcmp("findHedge", functionName) == 0) { + retElipse = findHedge(frame); + } if(retElipse.angle!=-1) { cvLine(frame, cvPoint(frame->width / 2, frame->height / 2), @@ -786,19 +937,6 @@ int main(int argc, char** argv) { - - //this part is for the reading of the config files - //thus setting the threshold values on the fly - readFile("config/buoy.txt", 1); - readFile("config/pipe.txt", 2); - //readFile("config/hedge.txt", 3); - - - //playVideo("finalFindPipe", "videos/pipe3.avi"); - //showImage("findBuoy", "images/buoy.jpg"); - //playVideo("finalFindPipe", "videos/ets2007buoy.avi"); - //playVideo("findBuoy", "videos/ets2007buoy.avi"); - if(argc<=1){ char readuser[100]; @@ -880,7 +1018,6 @@ } - } else if(strcmp(readuser, "4")==0){ @@ -902,18 +1039,15 @@ } - }//end while - - - - - - } else{ + readFile("config/buoy.txt", 1); + readFile("config/pipe.txt", 2); + readFile("config/hedge.txt", 3); + if(strcmp(argv[1], "-v")==0){ //then the person wants to play a video @@ -969,15 +1103,7 @@ } - - } - - return 0; } - - - - Modified: vision/src/test2.cpp =================================================================== --- vision/src/test2.cpp 2010-06-03 03:37:42 UTC (rev 21) +++ vision/src/test2.cpp 2010-06-03 03:50:24 UTC (rev 22) @@ -5,13 +5,71 @@ #include"cv.h" #include"highgui.h" #include"stdio.h" + +#define CONFIG "config/hedge.txt" +#define IMAGE "images/wire5.png" + +int sthreshold=0, hupper=0, hlower=0, erode=0, dilate=0; + +void readFile(char* filename){ + + FILE* filereader; + + filereader = fopen(filename, "r"); + char line[100]; + char* line2 = (char*)malloc(sizeof(char)*100); + + char var[100]; + char value[100]; + + if(filereader!=NULL){ + + while(fgets(line, sizeof(line), filereader)!=NULL){ + + strcpy(line2, line); + strcpy(var,""); + strcpy(value,""); + + sscanf(line, "%s %s", var, value); + + if(strncmp("sthreshold ", line, 11)==0) + sthreshold=atoi(value); + else if(strncmp("hupper ", line, 7)==0) + hupper=atoi(value); + else if(strncmp("hlower ", line, 7)==0) + hlower=atoi(value); + else if(strncmp("erode ", line, 6)==0) + erode=atoi(value); + else if(strncmp("dilate ", line, 7)==0) + dilate=atoi(value); + + }//end while + + } + else{ + + printf("Can't read from file.\n"); + } +} + +void saveFile(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); + } +} + int nmain() { - int sthreshold = 68, erode = 4, dialate = 8; + readFile(CONFIG); - int hlower = 127, hupper = 25;/* - here hlower is the lower cut off and the hupper is the upper cut off for hue values of red.*/ - cvNamedWindow("original", CV_WINDOW_AUTOSIZE); cvNamedWindow("Monochrome Of red Blob", CV_WINDOW_AUTOSIZE); @@ -21,7 +79,7 @@ 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("dialate", "Monochrome Of red Blob", &dialate, 20, 0); + cvCreateTrackbar("dilate", "Monochrome Of red Blob", &dilate, 20, 0); int i, j, k;//for iterations int temp = 0;//if we use a temporary var @@ -42,16 +100,13 @@ for (;;) { - - - 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("images/pipe.png",1); + frame=cvLoadImage(IMAGE, 1); if (frame == NULL) { puts("unable to load the frame"); @@ -111,7 +166,7 @@ or erosion*/ cvErode(monoimgbot, monoimgbot, 0, erode); - cvDilate(monoimgbot, monoimgbot, 0, dialate); + cvDilate(monoimgbot, monoimgbot, 0, dilate); /*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 @@ -132,5 +187,8 @@ } cvDestroyWindow("Monochrome Of red Blob"); cvDestroyWindow("original"); + + saveFile(CONFIG); + return 0; } Added: vision/videos/wire2.avi =================================================================== (Binary files differ) Property changes on: vision/videos/wire2.avi ___________________________________________________________________ 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. |