Ask Your Question
2

iterative closest point

asked 2012-08-30 07:09:57 -0600

mrgloom gravatar image

updated 2012-08-30 08:24:11 -0600

I want to implement ICP(iterative closest point) algorithm

  1. Associate points by the nearest neighbor criteria.
  2. Estimate transformation parameters using a mean square cost function.
  3. Transform the points using the estimated parameters.
  4. Iterate (re-associate the points and so on).

For every point in 1st set I found nearest point in 2nd set, but I don't understand how to do the 2nd step.

I tried folowing code, but it does't work, maybe I need to reject some pairs?

    vector<Point> vec_pair;
    for(int i=0;i<vec_M.size();++i)
    {
        double min_dist=INT_MAX;
        int id=-1;
        for(int j=0;j<vec_T.size();++j)
        {
            double metric= sqrt(double(vec_T[j].x-vec_M[i].x)*(vec_T[j].x-vec_M[i].x)+
                (vec_T[j].y-vec_M[i].y)*(vec_T[j].y-vec_M[i].y));
            if(min_dist>metric)
            {
                min_dist=metric;
                id=j;
            }
        }
        line(img,vec_M[i],vec_T[id],cvScalar(0,0,255));
        vec_pair.push_back(vec_T[id]);
    }
    Mat m= estimateRigidTransform(vec_M,vec_pair,1);
    cout<<m;
edit retag flag offensive close merge delete

Comments

Without looking at your code, but looking at your image, i think you have to somehow apply the following logic: if a point already has a neighbor, do not attribute it another neighbor.

Rui Marques gravatar imageRui Marques ( 2012-08-30 14:57:57 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
6

answered 2012-08-30 07:35:58 -0600

Ben gravatar image

updated 2012-08-30 08:29:17 -0600

Have a look at this tutorial :)

Or have a look at cv::estimateRigidTransform()

OR

cv::findHomography()

edit flag offensive delete link more

Comments

and what if I have perspective transform?

mrgloom gravatar imagemrgloom ( 2012-08-30 08:05:59 -0600 )edit

See my edited answer.

Ben gravatar imageBen ( 2012-08-30 08:30:14 -0600 )edit

Question Tools

Stats

Asked: 2012-08-30 07:09:57 -0600

Seen: 5,146 times

Last updated: Aug 30 '12