I have not yet been able to decode the QR code with ZXing. I am using BUG from buglabs.net, but the problem does not seem to have anything to do with the hardware, but rather with the image format.
This is what I still have:
try {
LuminanceSource source = new AWTImageLuminanceSource(bimage);
bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source));
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
Result result = reader.decode(bitmap, hints) ;
System.out.println("result is:" + result.getText());
} catch (ReaderException re) {
System.out.println("I can't find a barcode here");
}
The code is broken into reader.decode (bitmap, tooltips). I get a NullPointerException with the following trace:
java.lang.NullPointerException
at qrcoder.QRCoder.shoot(QRCoder.java:152)
at qrcoder.QRCoder.buttonEvent(QRCoder.java:89)
at com.buglabs.bug.input.pub.InputEventProvider.run(InputEventProvider.java:90)
I don't know what InputEventProvider is trying to tell me.
Thank you very much sarah
I don’t know how, but Reader never wrote. Finally, replace the Reader source code with a function, using a decoder instead.
private void shoot() throws IOException, NotFoundException, FormatException, ChecksumException {
Hashtable hints = null;
DecoderResult decoderResult;
cameraLED.setLEDFlash(true);
camera.grabPreview(buf);
camera.grabPreview(buf);
cameraLED.setLEDFlash(false);
InputStream in = new ByteArrayInputStream(camera.grabFull());
BufferedImage bImageFromConvert = ImageIO.read(in);
LuminanceSource source = new BufferedImageLuminanceSource(bImageFromConvert);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
ResultPoint[] points;
final Decoder decoder = new Decoder();
DetectorResult detectorResult = new Detector(bitmap.getBlackMatrix()).detect(hints);
decoderResult = decoder.decode(detectorResult.getBits(), hints);
points = detectorResult.getPoints();
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE);
if (result.getText() != null){
System.out.println("result is:" + result.getText());
}
else {System.out.println("bitmap is null");}
ic.repaint();
}
It works now, thanks!