 # Shape Detection

Detects shapes by matching a boundary curve to a known geometric shape or a user-defined shape.

This tool requires that the input is an ordered set of points that follows the boundary of an object. Suitable input can be generated for example with boundary detection.

## Inputs

vertices
The boundary curve of an unknown polygon as an N-by-2 matrix (N is a varying number of points).
shape
The reference shape to match to vertices.
aspectRatio
The aspect ratio (width/height) of the reference shape. In the case of an isosceles triangle with two equal sides with length b and the remaining side with length a the aspect ratio is a/b. An aspect ratio of one thus produces an equilateral triangle.
modelVertices
The vertices of a custom polygon if shape is Custom. The polygon must have at least three points and must not intersect itself.
maxError
The maximum matching error. If matching the input polygon to the reference shape produces a bigger error, no match will be reported. Zero error means a perfect match.
preferredAngle
If the model shape is symmetrical about at least one axis, determining a unique coordinate frame is not possible. In such a case, this parameter defines the preferred angle of the output frame's x axis with respect to the world coordinate system's x axis.

## Outputs

frame
The location and orientation of the upper left corner of a rectangle that encloses the detected shape in world coordinates. A 4-by-4 matrix.
size
The size of the rectangle that encloses a detected shape in world coordinates. A 1-by-2 matrix.
center
The location (x, y) of the center point of a detected shape in world coordinates. A 1-by-2 matrix.
diameter
The longest diameter of a detected shape in world coordinates.
matchingError
The mean square matching error between the input boundary and the matched shape.
meanDiff
The mean absolute distance between the boundary curve and the ideal matched shape in world coordinates.
maxInDiff
The maximum distance from the ideal shape to the boundary curve inwards.
maxOutDiff
The maximum distance from the ideal shape to the boundary curve outwards.
matchFound
true if the input polygon was successfully matched to the reference shape and false otherwise. This output is useful for example as an input to a gate.

The frame, size, center and diameter parameters are measured from the ideal (model) shape after fitting the model to the boundary. This technique is not sensitive to small deficiencies in the boundary curve. The downside is that cropping the input image based on the calculated frame and size generally loses part of the boundary curve.