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

xdem.coreg.ICP fails very underscriptively when not enough points are available #422

Open
erikmannerfelt opened this issue Aug 31, 2023 · 1 comment
Labels
invalid This doesn't seem right

Comments

@erikmannerfelt
Copy link
Contributor

I tried wrap my head around an error I got which even took me to the OpenCV C++ source code. Ooga booga!

When running .fit_pts() on a dataset that eventually didn't have enough points for registration (I'm still trying to figure out where the problem is; might be another issue coming up), ICP fails with a very strange error:

error: OpenCV(4.7.0) /build/source/modules/core/src/matrix.cpp:749: error: (-215:Assertion failed) m.dims >= 2 in function 'Mat'

Some debugging later and I realized one of the point clouds were empty, which the above error is obviously trying to tell me.

There's already an exception handler (see below) for this but for some reason the exception is new. Easy fix is to just catch both exceptions and print the nicer error message.

xdem/xdem/coreg/affine.py

Lines 543 to 553 in 3956073

try:
_, residual, matrix = icp.registerModelToScene(points["tba"], points["ref"])
except cv2.error as exception:
if "(expected: 'n > 0'), where" not in str(exception):
raise exception
raise ValueError(
"Not enough valid points in input data."
f"'reference_dem' had {points['ref'].size} valid points."
f"'dem_to_be_aligned' had {points['tba'].size} valid points."
)

@rhugonnet
Copy link
Contributor

The cause of this might have been SciPy map coordinates default prefilter removing data points: GlacioHack/geoutils#484

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants