Shape Detection

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.


The boundary curve of an unknown polygon as an N-by-2 matrix (N is a varying number of points).
The reference shape to match to vertices.
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.
The vertices of a custom polygon if shape is Custom. The polygon must have at least three points and must not intersect itself.
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.
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.


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.
The size of the rectangle that encloses a detected shape in world coordinates. A 1-by-2 matrix.
The location (x, y) of the center point of a detected shape in world coordinates. A 1-by-2 matrix.
The longest diameter of a detected shape in world coordinates.
The mean square matching error between the input boundary and the matched shape.
The mean absolute distance between the boundary curve and the ideal matched shape in world coordinates.
The maximum distance from the ideal shape to the boundary curve inwards.
The maximum distance from the ideal shape to the boundary curve outwards.
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.