[英]OpenCV Stereo Matching Essential Matrix weird values
我有一个使用OpenCV和两个网络摄像头的立体声设置。 我使用BM对应算法计算了基本矩阵和基本矩阵,惯常优势等。 现在,我想在另一幅图像的左侧图像中找到一个像素的匹配点。 为此,我定义了以下函数,由于我的主要目的是计算现实世界的距离,因此该函数是不完整的。
void StereoVision::findEpipolarLineForXY(int x, int y ,int lr)
{
if(calibrationDone)
{
CvPoint3D32f p1={x,y,1};
qDebug("%d,_,_,%d",p1.x,p1.y);
CvMat pt1=cvMat(3,1,CV_64FC1,&p1);
qDebug("-");
CvMat e=_E;
qDebug("pt1:");
PrintMat(&pt1);
qDebug("e:");
PrintMat(&e);
//CvMat * corLine;
//CvMat* pt2=e*pt1;
CvMat *pt2 = cvCreateMat( e.rows, pt1.cols, CV_64FC1);
qDebug("pt2:");
PrintMat(pt2);
qDebug("--%d--->%d",pt2->rows,pt2->cols);
cvMatMul( &e, &pt1, pt2 );
qDebug("--%d--->%d",pt2->cols,pt2->data);
//const CvMat* f=&_F;
qDebug("---");
//cvComputeCorrespondEpilines(&mat,lr,f,corLine);
qDebug("----");
//qDebug("%d,,,%d",corLine->height,corLine->rows);
}
}
void StereoVision::PrintMat(CvMat *A)
{
int i, j;
for (i = 0; i < A->rows; i++)
{
QDebug dbg(QtDebugMsg);
dbg<<"\n";
switch (CV_MAT_DEPTH(A->type))
{
case CV_32F:
case CV_64F:
for (j = 0; j < A->cols; j++)
dbg <<"%8.3f "<< ((float)cvGetReal2D(A, i, j));
break;
case CV_8U:
case CV_16U:
for(j = 0; j < A->cols; j++)
dbg <<"%6d"<<((int)cvGetReal2D(A, i, j));
break;
default:
break;
}
dbg.~QDebug();
}
qDebug("");
}
我想知道为什么必需矩阵是坏矩阵? 所有输出如下:
350,,,317
0,,,1081466880
--
pt1:
%8.3f 350
%8.3f 317
%8.3f 1
e:
%8.3f 0%8.3f inf%8.3f 0
%8.3f 0%8.3f 0%8.3f 0
%8.3f 0%8.3f 0%8.3f 0
pt2:
%8.3f -inf
%8.3f -inf
%8.3f -inf
--3 ---> 1
--1 ---> 44201616
另外我想知道im是否在正确的路径上找到现实世界坐标中像素的3D距离?
您应该查找“ 立体声测距” 。
如果您具有视差像素值,即两帧中两个点之间的水平像素距离,则可以找出该点的真实世界深度(相对于相机基线)。
focal_length_pixels = focal_length_mm * sensor_pixels_per_mm;
distance_mm = baseline_mm * focal_length_pixels / disparity_pixels;
disparity_pixels
两个帧之间的水平像素距离(针对该点)。 例如。 如果左图像中的点是(100, 150)
,第二个图像中的点是(125, 160)
,则disparity_pixel = 25
您可以从相机规格中获取focal_length_mm
。
focal_length_pixels = distance_mm * disparity_pixels / baseline_mm;
sensor_pixels_per_mm = focal_length_pixels / focal_length_mm;
保持物体与相机基线的距离为x mm
。 并获得disparity_pixels
如上所示。 您知道baseline_mm
。 这将为您提供focal_length_pixels
和sensor_pixels_per_mm
。 阅读此 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.