Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contour chain approximation "simple" is buggy or numerically instable #18

Open
MikeTkachuk opened this issue Aug 7, 2022 · 0 comments

Comments

@MikeTkachuk
Copy link

Description

I was running Fourier descriptors extraction on contours that naturally contain long straight lines. I used cv.CHAIN_APPROX_SIMPLE as usual but was having weird results as if the method does not converge:

image

I tried storing the contour as cv.CHAIN_APPROX_NONE instead and it fixed the problem for all of my cases:
image

Minimal setup to reproduce:

img = np.zeros((100,100), dtype=np.uint8)
img = cv.rectangle(img, (25,25), (75,75), (255,255,255), -1)
cnt, h = cv.findContours(img,cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
coeffs = pyefd.elliptic_fourier_descriptors(cnt[0].reshape(-1,2), order=10, normalize=True)
pyefd.plot_efd(coeffs)
plt.show()

img = np.zeros((100,100), dtype=np.uint8)
img = cv.rectangle(img, (25,25), (75,75), (255,0,0), -1)
cnt, h = cv.findContours(img,cv.RETR_EXTERNAL, cv.CHAIN_APPROX_NONE)
coeffs = pyefd.elliptic_fourier_descriptors(cnt[0].reshape(-1,2), order=10, normalize=True)
pyefd.plot_efd(coeffs)
plt.show()

I get:
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant