Ask Your Question
2

iterative closest point

asked Aug 30 '12

mrgloom gravatar image

updated Aug 30 '12

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;
Preview: (hide)

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 (Aug 30 '12)edit

1 answer

Sort by » oldest newest most voted
6

answered Aug 30 '12

Ben gravatar image

updated Aug 30 '12

Have a look at this tutorial :)

Or have a look at cv::estimateRigidTransform()

OR

cv::findHomography()

Preview: (hide)

Comments

and what if I have perspective transform?

mrgloom gravatar imagemrgloom (Aug 30 '12)edit

See my edited answer.

Ben gravatar imageBen (Aug 30 '12)edit

Question Tools

Stats

Asked: Aug 30 '12

Seen: 5,182 times

Last updated: Aug 30 '12