我正在尝试做的是:
我想将左立体图像转换为具有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点。

我不确定现在在这里是否会出现某种思维错误,或者我使用的功能之一是错误的?
我非常感谢您的帮助!

最佳答案

我发现了一些小错误,现在看来一切正常。

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);

关于c++ - reprojectImageTo3D仅创建NaN点,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33804280/

10-11 22:07