MCPcopy Create free account
hub / github.com/UZ-SLAMLab/ORB_SLAM3 / ProjectPointDistort

Method ProjectPointDistort

src/KeyFrame.cc:1011–1072  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1009}
1010
1011bool KeyFrame::ProjectPointDistort(MapPoint* pMP, cv::Point2f &kp, float &u, float &v)
1012{
1013
1014 // 3D in absolute coordinates
1015 Eigen::Vector3f P = pMP->GetWorldPos();
1016
1017 // 3D in camera coordinates
1018 Eigen::Vector3f Pc = mRcw * P + mTcw.translation();
1019 float &PcX = Pc(0);
1020 float &PcY = Pc(1);
1021 float &PcZ = Pc(2);
1022
1023 // Check positive depth
1024 if(PcZ<0.0f)
1025 {
1026 cout << "Negative depth: " << PcZ << endl;
1027 return false;
1028 }
1029
1030 // Project in image and check it is not outside
1031 float invz = 1.0f/PcZ;
1032 u=fx*PcX*invz+cx;
1033 v=fy*PcY*invz+cy;
1034
1035 // cout << "c";
1036
1037 if(u<mnMinX || u>mnMaxX)
1038 return false;
1039 if(v<mnMinY || v>mnMaxY)
1040 return false;
1041
1042 float x = (u - cx) * invfx;
1043 float y = (v - cy) * invfy;
1044 float r2 = x * x + y * y;
1045 float k1 = mDistCoef.at<float>(0);
1046 float k2 = mDistCoef.at<float>(1);
1047 float p1 = mDistCoef.at<float>(2);
1048 float p2 = mDistCoef.at<float>(3);
1049 float k3 = 0;
1050 if(mDistCoef.total() == 5)
1051 {
1052 k3 = mDistCoef.at<float>(4);
1053 }
1054
1055 // Radial distorsion
1056 float x_distort = x * (1 + k1 * r2 + k2 * r2 * r2 + k3 * r2 * r2 * r2);
1057 float y_distort = y * (1 + k1 * r2 + k2 * r2 * r2 + k3 * r2 * r2 * r2);
1058
1059 // Tangential distorsion
1060 x_distort = x_distort + (2 * p1 * x * y + p2 * (r2 + 2 * x * x));
1061 y_distort = y_distort + (p1 * (r2 + 2 * y * y) + 2 * p2 * x * y);
1062
1063 float u_distort = x_distort * fx + cx;
1064 float v_distort = y_distort * fy + cy;
1065
1066 u = u_distort;
1067 v = v_distort;
1068

Callers

nothing calls this directly

Calls 1

GetWorldPosMethod · 0.80

Tested by

no test coverage detected