Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save fernandocyder/d95e55bd5c3a3b8d8c45944afe6b4ac3 to your computer and use it in GitHub Desktop.

Select an option

Save fernandocyder/d95e55bd5c3a3b8d8c45944afe6b4ac3 to your computer and use it in GitHub Desktop.
boofcv
public class BoofCVQRCodeReader {
public static String read(String filePath) {
// read the image to memory
BufferedImage input = UtilImageIO.loadImage(filePath);
// gray-out the image, easy to process
GrayU8 gray = ConvertBufferedImage.convertFrom(input, (GrayU8) null);
QrCodeDetector<GrayU8> detector = FactoryFiducial.qrcode(null, GrayU8.class);
detector.process(gray);
// get a list of all the qr codes it could successfully detect and decode
List<QrCode> detections = detector.getDetections();
Graphics2D g2 = input.createGraphics();
int strokeWidth = Math.max(4, input.getWidth() / 200); // in large images the line can be too thin
g2.setColor(Color.GREEN);
g2.setStroke(new BasicStroke(strokeWidth));
// get the first detected QR code and return its text
for (QrCode qr : detections) {
// The message encoded in the marker
System.out.println("found message: " + qr.message);
return qr.message;
}
// not able to detect any QR code, return NULL
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment