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

Detailed error for generic type parameter of find_contours_with_threshold #694

Open
sakird opened this issue Nov 21, 2024 · 2 comments
Open

Comments

@sakird
Copy link

sakird commented Nov 21, 2024

I am learning Rust and tried to use find_contours_with_threshold function that I have asked ChatGPT to prepare.

Calling:
let contours = find_contours_with_threshold::<u8>(&binary_edges, 0u8);

Image dimensions were too big for u8. And since I am new to Rust I have been trying to find the cause of this error. I have finally managed to find it, here:

contour_points.push(Point::new(cast(pos3.x).unwrap(), cast(pos3.y).unwrap()));

After changing that dimension to u32, it worked.
This cast panics if image width or height is bigger than max of u8. Would it be OK to update this code like this:

contour_points.push(Point::new( cast(pos3.x).expect("Generic data type should be bigger than width."), cast(pos3.y).expect("Generic data type should be bigger than height."), ));

If this is acceptable, I can send a PR.

@sakird sakird changed the title Detailen error for generic type parameter of find_contours_with_threshold Detailed error for generic type parameter of find_contours_with_threshold Nov 21, 2024
@ripytide
Copy link
Member

ripytide commented Nov 21, 2024

That seems like an improvement to me, since this is a user facing error then having an error message is better than nothing. Thought I might make the error message : Generic Type Parameter T should be bigger than width/Generic Type Parameter T should be bigger than height.

@sakird
Copy link
Author

sakird commented Nov 21, 2024

Then I will send a PR. Thanks.

sakird added a commit to sakird/imageproc that referenced this issue Nov 22, 2024
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

2 participants