Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ch7 pose_estimation_2d2d essential matrix 计算结果不一致 #332

Open
yq-90 opened this issue Dec 2, 2024 · 0 comments
Open

ch7 pose_estimation_2d2d essential matrix 计算结果不一致 #332

yq-90 opened this issue Dec 2, 2024 · 0 comments

Comments

@yq-90
Copy link

yq-90 commented Dec 2, 2024

这个问题可能重复 #277
跟着书上的代码,使用cv的orb特征提取,获得500个匹配,筛除hamming distance过小的剩余79个,与书上相同。但是最大的hamming distance我的cv库算出来是94而非95,图片显示如下,肉眼观察无问题。
Good Matches_screenshot_02 12 2024
到了pose estimation这里,代码如下,

void pose_estimate_2d2d(
        const std::vector<cv::KeyPoint> &kp1, const std::vector<cv::KeyPoint> &kp2,
        const std::vector<cv::DMatch> &matches, const cv::Mat &K, cv::Mat &R, cv::Mat &t)
{
    std::vector<cv::Point2f> p1;
    p1.reserve(4096);
    std::vector<cv::Point2f> p2;
    p2.reserve(4096);
    for (const cv::DMatch &m : matches) {
        p1.push_back(kp1[m.queryIdx].pt);
        p2.push_back(kp2[m.trainIdx].pt);
    }

    cv::Mat F;
    F = cv::findFundamentalMat(p1, p2, cv::FM_8POINT);
    std::cout << "Fundamental Matrix: " << std::endl << F << std::endl;

    cv::Mat E;
    E = cv::findEssentialMat(p1, p2, K);
    std::cout << "Essential Matrix: " << std::endl << E << std::endl;

    cv::Mat H;
    H = cv::findHomography(p1, p2, cv::RANSAC);
    std::cout << "Homograph Matrix: " << std::endl << H << std::endl;

    cv::recoverPose(E, p1, p2, K, R, t);

    std::cout << "K ^ -T * E * K ^ -1 = " << std::endl << K.inv().t() * E * K.inv() << std::endl;
}

参数列表中相对书上的代码多了一个相机内参K,数值来自ORB SLAM3的TUM FREIBURG2数据集:

K = 
520.909               0 325.141
        0       521.007 249.702
        0             0        1

算出来的Fundamental matrix

Fundamental Matrix: 
[4.54443750398184e-06, 0.0001333855576992603, -0.01798499246479044;
 -0.0001275657012964255, 2.266794804645652e-05, -0.01416678429206633;
 0.01814994639971766, 0.004146055870980492, 1]

与p175的结果误差不大,而essential matrix为

Essential Matrix: 
[-0.008457490262424407, 0.05444442307766559, 0.1546250154919883;
 -0.008221501658750767, 0.03351078406299837, -0.6896501808694672;
 -0.1153973780662328, 0.6945965301729999, 0.02159972069358522]

与书上结果毫无关联,甚至正负号都不一致,而计算homography则又与教材上近似:

Homograph Matrix: 
[0.9261214238501467, -0.1445322040811318, 33.26921163455131;
 0.04535424241276671, 0.9386696657491596, 8.570980719920279;
 -1.006198263331389e-05, -3.008140673707998e-05, 1]

而且,p175的验证E = t^R并不成立,t^R与E也有误差。
最后我的计算结果为:

R: 
[0.9956597556244213, -0.05614218770142942, 0.07422739245059702;
 0.052677474871967, 0.997465004120366, 0.04783982855603914;
 -0.07672505895097613, -0.04372208040859218, 0.9960931909282955]
t: 
[-0.9726822505199769;
 -0.2153697392331127;
 0.08663206649996272]

请问这些误差是正常的吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant