QuadrilateralFitter

raw JSON →
1.12 verified Fri May 01 auth: no python

QuadrilateralFitter is an efficient and easy-to-use Python library for fitting irregular quadrilaterals from irregular polygons or any noisy data. Current version is 1.12, released on PyPI. The library is actively maintained and provides a simple API to fit quadrilaterals to polygon data, often used in computer vision and geometry processing. Release cadence is irregular, with minor updates.

pip install quadrilateral-fitter
error ImportError: cannot import name 'QuadrilateralFitter' from 'quadrilateral_fitter'
cause Trying to import from the wrong module path or the package not installed correctly.
fix
Run 'pip install quadrilateral-fitter' and use 'from quadrilateral_fitter import QuadrilateralFitter'.
error TypeError: __init__() missing 1 required positional argument: 'polygon'
cause QuadrilateralFitter requires the polygon argument at initialization.
fix
Provide the polygon as a list of coordinates: QuadrilateralFitter([(x1,y1), (x2,y2), ...])
gotcha Input polygon must be a list of (x, y) tuples or a numpy array with shape (N, 2). Order matters: vertices should be in sequential order around the polygon.
fix Ensure polygon is closed? Not required but points should be in order. For unordered points, the fit may produce unexpected results.
deprecated In version 1.x, the method 'fit' returns a 'Quadrilateral' object. In future versions, the API might change. Use the current pattern.
fix Check documentation for any changes when upgrading.

Basic usage: fit a quadrilateral to a noisy polygon.

from quadrilateral_fitter import QuadrilateralFitter

# Example polygon: coordinates (x, y) list of points
polygon = [(0, 0), (1, 0), (1, 1), (0.5, 1.5), (0, 1)]

# Create fitter instance
fitter = QuadrilateralFitter(polygon)

# Fit the quadrilateral
fitted_quad = fitter.fit()

# Access fitted vertices
print(fitted_quad.vertices)