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

refactor: Adds better error handling for image format YUV_420_888. #730

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

panmari
Copy link
Contributor

@panmari panmari commented Jan 8, 2025

This format can not be read by the InputImage.fromByteArray API, as documented at https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#public-static-inputimage-frombytearray-byte[]-bytearray,-int-width,-int-height,-int-rotationdegrees,-int-format.

Converting the bytes received here to the right type (android.media.Image) is non-trivial.

Additionally improving error handling by passing along stack traces when possible.

@panmari panmari changed the title Adds better error handling for image format YUV_420_888. refactor: Adds better error handling for image format YUV_420_888. Jan 8, 2025
@panmari panmari marked this pull request as ready for review January 8, 2025 14:26
@panmari panmari force-pushed the imageerror branch 3 times, most recently from 43755fc to 327d0df Compare January 8, 2025 20:07
@fbernaly
Copy link
Collaborator

fbernaly commented Jan 8, 2025

And update branch, it is out-of-date

This format can not be read by the InputImage.fromByteArray API, as documented at https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#public-static-inputimage-frombytearray-byte[]-bytearray,-int-width,-int-height,-int-rotationdegrees,-int-format.

Converting the bytes received here to the right type (android.media.Image) is non-trivial.

Additionally improving error handling by passing along stack traces when possible.
@panmari
Copy link
Contributor Author

panmari commented Jan 8, 2025

Rebased, as requested.

byte[] data = (byte[]) Objects.requireNonNull(imageData.get("bytes"));
int imageFormat = Integer.parseInt(Objects.requireNonNull(metaData.get("image_format")).toString());
int rotationDegrees = Integer.parseInt(Objects.requireNonNull(metaData.get("rotation")).toString());
int width = Double.valueOf(Objects.requireNonNull(metaData.get("width")).toString()).intValue();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to:

int width = Integer.parseInt(Objects.requireNonNull(metaData.get("width")).toString());

do the same for height

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologize, I think I was too quick at resolving the last comment on this.

On the dart side, where this JSON object is created, it is set as double. That is because the dart type of Size.weight and Size.height is double.

Considering that, I feel the code does the right thing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@fbernaly fbernaly merged commit 8255747 into flutter-ml:develop Jan 9, 2025
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants