Ask Your Question
0

opencv ReprojectImageto3D gives values tending to infinity

asked 2013-11-25 00:59:14 -0600

Katri gravatar image

updated 2013-11-25 01:58:28 -0600

berak gravatar image

I am using stereocalibrate and stereorectify to get the Q matrix. I am giving this as input to cv.ReprojectImageto3D to get the depth map. But when I try to show the results, many values are calculated as infinity.

Do I need to change or scale anything before reprojecting. And is the result which we get in pixels?

(roi1,roi2) = cv.StereoRectify(camMatrix1, camMatrix2, d1, d2,(320,240), r, t, r1, r2, p1, p2, q, cv.CV_CALIB_ZERO_DISPARITY, -1, (0, 0))
np.savetxt('Q_mat.txt',q)
disparity  = getDisparity(img_r, img_l, "BM")
disp = cv.fromarray(disparity)
Image = cv.CreateMat(disp.rows, disp.cols, cv.CV_32FC3)
Q = np.loadtxt('Q_mat.txt')
Q = np.reshape(Q,(4,4))
Q1 = cv.fromarray(Q)
cv.ReprojectImageTo3D(disp, Image, Q1, 0)

Thanks in advance

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-11-25 03:00:03 -0600

berak gravatar image

updated 2013-11-25 03:08:42 -0600

yes it does generate some NaN or INF, due to the perspective-divide

            {   // try to achieve the same as reprojectImageTo3D, without generating NaN's
                uchar d = disp.at<uchar>(r,c);
                cv::Scalar t =  Q * cv::Scalar(c,r,d,1);
                if ( abs(t[3]) < 0.0001 )
                    continue;
                pt.x = t[0] / t[3];
                pt.y = t[1] / t[3];
                pt.z = t[2] / t[3];
                break;
            }

or use :

patchNaNs(mat, 0); // available in python, too, unfortunately undocumented

to get rid of them

edit flag offensive delete link more

Comments

@berak,

okay, so what can be done is to just remove those values with a threshold I guess right. and are these values in pixels? the output in the depth map. basically am trying tgo find depth. and the values I get are similar to these

0.017291443422436714 033600419759750366. i am not sure if what am getting is right or wrong

Katri gravatar imageKatri ( 2013-11-25 03:07:54 -0600 )edit

okay, thanx berak

Katri gravatar imageKatri ( 2013-11-25 03:12:32 -0600 )edit

the depth value is probably not in pixels. think of a 3d-frustum (the z-axis pointing into the screen)

0 should be the cam position, 1 the 'far' plane

if you throw that at opengl, you'll probably need some offset/scale factors.

berak gravatar imageberak ( 2013-11-25 03:18:45 -0600 )edit
2

okay, so how do we map these values to the distance.

Katri gravatar imageKatri ( 2013-11-25 03:27:52 -0600 )edit

Question Tools

Stats

Asked: 2013-11-25 00:59:14 -0600

Seen: 2,743 times

Last updated: Nov 25 '13