我想做什么: 我想将左立体图像转换为具有3D坐标的点。 (借助视差图像和函数reprojectImageTo3D())
我的代码到目前为止:
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;
当我输出reprojectImageTo3D(..)的结果时,我只有NaN点。
我现在不确定我在这里有某种思考错误,或者我使用其中一种错误的功能? 我非常感谢任何帮助!
答案 0 :(得分:1)
我发现了一些小错误,现在看起来工作正常。
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);