Calculate distance (stereo vision) [closed]

asked 2013-05-29 03:36:04 -0600

Odrai gravatar image

updated 2013-06-05 07:56:32 -0600

For my project I am using parts of the next code:

link text

To track objects of a specific color I implemented this method:

My question is: How can I calculate the distance to the tracked colored objects?

Thank you in advance!

*The application calls the method for the left and right frame. This is not efficient...

**I need to calculate detectedObject.Zcor

DetectedObject Detect(IplImage *frame)
 //Track object (left frame and right frame)
 //Calculate average position
 //Show X,Y,Z coordinate and detected color

color_image = frame;

imgThreshold = cvCreateImage(cvSize(color_image->width,color_image->height), IPL_DEPTH_8U, 1);
cvInitFont(&font, CV_FONT_HERSHEY_PLAIN, 1, 1, 0, 1.4f, CV_AA);

imgdraw = cvCreateImage(cvGetSize(color_image),8,3);

cvFlip(color_image, color_image, 1);

cvSmooth(color_image, color_image, CV_GAUSSIAN, 3, 0);

threshold = getThreshold(color_image);
cvErode(threshold, threshold, NULL, 3);
cvDilate(threshold, threshold, NULL, 10);
imgThreshold = cvCloneImage(threshold);

storage = cvCreateMemStorage(0);
contours = cvCreateSeq(0, sizeof(CvSeq), sizeof(CvPoint), storage);
cvFindContours(threshold, storage, &contours, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE, cvPoint(0,0));
final = cvCreateImage(cvGetSize(color_image),8,3);

for(; contours!=0; contours = contours->h_next)
    CvRect rect = cvBoundingRect(contours, 0);  

        cvPoint(rect.x, rect.y),
        cvPoint(rect.x+rect.width, rect.y+rect.height),

    string s = to_string(rect.x) + "," +  to_string(rect.y);
    char const* pchar = s.c_str();

    cvPutText(frame, pchar, cvPoint(rect.x, rect.y), &font, cvScalar(0,0,255,0));
    detectedObject.Xcor = rect.x;
    detectedObject.Ycor = rect.y;

cvShowImage("Threshold", imgThreshold);

detectedObject.Zcor = 0;
return detectedObject;
edit retag flag offensive reopen merge delete

Closed for the following reason too localized by StevenPuttemans
close date 2013-06-05 08:25:07.764454


First of all this is a project that is not included inside the OpenCV library. For questions, adress the author, not this Q&A forum. Look at the FAQ. Topic closed.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-06-05 08:24:16 -0600 )edit