当前位置:   article > 正文

opencv双目视觉特征匹配点三角测量得到三维坐标_opencv 三角测量 csdn

opencv 三角测量 csdn
  1. void StereoTo3D(vector<Point2f> ptsL, vector<Point2f> ptsR, vector<Point3f> &pts3D, Mat Q,Mat T)
  2. {
  3. //1三角测量
  4. if (ptsL.size() != ptsR.size())
  5. {
  6. cout << "匹配点数量出现错误" << endl;
  7. return;
  8. }
  9. float cx = -Q.at<double>(0, 3);
  10. float cy = -Q.at<double>(1, 3);
  11. float f = Q.at<double>(2, 3);
  12. float B = sqrt(T.at<double>(0,0)* T.at<double>(0, 0) + T.at<double>(1, 0) * T.at<double>(1, 0) + T.at<double>(2, 0) * T.at<double>(2, 0));
  13. pts3D.resize(ptsL.size());
  14. for (int i = 0; i < ptsL.size(); i++)
  15. {
  16. pts3D[i].x = (ptsL[i].x - cx) * B / (ptsL[i].x - ptsR[i].x);
  17. pts3D[i].y = (ptsL[i].y - cy) * B / (ptsL[i].x - ptsR[i].x);
  18. pts3D[i].z = f * B / (ptsL[i].x - ptsR[i].x);
  19. }
  20. //2基于cvPerspectiveTransform函数
  21. //CvMat *src = cvCreateMat(1, 1, CV_32FC3);//待变换点
  22. //CvMat *dst = cvCreateMat(1, 1, CV_32FC3);//变换后点
  23. //CvMat *perMat = cvCreateMat(4, 4, CV_32FC1);//透视投影变换矩阵
  24. //*perMat = Q;
  25. //pts3D.resize(ptsL.size());
  26. //for (int i = 0; i < ptsL.size(); i++)
  27. //{
  28. // cvZero(src);
  29. // cvZero(dst);
  30. // for (int j = 0; j < 3; j++)
  31. // {
  32. // float *p = (float*)cvPtr2D(src, 0, 0);
  33. // *p++ = ptsL[i].x;
  34. // *p++ = ptsL[i].y;
  35. // *p = ptsL[i].x - ptsR[i].x;
  36. // }
  37. // cvPerspectiveTransform(src, dst, perMat);
  38. // float *pp = (float*)cvPtr2D(dst, 0, 0);
  39. // pts3D[i].x = *pp++;
  40. // pts3D[i].y = *pp++;
  41. // pts3D[i].z = *pp;
  42. //}
  43. }

将双目标定校正后的参数导入即可。测试可行

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/152861?site
推荐阅读
相关标签
  

闽ICP备14008679号