Decoding a QR 8-bit grayscale image directly on Android

74 views
Skip to first unread message

gmmo

unread,
Aug 5, 2017, 5:43:45 AM8/5/17
to zxing
I have code that can decode a QR image from and android preview as below:

private void startPreview() {
final Camera.Size imageSize = camera.getPreviewSize();
final QRCodeReader reader = new QRCodeReader();

camera.startCameraPreview(new Camera.PreviewCallback() {
@Override
public void onPreviewFrame(byte[] data, Camera camera) {

if (!resultUpdated) {
PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data,
imageSize.width, imageSize.height,
QR_BARCODE_ROI_LEFT, QR_BARCODE_ROI_TOP,
QR_BARCODE_ROI_WIDTH, QR_BARCODE_ROI_HEIGHT, false);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result = reader.decode(bitmap); // This works

but I am not sure how to do the same if the image is a plain 8-bit bmp grayscale. Meaning the image would be:

Image = Width*Height*BYTE

where a BYTE is a simple gray scale of the pixel varying from 0 to 255

Can someone point me out on how this can be done?

thank you.

Lachezar Dobrev

unread,
Aug 7, 2017, 7:18:04 AM8/7/17
to gmmo, zxing
You should make your own LuminanceSource implementation instead of
using the PlanarYUVLuminanceSource.
However the PlanarYUVLuminanceSource should/might work out, because
YUV has the Y (luminance) in the most significant 4 bits, and the rest
is generally ignored.
Actually when I look at the code it seems that the
PlanarYUVLuminanceSource is a GrayScaleLuminanceSource that works for
YUV, not the other way around :).
> --
> You received this message because you are subscribed to the Google Groups "zxing" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to zxing+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages