Is there an easy way/algorithm to match 2 clouds of 2D points?

后端 未结 7 1737
萌比男神i
萌比男神i 2020-12-15 00:43

I am wondering if there is an easy way to match (register) 2 clouds of 2d points.

Let\'s say I have an object represented by points and an cluttered 2nd image with t

7条回答
  •  醉酒成梦
    2020-12-15 01:22

    Here is the function that finds translation and rotation. Generalization to scaling, weighted points, and RANSAC are straight forward. I used openCV library for visualization and SVD. The function below combines data generation, Unit Test , and actual solution.

     // rotation and translation in 2D from point correspondences
     void rigidTransform2D(const int N) {
    
    // Algorithm: http://igl.ethz.ch/projects/ARAP/svd_rot.pdf
    
    const bool debug = false;      // print more debug info
    const bool add_noise = true; // add noise to imput and output
    srand(time(NULL));           // randomize each time
    
    /*********************************
     * Creat data with some noise
     **********************************/
    
    // Simulated transformation
    Point2f T(1.0f, -2.0f);
    float a = 30.0; // [-180, 180], see atan2(y, x)
    float noise_level = 0.1f;
    cout<<"True parameters: rot = "<(2, 2)<0)
        RMSE = sqrt(RMSE/N);
    
    // Final estimate msg
    cout<<"Estimate = "<& src, const vector& dst,
            const float* param, const bool* inliers, const Point2f center) {
    
        const bool all_inliers = (inliers==NULL); // handy when we run QUADRTATIC will all inliers
        unsigned int n = src.size();
        assert(n>0 && n==dst.size());
    
        float ang_rad = param[0];
        Point2f T(param[1], param[2]);
        float cos_alpha = cos(ang_rad);
        float sin_alpha = sin(ang_rad);
    
        double RMSE = 0.0;
        int ninliers = 0;
        for (unsigned int i=0; i(2, 2)< best_ninliers) {
                best_ninliers = ninliers;
                best_param[0] = param[0];
                best_param[1] = param[1];
                best_param[2] = param[2];
                best_rmse = cur_rmse;
    
    
    #ifdef DEBUG_RANSAC
                cout<<" --- Solution improved: "<<
                        best_param[0]<<", "< INLIERS_RATIO_OK) {
    #ifdef DEBUG_RANSAC
                    cout<<"Breaking early after "<< iter+1<<
                            " iterations; inlier ratio = "<

提交回复
热议问题