Created
March 2, 2021 06:52
-
-
Save fernandocyder/d95e55bd5c3a3b8d8c45944afe6b4ac3 to your computer and use it in GitHub Desktop.
Revisions
-
fernandocyder created this gist
Mar 2, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ 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; } }