IIIIIIIIIIIIIIIIIIIIII
IIIIIIIIIIIIIIIIIIIIII

Reputation: 4088

reprojectImageTo3D creates just NaN Points

What I am trying to do: I want to convert the left stereo image into points with 3D-coordinates. (With the help of the disparity image and the function reprojectImageTo3D())

My Code so far:

stereoRectify(M1,D1,M2,D2,inputImageleft.size(),R,T,R1,R2,P1,P2,Q,CV_CALIB_ZERO_DISPARITY,-1,inputImageleft.size(),0,0);
Mat lMap1;
Mat lMap2;
Mat rMap1;
Mat rMap2;

initUndistortRectifyMap(M1,D1,R1,M1,inputImageleft.size(),CV_32FC1,lMap1,lMap2);
initUndistortRectifyMap(M2,D2,R2,M2,inputImageright.size(),CV_32FC1,rMap1,rMap2);

Mat leftImageMatO;
Mat rightImageMatO;

remap(inputImageleft,leftImageMatO,lMap1,lMap2,INTER_NEAREST,BORDER_CONSTANT,0);
remap(inputImageright,rightImageMatO,rMap1,rMap2,INTER_NEAREST,BORDER_CONSTANT,0);

Ptr<cv::StereoSGBM> sgbm = cv::StereoSGBM::create(0,64,11,8*1*10*10,32*1*10*10,-1,1,15,150,1, StereoSGBM::MODE_HH);

Mat outPut;
sgbm->compute(leftImageMatO, rightImageMatO, outPut);

Mat new3dimg(outPut.size(),CV_32F);
reprojectImageTo3D(outPut,new3dimg,Q,false);

cout << new3dimg;

When I output the result of reprojectImageTo3D(..) I just have NaN Points.

I am not sure now do I have some kind of thinking error here or am I using one of the functions wrong ? I am very thankful for any help!

Upvotes: 0

Views: 516

Answers (1)

IIIIIIIIIIIIIIIIIIIIII
IIIIIIIIIIIIIIIIIIIIII

Reputation: 4088

I found some little errors and it seems to be work fine now.

stereoRectify(M1,D1,M2,D2,inputImageleft.size(),R,T,R1,R2,P1,P2,Q,CV_CALIB_ZERO_DISPARITY,-1,inputImageleft.size(),0,0);

Mat lMap1;
Mat lMap2;
Mat rMap1;
Mat rMap2;

initUndistortRectifyMap(M1,D1,R1,P1,inputImageleft.size(),CV_16SC2,lMap1,lMap2);
initUndistortRectifyMap(M2,D2,R2,P2,inputImageleft.size(),CV_16SC2,rMap1,rMap2);

Mat leftImageMatO;
Mat rightImageMatO;

remap(inputImageleft,leftImageMatO,lMap1,lMap2,INTER_LINEAR);
remap(inputImageright,rightImageMatO,rMap1,rMap2,INTER_LINEAR);


Ptr<cv::StereoSGBM> sgbm = cv::StereoSGBM::create(0,64,11,8*1*10*10,32*1*10*10,-1,1,15,150,1, StereoSGBM::MODE_HH);

Mat outPut;
sgbm->compute(leftImageMatO, rightImageMatO, outPut);

Mat disp;
outPut.convertTo(disp,CV_8U);

Mat new3dimg;
reprojectImageTo3D(disp,new3dimg,Q,false);

Upvotes: 1

Related Questions