You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An Python/NumPy implementation of a method for approximating a contour with a Fourier series, as described in [1].
Installation
pip install pyefd
Usage
Given a closed contour of a shape, generated by e.g. scikit-image or
OpenCV, this package can fit a
Fourier series approximating the shape of the contour.
General usage examples
This section describes the general usage patterns of pyefd.
If you are using OpenCV to generate contours, this example shows how to
connect it to pyefd.
importcv2importnumpyfrompyefdimportelliptic_fourier_descriptors# Find the contours of a binary image using OpenCV.contours, hierarchy=cv2.findContours(
im, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# Iterate through all contours found and store each contour's # elliptical Fourier descriptor's coefficients.coeffs= []
forcntincontours:
# Find the coefficients of all contourscoeffs.append(elliptic_fourier_descriptors(
numpy.squeeze(cnt), order=10))
Using EFD as features
To use these as features, one can write a small wrapper function:
If the coefficients are normalized, then coeffs[0, 0] = 1.0, coeffs[0, 1] = 0.0 and
coeffs[0, 2] = 0.0, so they can be disregarded when using the elliptic Fourier descriptors as features.