| 992 | } |
| 993 | |
| 994 | float Initializer::NormalizeScale( |
| 995 | std::vector<Eigen::Vector3f>& points3d, |
| 996 | Eigen::Vector3f& t |
| 997 | ) const { |
| 998 | if (points3d.empty()) { |
| 999 | return 1.0f; |
| 1000 | } |
| 1001 | |
| 1002 | // Collect depths (Z-coordinate in frame1 = forward direction) |
| 1003 | // For 360 camera, depth is the distance from camera center |
| 1004 | std::vector<float> depths; |
| 1005 | depths.reserve(points3d.size()); |
| 1006 | |
| 1007 | for (const auto& pt : points3d) { |
| 1008 | // Skip invalid points (zero vector) |
| 1009 | if (pt.norm() < 1e-6f) continue; |
| 1010 | |
| 1011 | // For 360 camera: depth = distance from origin |
| 1012 | float depth = pt.norm(); |
| 1013 | if (depth > 0.01f) { // Valid depth |
| 1014 | depths.push_back(depth); |
| 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | if (depths.empty()) { |
| 1019 | return 1.0f; |
| 1020 | } |
| 1021 | |
| 1022 | // Compute median depth |
| 1023 | std::sort(depths.begin(), depths.end()); |
| 1024 | float median_depth; |
| 1025 | size_t mid = depths.size() / 2; |
| 1026 | if (depths.size() % 2 == 0) { |
| 1027 | median_depth = (depths[mid - 1] + depths[mid]) / 2.0f; |
| 1028 | } else { |
| 1029 | median_depth = depths[mid]; |
| 1030 | } |
| 1031 | |
| 1032 | // Scale factor to normalize median depth to 1.0 (unit scale for IMU initialization) |
| 1033 | const float target_median_depth = 100.0f; |
| 1034 | float scale_factor = target_median_depth / median_depth; |
| 1035 | |
| 1036 | // Scale all 3D points |
| 1037 | for (auto& pt : points3d) { |
| 1038 | pt *= scale_factor; |
| 1039 | } |
| 1040 | |
| 1041 | // Scale translation vector |
| 1042 | t *= scale_factor; |
| 1043 | |
| 1044 | return scale_factor; |
| 1045 | } |
| 1046 | |
| 1047 | void Initializer::CreateMapPoints( |
| 1048 | std::shared_ptr<Frame> frame1, |
nothing calls this directly
no outgoing calls
no test coverage detected