How to read pixel values from Mat and Bitmap images on Android

Asked 2 years ago, Updated 2 years ago, 63 views

I don't know how to get the pixel value (0-255) of the coordinates you specified from the Mat type grayscale image on Android (Java).Please let me know if there are any available functions.

Also, I would appreciate it if you could tell me how to get pixel values from Bitmap in numeric form.

java android opencv

2022-09-30 16:19

1 Answers

Retrieving the value of RGBA 0..255 from Bitmap can be done using Bitmap#getPixel(x,y), for example:

//cf.https://stackoverflow.com/a/26960189/3501958
int color=bitmap.getPixel(x,y);

intred=Color.red(color);
int green=Color.green(color);
int blue=Color.blue(color);
int alpha=Color.alpha(color);

Log.d(TAG, String.format(
        "(R,G,B,A)=(%3d,%3d,%3d,%3d),red,green,blue,alpha
));

I'm not familiar with Mat format files, but once you convert them to Bitmap, the rest is the same.In any Android program, the image files (whether PNG or JPEG) are basically operated in Bitmap.

I haven't checked, but I found a code snippet called to convert Mat to Bitmap in OpenCV.


2022-09-30 16:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.