簡體   English   中英

OpenCV計算距離(立體視覺)

[英]OpenCV calculate distance (stereo vision)

對於我的項目,我使用下一部分代碼的一部分: link

為了跟蹤特定顏色的對象,我實現了此方法:

我的問題是:如何計算到跟蹤的彩色物體的距離?

先感謝您!

*應用程序調用左右框架的方法。 這效率不高... **我需要計算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);
cvSetZero(imgdraw);

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);  

    cvRectangle(color_image, 
        cvPoint(rect.x, rect.y),
        cvPoint(rect.x+rect.width, rect.y+rect.height),
        cvScalar(0,0,255,0),
        2,8,0);

    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);

cvAdd(final,imgdraw,final);
detectedObject.Zcor = 0;
return detectedObject;

}

為了進行深度估計,您將需要校准的立體聲對(左右相機的已知相機矩陣)。 然后,使用相機矩陣和立體聲對中的相應點/輪廓,可以計算深度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM