Convert a RGB565 byte[] to Luminance source

291 views
Skip to first unread message

Umresh

unread,
Sep 9, 2014, 7:26:07 AM9/9/14
to zx...@googlegroups.com
I have a byte[] of RGB565 and I want to convert it to the YUV byte[]. I tried other methods but i have performance issues(poor performance 4 fps). It'll be faster if I use the incoming RGB byte[].
Guys help me.

Thanks

Lachezar Dobrev

unread,
Sep 9, 2014, 8:20:54 AM9/9/14
to Umresh, zxing
You should "probably" try and use the RGB as luminance source,
rather than converting to YUV and then using that for luminance
source.

com.google.zxing.RGBLuminanceSource
https://github.com/zxing/zxing/blob/master/core/src/main/java/com/google/zxing/RGBLuminanceSource.java

This implementation is RGB-888, so a RGB-565 might require some
changing in the shift-and-mask operations.
Also this implementation converts the whole frame upfront, which
might not be the best solution, but you can try.

I just realised, that RGB-565 does not fit in a byte. Is it int[],
or is it two bytes per pixel?

Umresh

unread,
Sep 9, 2014, 9:09:30 AM9/9/14
to zx...@googlegroups.com, m.um...@gmail.com

I'm using this vuforia code
if (imageRGB565 != null) {
int imageWidth = imageRGB565.getWidth();
int imageHeight = imageRGB565.getHeight();
int stride = imageRGB565.getStride();
ByteBuffer pixels = imageRGB565.getPixels();
byte[] pixelArray = new byte[pixels.remaining()];
pixels.get(pixelArray, 0, pixelArray.length);

saveCapturedImage(pixelArray, imageWidth, imageHeight);
}
here I get byte[] (pixelArray) and the frame format is set to RGB565. So I converted it to bitmap and used RGBLuminance for bitmap version. I tried pixel version too but it didn't detect but bitmap version detected. The problem is the performance is poor and is there any way to improve it.

Thanks for your help.

Lachezar Dobrev

unread,
Sep 10, 2014, 4:35:42 AM9/10/14
to Umresh, zxing
This code seems severely ineffective.
It creates a large byte array, then it seems to perform pre-emptive
conversion of the image.
Are you SURE you need the image? I was left with the impression that
you need to scan the frame for a bar-code. You should try to shorten
the process of bringing the frame into a LuminanceSource instead. A
new implementation of the LuminanceSource should be better.

The code is too short to give any deeper impression.

Umresh

unread,
Sep 10, 2014, 5:20:48 AM9/10/14
to zx...@googlegroups.com, m.um...@gmail.com
I don't need to save the image but I have to use the data in pixelArray byte[] and its a RGB565. If i convert the byte[] to int[] and use in RGBLuminanceSource I get error.
I convert to int[] saying 3 bytes/pixel and store the values in an int[] then pass to RGBLuminance, it the converts it to byte[]. I get error in
int pixel = pixels[offset + x];
ArrayIndexOutOfBounds
Reply all
Reply to author
Forward
0 new messages