| 884 | } |
| 885 | |
| 886 | bool Initializer::ValidateInitialization( |
| 887 | const std::vector<Eigen::Vector3f>& bearings1, |
| 888 | const std::vector<Eigen::Vector3f>& bearings2, |
| 889 | const std::vector<Eigen::Vector3f>& points3d, |
| 890 | const Eigen::Matrix3f& R, |
| 891 | const Eigen::Vector3f& t, |
| 892 | const std::vector<bool>& inlier_mask, |
| 893 | float& mean_error |
| 894 | ) const { |
| 895 | // Validation: |
| 896 | // Check reprojection error in BOTH frames (ref and cur) |
| 897 | |
| 898 | int valid_count = 0; |
| 899 | int total_inliers = 0; |
| 900 | int skip_zero = 0; |
| 901 | int skip_ref = 0; |
| 902 | int skip_cur = 0; |
| 903 | std::vector<float> errors_pixel; |
| 904 | float error_sum = 0.0f; |
| 905 | |
| 906 | const float reproj_err_thr_sq = m_max_reprojection_error * m_max_reprojection_error; |
| 907 | |
| 908 | for (size_t i = 0; i < points3d.size(); ++i) { |
| 909 | if (!inlier_mask[i]) continue; |
| 910 | total_inliers++; |
| 911 | |
| 912 | // Skip invalid points (zero vector - triangulation failed) |
| 913 | if (points3d[i].norm() < 1e-6) { |
| 914 | skip_zero++; |
| 915 | continue; |
| 916 | } |
| 917 | |
| 918 | const Eigen::Vector3f& pt = points3d[i]; |
| 919 | |
| 920 | // Check reprojection error in BOTH frames |
| 921 | |
| 922 | // 1. Reprojection error in frame1 (reference) |
| 923 | float error_ref = ComputeReprojectionErrorInFrame(pt, bearings1[i]); |
| 924 | |
| 925 | // DEBUG: Show first few points |
| 926 | if (total_inliers <= 5) { |
| 927 | Eigen::Vector3f b1 = bearings1[i]; |
| 928 | Eigen::Vector3f pt_dir = pt.normalized(); |
| 929 | float dot = pt_dir.dot(b1); |
| 930 | LOG_INFO(" [DBG] pt[{}]: pt=({:.3f},{:.3f},{:.3f}), b1=({:.3f},{:.3f},{:.3f}), dot={:.3f}, err_ref={:.2f}px", |
| 931 | i, pt.x(), pt.y(), pt.z(), b1.x(), b1.y(), b1.z(), dot, error_ref); |
| 932 | } |
| 933 | |
| 934 | if (error_ref > m_max_reprojection_error) { |
| 935 | skip_ref++; |
| 936 | continue; |
| 937 | } |
| 938 | |
| 939 | // 2. Reprojection error in frame2 (current) |
| 940 | // Transform point to frame2: P_cur = R * P_ref + t |
| 941 | Eigen::Vector3f point_in_frame2 = R * pt + t; |
| 942 | float error_cur = ComputeReprojectionErrorInFrame(point_in_frame2, bearings2[i]); |
| 943 |
nothing calls this directly
no outgoing calls
no test coverage detected