首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenCV计算距离(立体视觉)

OpenCV计算距离(立体视觉)
EN

Stack Overflow用户
提问于 2013-05-28 21:59:23
回答 1查看 1.3K关注 0票数 0

在我的项目中,我使用了下面代码的一部分:link

为了跟踪特定颜色的对象,我实现了这个方法:

我的问题是:我如何计算到被跟踪的彩色物体的距离?

提前谢谢你!

*应用程序调用left和right框架的方法。这不是很有效率。**我需要计算detectedObject.Zcor

代码语言:javascript
复制
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;

}

EN

回答 1

Stack Overflow用户

发布于 2013-08-14 18:19:33

对于深度估计,您将需要校准的立体对(左右两个相机的已知相机矩阵)。然后,使用立体对中的相机矩阵和相应的点/轮廓,您可以计算深度。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16794041

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档