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

Android. Process ARGB and Grayscale input packets #5018

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

definability
Copy link

Issue #5017
points to the issue of incorrect bitmap conversion in
Android when RGBA or Grayscale images are used.
As far as the library allows the creation of ALPHA8 bitmaps,
it is not enough to use only getBitmapFromRgb and getBitmapFromRgba,
so the new getBitmapFromAlpha method is needed.
Otherwise, existing users relying on the 8-bit input but not using the
input packet would catch errors despite their code operating as
intended.

Add correct processing of images with 1, 3, and 4 channels
to FaceDetector, FaceLandmarker, FaceStylizer,
GestureRecognizer, HandLandmarker, HolisticLandmarker,
ImageClassifier, ImageEmbedder, ImageSegmenter,
InteractiveSegmenter, ObjectDetector, and PoseLandmarker.
If the number of channels is not 1, 3, or 4,
throw MediaPipeException with INVALID_ARGUMENT status code.

Implement methods and functions needed to convert single-channel images
to RGBA bitmaps.
The native function AlphaToRGBA uses memset
to set all bytes of the resulting buffer to zeros
and then copies the alpha values of the input image to the alpha values
of the corresponding output pixels.

Perform a slight refactoring:
use operator[i] instead of *(array + i) for clarity.

Issue google-ai-edge#5017
points to the issue of incorrect bitmap conversion in
Android when RGBA or Grayscale images are used.
As far as the library allows the creation of ALPHA8 bitmaps,
it is not enough to use only `getBitmapFromRgb` and `getBitmapFromRgba`,
so the new `getBitmapFromAlpha` method is needed.
Otherwise, existing users relying on the 8-bit input but not using the
input packet would catch errors despite their code operating as
intended.

Add correct processing of images with 1, 3, and 4 channels
to `FaceDetector`, `FaceLandmarker`, `FaceStylizer`,
`GestureRecognizer`, `HandLandmarker`, `HolisticLandmarker`,
`ImageClassifier`, `ImageEmbedder`, `ImageSegmenter`,
`InteractiveSegmenter`, `ObjectDetector`, and `PoseLandmarker`.
If the number of channels is not 1, 3, or 4,
throw MediaPipeException with `INVALID_ARGUMENT` status code.

Implement methods and functions needed to convert single-channel images
to RGBA bitmaps.
The native function `AlphaToRGBA` uses `memset`
to set all bytes of the resulting buffer to zeros
and then copies the alpha values of the input image to the alpha values
of the corresponding output pixels.

Perform a slight refactoring:
use `operator[i]` instead of `*(array + i)` for clarity.
@definability
Copy link
Author

@schmidt-sebastian, is there a chance somebody will look at this PR?

Please let me know how to run the unit tests for Android MediaPipe. I wanted to add tests for this PR but failed to launch them, so I had to test the code manually on my device.

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.

None yet

2 participants