我试图从相机获取检测到的物体的距离 . 为此,我们使用三角测量深度 . 我们正在使用立体声设置 . 但获得的数值并不准确 .

这是该计划的流程:

  • 校准相机

  • Stero校准,立体校正并使用initUndistortrectifymap()计算两个图像的校正图 .

  • 相对于在上述步骤中获得的 Map 重新映射两个图像 .

  • 计算冲浪关键点和匹配 .

  • 计算这些特定匹配的三角测量深度 .

现在,虽然立体声校正,匹配和检测相当准确 . 对于该点获得的三角测量深度在整个图像中变化很大 . 当我们看到它们相应的三角测量深度时,在现实世界中处于相同附近的物体给出不同的值 . Depth Image 1 triangulation depth image 2 correspondence .

请参考上面的图片以更清楚地了解我的困境,深度图像显示计算的深度,对应显示如何获得匹配 . 照片中的人物处于15和20英尺的现实世界中 . 但是我们从点击三角测量获得的值是9或10英尺,但是远离相机 . 这是triangulatePoints()的预期行为吗?或者我错过了什么 . 请指教 . 提前谢谢 .

下面是我的代码的一小部分,显示了程序的流程 .

file["M1"] >> camMatrix;
file["M2"] >> camMatrix2;
file["R"] >> R;
file["T"] >> T;
file["D1"] >> distCoeffs;
file["D2"] >> distCoeffs2; // getting calibrations 


Mat P1 = (Mat_<double>(3, 4) << 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0);
P1 = Knew_mat*P1;
Mat P2(3, 4, CV_64F, Scalar::all(0));
R.copyTo(P2(Rect(0, 0, 3, 3)));
P2.at<double>(0, 3) = T.at<double>(0, 0);
P2.at<double>(1, 3) = T.at<double>(1, 0);
P2.at<double>(2, 3) = T.at<double>(2, 0);
P2 = Knew_mat*P2;
//calculate projection matrices based on the common Projection matrix which is optimized for undistortion  

initUndistortRectifyMap(camMatrix, distCoeffs, noArray(), Knew_mat,image.size(), CV_16SC2, map1x, map1y);
initUndistortRectifyMap(camMatrix2, distCoeffs2,noArray(), Knew_mat,image2.size(), CV_16SC2, map2x, map2y);
cout << "Past initUndistortRectifyMap  :" << map1x.size()<<" " << 
map1y.size()<<" "<<map2x.size()<<" "<<map2y.size()<<endl;
remap(image, imgU1, map1x, map1y, INTER_LINEAR , BORDER_CONSTANT, Scalar());
remap(image2, imgU2, map2x, map2y, INTER_LINEAR, BORDER_CONSTANT, Scalar());


surf( imgATestGpu, cuda::GpuMat(), keypointsGpuA, descriptorsGpuA);
surf( imgBTestGpu, cuda::GpuMat(), keypointsGpuB, descriptorsGpuB);
 FlannBasedMatcher matcher(new cv::flann::KDTreeIndexParams(4), new cv::flann::SearchParams());
matcher.match(descriptorsB, descriptorsA, matches, noArray());
//calculate surf points and filter them.


triangulatePoints(P1, P2, imgPtsA, imgPtsB, outputPoints);
// use triangulate points on the obtained filtered image points.