[Robotvision-commit] SF.net SVN: robotvision:[18] vision
Brought to you by:
phildavidson
From: <bre...@us...> - 2010-06-02 03:02:32
|
Revision: 18 http://robotvision.svn.sourceforge.net/robotvision/?rev=18&view=rev Author: brendasegal Date: 2010-06-02 03:02:26 +0000 (Wed, 02 Jun 2010) Log Message: ----------- This is some stuff I added. I'll add more tomorrow and throughout the week. Modified Paths: -------------- vision/src/findBuoy.c Added Paths: ----------- vision/config/ vision/config/buoy.txt vision/config/hedge.txt vision/config/pipe.txt vision/images/buoy.jpg Removed Paths: ------------- vision/src/main.cpp Added: vision/config/buoy.txt =================================================================== --- vision/config/buoy.txt (rev 0) +++ vision/config/buoy.txt 2010-06-02 03:02:26 UTC (rev 18) @@ -0,0 +1,5 @@ +sthreshold 11 +hupper 45 +hlower 127 +erode 4 +dilate 8 \ No newline at end of file Added: vision/config/hedge.txt =================================================================== --- vision/config/hedge.txt (rev 0) +++ vision/config/hedge.txt 2010-06-02 03:02:26 UTC (rev 18) @@ -0,0 +1,5 @@ +sthreshold 0 +hupper 0 +hlower 0 +erode 0 +dilate 0 Added: vision/config/pipe.txt =================================================================== --- vision/config/pipe.txt (rev 0) +++ vision/config/pipe.txt 2010-06-02 03:02:26 UTC (rev 18) @@ -0,0 +1,5 @@ +sthreshold 86 +erode 4 +dilate 8 +hlower 127 +hupper 25 Added: vision/images/buoy.jpg =================================================================== (Binary files differ) Property changes on: vision/images/buoy.jpg ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: vision/src/findBuoy.c =================================================================== --- vision/src/findBuoy.c 2010-05-31 11:17:12 UTC (rev 17) +++ vision/src/findBuoy.c 2010-06-02 03:02:26 UTC (rev 18) @@ -238,8 +238,13 @@ if(strcmp(argv[1], "-v")==0){ - if (argc <= 3){ + } + + else if(strcmp(argv[1], "-v")==0){ + + if (argc <= 4){ + printf("not enough arguments\n"); return 1; Deleted: vision/src/main.cpp =================================================================== --- vision/src/main.cpp 2010-05-31 11:17:12 UTC (rev 17) +++ vision/src/main.cpp 2010-06-02 03:02:26 UTC (rev 18) @@ -1,426 +0,0 @@ -#ifdef _CH_ -#pragma package <opencv> -#endif - -#define CV_NO_BACKWARD_COMPATIBILITY - -#include <cv.h> -#include <highgui.h> -#include <stdio.h> -#include <math.h> -#include <string.h> -//#include "pipe.cpp" - -using namespace std; - -//using namespace pipe; - -//the struct is what will be used to return the values in the form of an ordered pair (x,y) - - -typedef struct retValue { - - double x; - double y; - -} point; - - -typedef struct elipse { - - float angle; - int total; - CvPoint center; - CvSize size; - - -} elipse; - -//need to show the method headers -/*point findBuoy(IplImage* img); - point findPipe(IplImage* img); - point findHeading(IplImage* img); - */ - -//the convert function converts a gStreamer object to an OpenCV image -/* - - IplImage* convert(GSTBuffer gBuffer){ - - - - - } - */ - -//For the findBuoy function, the center of mass is returned as (x,y) coordinates -//center of mass will either be found by averaging white pixels in binary image -//or by fitting an ellipse around the buoy - -point findBuoy(IplImage* img) { - - point p; - 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); - //this is for the smoothed image - cvNamedWindow("smooth", CV_WINDOW_AUTOSIZE); - //this is for the binary image (thresholding) - cvNamedWindow("binary", CV_WINDOW_AUTOSIZE); - - //display the original image - cvShowImage("orig", img); - - //we smooth the image and store the smooth img back in img - cvSmooth(img, img, CV_GAUSSIAN, 3, 3, 0, 0); - - //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; - -} - -//the findHedge function will have to be used with a fake image we create -//(I suggest manipulating the buoy image and drawing a green hedge within it) -//since we don't have any ones to base ourselves on -//how are we going to return the values? Are we going to return a struct with three points, -//each corresponding to the center of each rectangle? Will it have to be done in the same way -//as finding the heading of the pipe? -//will we need to make a new struct then for this return value? - -/*point? findHedge(IplImage* img){ - - - } - */ - -//The findPipe function works in quite the same way as findBuoy - - - - -elipse finalFindPipe(IplImage *src) { - - int sthreshold = 86, erode = 4, dialate = 8; - - int hlower = 127, hupper = 25; - - //int sthreshold = 11, erode = 3, dialate = 6; - - //int hlower = 127, hupper = 45; - - /*here hlower is the lower cut off and the hupper is the upper cut off for hue values of red.*/ - - 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; - - 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] <= 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; - } - } - } - - - //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, erode); - cvDilate(monoimgbot, monoimgbot, 0, dialate); - - 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; -} - -int main(int argc, char** argv) { - - 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"); - - IplImage *frame; - - if (!capture) { - - printf("Cannot open video file!\n"); - - return (1); - - } - - - for (;;) {/*keep looping till we are out of frames...*/ - - if (!cvGrabFrame(capture)) { - - break; - - } - - - frame = cvRetrieveFrame(capture); - - if (frame == NULL) { - puts("unable to load the frame"); - return 0; - } - - elipse retElipse = finalFindPipe(frame); - - 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); - - cvCircle(frame, cvPoint(frame->width / 2, frame->height / 2), 10, - CV_RGB(0,0,255), 10); - - // Draw ellipse. - cvEllipse(frame, retElipse.center, retElipse.size, -retElipse.angle, 0, 360, CV_RGB(255,0,255), - 1, CV_AA, 0); - - - cvCircle(frame, retElipse.center, 10, CV_RGB(0,255,0), 5); - - - } - - - cvShowImage("original", frame); - - - int c = cvWaitKey(150); - if ((char) c == 27) - break; - - } - - /* free memory */ - - - cvDestroyWindow("processed"); - cvDestroyWindow("original"); - - cvReleaseCapture(&capture); - - return 0; -} - - - - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |