I have much trouble with xzing and decoding QR Code on a Google glass. The code works fine with starting the camera an calling the decoding method for the camera preview. The decoding always throws a "NotFoundExecption". The Test QRCode works fine on http://zxing.org/w/decode.jspx. I have tried many hints from other posts, but the problem always exists. I have taken the example from the zxing glass folder.
Here is my code for the method decode:
private void decode(byte[] data) {
Result rawResult = null;
int subtendedWidth = width / CameraConfigurationManager.ZOOM;
int subtendedHeight = height / CameraConfigurationManager.ZOOM;
int excessWidth = width - subtendedWidth;
int excessHeight = height - subtendedHeight;
//long start = System.currentTimeMillis();
PlanarYUVLuminanceSource source =
new PlanarYUVLuminanceSource(data,
width, height,
excessWidth / 2, excessHeight / 2,
subtendedWidth, subtendedHeight,
false);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
rawResult = new MultiFormatReader().decode(bitmap, hints);
//rawResult = new QRCodeReader().decode(bitmap, hints);
} catch (ReaderException re) {
// continue
Log.i(TAG,"Decode Result: " + re.getMessage());
}
//long end = System.currentTimeMillis();
//Log.i(TAG, "Decode in " + (end - start));
Handler handler = getHandler();
Message message;
if (rawResult == null) {
message = handler.obtainMessage(R.id.decode_failed);
} else {
Log.i(TAG, "Decode succeeded: " + rawResult.getText());
message = handler.obtainMessage(R.id.decode_succeeded, rawResult);
}
message.sendToTarget();
}
And here my code on the preview call:
public void onPreviewFrame(byte[] data, Camera camera) {
if (running) {
getHandler().obtainMessage(R.id.decode, data).sendToTarget();
}
}
The Constructor for my handler sets the following DecodingHints:
DecodeHandler() {
hints = new EnumMap<>(DecodeHintType.class);
hints.put(DecodeHintType.POSSIBLE_FORMATS,
Arrays.asList(BarcodeFormat.AZTEC, BarcodeFormat.QR_CODE, BarcodeFormat.DATA_MATRIX));
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
}
Does anybody see what my problem is?