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

手写Findhomography,能否考虑引入ocvm中 #120

Open
futz12 opened this issue May 30, 2024 · 1 comment
Open

手写Findhomography,能否考虑引入ocvm中 #120

futz12 opened this issue May 30, 2024 · 1 comment

Comments

@futz12
Copy link
Contributor

futz12 commented May 30, 2024

手写过Findhomography(在不显著增加体积情况下,增加一些功能),个人感觉比较有用。能否考虑引入ocvm中

// 对OpenCV的findHomography的重写,利用SVD求解
    cv::Mat Findhomography(std::vector<cv::Point2f> src, std::vector<cv::Point2f> target) {
        // 求解系统为 A*X - B = 0

        const int n = src.size();
        float x[9] = {0};

        cv::Mat A = cv::Mat::zeros(2 * n, 8, CV_32F);
        cv::Mat B = cv::Mat::zeros(2 * n, 1, CV_32F);
        cv::Mat X(8, 1, CV_32F, x);

        for (int i = 0; i < n; i++) {
            A.at<float>(i, 0) = src[i].x;
            A.at<float>(i + n, 3) = src[i].x;
            A.at<float>(i, 1) = src[i].y;
            A.at<float>(i + n, 4) = src[i].y;

            A.at<float>(i, 2) = 1;
            A.at<float>(i + n, 5) = 1;

            A.at<float>(i, 6) = -src[i].x * target[i].x;
            A.at<float>(i, 7) = -src[i].y * target[i].x;

            A.at<float>(i + n, 6) = -src[i].x * target[i].y;
            A.at<float>(i + n, 7) = -src[i].y * target[i].y;

            B.at<float>(i, 0) = target[i].x;
            B.at<float>(i + n, 0) = target[i].y;
        }

        cv::solve(A, B, X, cv::DECOMP_SVD);


        x[8] = 1;
        cv::Mat H = cv::Mat(3, 3, CV_32F, x).clone();
        return H;
    }
···
@nihui
Copy link
Owner

nihui commented Jun 27, 2024

如果你的实现和标准 opencv findHomography 行为保持一致,欢迎 pull request

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

2 participants