# Match rigid 2D object

Matches key points with the RANSAC algorithm using a geometric model that allows a proper rigid transformation and scaling in two dimensions. Given a set of points and their associated feature vectors, this matcher tries to find a transformation that maps the points to one of the known models in the model database with sufficient accuracy so that the shape of the model is preserved.

In mathematics, a proper rigid transformation preserves distances between every pair of points and the handedness of shapes. In other words, it allows translation and rotation but no reflection or shape-changing transformations such as scaling or stretching. This tool can however allow scale changes even though it models rigid objects because the apparent size of a rigid object may change due to changing distance from the camera.

The matching algorithm makes it possible to impose fine-grained limits on allowed changes between a model and a query. It is possible to limit allowed rotation angles and scaling factors to a predefined range. The algorithm can also prune duplicate detections that overlap each other. Finally, a number of parameters are provided for making an optimal trade-off between speed an accuracy.

## Inputs

rotationInvariant
If true, the matcher will allow at most maxRotationAngle degrees of rotation between a model and an unknown object to be matched. Otherwise, no rotation will be allowed.
maxRotationAngle
The maximum allowed absolute rotation angle in degrees. If set to 180, all rotations will be accepted.
scaleInvariant
If true, the matcher will allow a relative scale change between minScale and maxScale. Otherwise, no scale changes will be allowed.
minScale
The minimum accepted scaling factor. If the size of an unknown object is less than minScale times that of the matched model, no match will be reported.
maxScale
The maximum accepted scaling factor. If the size of an unknown object is greater than maxScale times that of the matched model, no match will be reported.
minimizeGeometricError
Enables or disables geometric refinement of the matched transformation. The RANSAC algorithm produces a transformation that is based on a random subset of the input points. If minimizeGeometricError is enabled, the model will be adjusted so that it matches the matched points with the smallest possible geometric error. This will generally result in more accurate match positioning, but it also makes the algorithm a bit slower.
mergeNearbyMatches
If true, the matcher will merge detections whose scale, angle and location are close enough to each other. This is usually the right thing to do because the same model can often be matched with slightly different parameters. Model merging puts such nearby matches into one match. With geometric error minimization enabled, the geometric model will be fitted to all of the points in the merged matches.
scaleTolerance
The maximum allowed relative scale change in merging nearby detections. Setting scaleTolerance to a non-zero value makes it possible to merge detected models even if their sizes are slightly different. For example, if scaleTolerance is 0.1, the tool can merge two detections if the scaling factor of the smaller detection is greater than 90% of the scaling factor of the larger detection.
angleTolerance
The maximum allowed angle change in merging nearby detections, in degrees. Setting angleTolerance to a non-zero value makes it possible to merge detected models even if their angles are slightly different. For example, if scaleTolerance is 5, the tool can merge two detections if the angle between them is less than 5 degrees.
distanceTolerance
The maximum allowed distance between origins of models to be merged, in world coordinates. Setting distanceTolerance to a non-zero value makes it possible to merge detected models even if their locations are slightly different. For example, if distanceTolerance is set to 10, the tool can merge overlapping detections if the distance between their coordinate frames is less than 10 world units.
selectionProbability
The probability of choosing a model that fits the data well enough. Provided that a model can be fitted to the input points, the RANSAC algorithm can estimate the number or rounds required to find a good solution. Due to the probabilistic nature of the algorithm, one can never be sure that the solution is actually found. This parameter sets the confidence level for finding a solution. A higher probability means slower execution.
maxIterations
The maximum number of iterations the RANSAC algorithm will run if it doesn't find a match earlier. This value is used to put a hard upper bound to the time the algorithm will run even when a high selectionProbability value is used.
maxSamplings
The maximum number of random samplings the algorithm will try while finding model candidates. On each iteration, the algorithm randomly picks a subset of points to match the models against. The algorithm will fail if no valid model candidates are found after maxSamplings random subsets.
maxPointMatchDistance
The threshold for accepting a point as an match. When the matcher tries to fit different models to the input points, it measures the distance of each point to the corresponding point in the model. If the distance exceeds maxPointMatchDistance, the point will be considered an outlier and rejected. The points whose distance to the corresponding model point is less than or equal to maxPointMatchDistance are regarded as inliers to which the model can be fitted.
minMatchedPoints
The minimum number of matched key point pairs that are required for an accepted match. A candidate model will be rejected if the number of matched points is less than this value. Increasing this value makes spurious detections less likely.

Inherits MatchKeyPointsTool.