[Robotvision-commit] SF.net SVN: robotvision:[20] vision/src/main.cpp
Brought to you by:
phildavidson
From: <bre...@us...> - 2010-06-02 18:34:46
|
Revision: 20 http://robotvision.svn.sourceforge.net/robotvision/?rev=20&view=rev Author: brendasegal Date: 2010-06-02 18:34:39 +0000 (Wed, 02 Jun 2010) Log Message: ----------- Fixed the command line menu thingy Modified Paths: -------------- vision/src/main.cpp Modified: vision/src/main.cpp =================================================================== --- vision/src/main.cpp 2010-06-02 03:03:00 UTC (rev 19) +++ vision/src/main.cpp 2010-06-02 18:34:39 UTC (rev 20) @@ -522,6 +522,136 @@ return retElipse; } +int slider(char* imageFile) { + + int sthreshold = 68, erode = 4, dialate = 8; + + 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); + + 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("dialate", "Monochrome Of red Blob", &dialate, 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 + height attribute is for the image which is color converted to the hsv,Similar conventions + for the monochrome image\x85so you may find the attribute height for the monochrome image to be + heightmono\x85So i believe it is easy\x85*/ + int heighthsv, widthhsv, stephsv, channelshsv; + int heightmono, widthmono, stepmono, channelsmono; + uchar *datahsv, *datamono; + + IplImage *frame; + IplImage *colimgbot; + + IplImage *monoimgbot; + + 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(imageFile,1); + + if (frame == NULL) { + puts("unable to load the frame"); + exit(0); + } + //printf("frame loaded"); + colimgbot = cvCreateImage(cvGetSize(frame), 8, 3); + + monoimgbot = cvCreateImage(cvGetSize(frame), 8, 1); + + cvCvtColor(frame, 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] <= hlower) + && (datahsv[(i) * stephsv + j * channelshsv] >= hupper)) { + if ((datahsv[(i) * stephsv + j * (channelshsv) + 1]) + > sthreshold) { + 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; + } + } + } + + 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; + } + }/*Just a cross chek to ensure whether all the pixels have only + either 0 or 255*/ + /*Please check these links for the explanation of the erosion and dilation functions + + http://www.dca.fee.unicamp.br/dipcourse/html-dip/c9/s4/front-page.html*/ + + /*so now the last parameter in the function indicates how many times you want to apply dilation + + or erosion*/ + + cvErode(monoimgbot, monoimgbot, 0, erode); + cvDilate(monoimgbot, monoimgbot, 0, dialate); + /*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 + Sometimes you will find the areas which are shining in the image also get detected\x85 + + Please think why and then try to post a comment the best commment would get visible on this page*/ + + cvShowImage("original", frame); + //cvSaveImage("red-ballmonochrome.jpg",monoimgbot);/*if you want to save the image*/ + cvShowImage("Monochrome Of red Blob", monoimgbot); + int c = cvWaitKey(0); + if ((char) c == 27) + break; + /*for all the other clarifications you can check the other posts\x85. you will find an answer + People who are getting started with the Opencv must make sure you + + check the other posts on this blog*/ + } + cvDestroyWindow("Monochrome Of red Blob"); + cvDestroyWindow("original"); + return 0; +} + int showImage(char* functionName, char* img){ @@ -658,24 +788,165 @@ //readFile("config/hedge.txt", 3); - playVideo("finalFindPipe", "videos/pipe3.avi"); + //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]; + char functionName[100]; + char fileName[100]; + int type = 1; + while(true){ + 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){ + //we exit the program + exit(0); + } + else if(strcmp(readuser, "1")==0){ + printf("Function name?\n"); + printf("%**>"); + gets(functionName); + printf("Video file? Remember: videos/...\n"); + printf("%**>"); + gets(fileName); + playVideo(functionName, fileName); + } + else if(strcmp(readuser, "2")==0){ + + printf("Function name?\n"); + printf("%**>"); + gets(functionName); + printf("Image file? Remember: images/...\n"); + printf("%**>"); + gets(fileName); + + showImage(functionName, fileName); + } + 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){ + + readFile("config/buoy.txt", type); + + } + else if(type==2){ + + readFile("config/pipe.txt", type); + } + else{ + + readFile("config/hedge.txt", type); + + } + + + } + else if(strcmp(readuser, "4")==0){ + + printf("\nVideos\n******\nets2007buoy.avi\nets2007pipe.avi\npipe3.avi\ncuauvFinalForward.avi\n"); + printf("\nImages\n******\nbuoy.jpg\npipe.png\ntest2.png\ntest3.png\ntest4.png\ntest5.png\ntest6.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("%**>"); + gets(fileName); + slider(fileName); + + } + else{ + + printf("\n You must choose an option from the menu\n"); + + } + + + }//end while + + + + + + + } else{ + 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){ + + printf("Insufficient number of arguments.\n"); + } + else{ + + playVideo(argv[2], argv[3]); + } + + } + 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 + + if(argc<4){ + + printf("Insufficient number of arguments.\n"); + } + else{ + + showImage(argv[2], argv[3]); + } + + } + 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<3){ + + printf("Insufficient number of arguments.\n"); + } + else{ + + slider(argv[2]); + } + + } + else{ + + printf("To view a video type vision.exe -v functionName video\n " + "To view an image type vision.exe -i functionName image"); + + } + + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |