# RANSAC and 2D point clouds 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 close merge delete

Sort by » oldest newest most voted

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.

more

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

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

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.

@sammy , under some constraints (you know the relation is an affine transform for example), in most real world cases there is only one transform. 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?

more

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.

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.

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.

Official site

GitHub

Wiki

Documentation