Ask Your Question
2

RANSAC and 2D point clouds

asked 2012-08-28 02:45:39 -0600

mrgloom gravatar image

updated 2012-08-28 06:27:08 -0600

I have 2 point clouds in 2D and I want to use RANSAC to determine transformation matrix between them. I have no pairs of points, just 2 sets of points. How can I do this in OpenCV?


I tried to write ransac-like scheme for my purposes.

  1. Get 4 random points from 1st set and from 2nd set.
  2. Compute transform matrix H using getPerspectiveTransform.
  3. Warp 1st set of points using H and test how they aligned to the 2nd set of points using some metric(I don't know what metric I should use I tried sum of min distance for all points in 1st set, but it seems it's not work good if points group together after transform)
  4. Repeat 1-3 N times and choose best transform according to metric.

maybe I should use different metric?

Also I have idea that I can match points using shape context algorithm and only then use RANSAC(or some other algorithm) to determine transformation.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2012-08-28 03:19:16 -0600

sammy gravatar image

Just call

cv::Mat transform = cv::findHomography(firstPtVector, secndPtVector, CV_RANSAC);

The last parameter is optional, and it defaults to RANSAC. In C++, the point clouds must be either std::vector<cv::Point> either cv::Mat with one point per line.

edit flag offensive delete link more

Comments

but we must have pair point in vectors firstPtVector, secndPtVector isn't it? I have just 2 point sets without pairs.

mrgloom gravatar imagemrgloom ( 2012-08-28 06:12:38 -0600 )edit

If you do not have pairing, you cannot define anything. There are infinite combinations of possibilities of transforms between two points sets.

sammy gravatar imagesammy ( 2012-08-28 07:03:47 -0600 )edit

I don't fink so, for example http://www.mrpt.org/Iterative_Closest_Point_(ICP)_and_other_matching_algorithms I just don't know how to generalize ICP algorithm to perspective transform.

mrgloom gravatar imagemrgloom ( 2012-08-28 08:15:01 -0600 )edit

@sammy , under some constraints (you know the relation is an affine transform for example), in most real world cases there is only one transform.

Mehdi gravatar imageMehdi ( 2016-10-14 08:36:27 -0600 )edit
0

answered 2012-08-28 12:06:14 -0600

Jacek gravatar image

I don't think RANSAC is a good idea in your case. RANSAC can be used when you have a number of measurements (e.g. pairs of corresponding points from 2 sets) containing some outliers (e.g. incorrectly matched points). The more outliers you have the more RANSAC iterations are needed to estimate parameters with a given confidence. In your scenario, choosing matching points randomly, you'll need a really HUGE number of iterations to ensure proper matching is found. Computational cost may be prohibitive.

Can you give more details about your problem. Why are you trying to estimate perspective transform? Are these 2D points projections of some 3D points?

edit flag offensive delete link more

Comments

I need to align raster and vector data, raster data is distorted, I represent the, as point clouds in 2D. Look here there is no need for pair points http://www.mrpt.org/Iterative_Closest_Point_(ICP)_and_other_matching_algorithms but I need non rigid ICP.

mrgloom gravatar imagemrgloom ( 2012-08-29 01:11:40 -0600 )edit

If distortion is not too big you may still use ICP. ICP doesn't require that 2 point clouds are exactly identical. One point cloud may contain points corrupted with a noise and ICP will still work.

The catch is that ICP requires point clouds to be roughly aligned. So if corresponding points in your point clouds are quite close you may use ICP. Otherwise you'll need to use some method to roughly align your point clouds (e.g. compute some kind of feature descriptors for each point, use these feature descriptors to create matching between points in both clouds and roughly align point clouds using these matchings) and then use ICP for final registration.

Jacek gravatar imageJacek ( 2012-08-29 03:40:58 -0600 )edit

The problem is that implementation of ICP that I found have only translate and rotation invariance, but I need to register images with perspective transform.

mrgloom gravatar imagemrgloom ( 2012-08-29 08:21:25 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2012-08-28 02:45:39 -0600

Seen: 7,316 times

Last updated: Aug 28 '12