-
Notifications
You must be signed in to change notification settings - Fork 757
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
Conversation
...google_mlkit_commons/android/src/main/java/com/google_mlkit_commons/InputImageConverter.java
Outdated
Show resolved
Hide resolved
43755fc
to
327d0df
Compare
...google_mlkit_commons/android/src/main/java/com/google_mlkit_commons/InputImageConverter.java
Show resolved
Hide resolved
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.
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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
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.