OpenCV Stereo Matching Essential Matrix weird values

asked 2013-01-20 03:55:13 -0500

I have a stereo setup using OpenCV and two webcams (The one in the book Lerning OpenCV by H&Z). I computed essential and fundamental matrices, intrinces extrinces etc using BM correspondancy algorithm. Now I want to find the matching point of a pixel in left image in the other image. To do this I have defined the following function, which is incomplete since my primary aim is to calculate real world distance.

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("");
}
I want to know why essential matrix is a bad one? all output is below:

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

Also Id like to know if im on the right path to find the 3D distance of the pixel in real world coordinates?

edit retag flag offensive close merge delete