I can get the value of the QR code using ZXing library but I also need the coordinates of the corner points of the QR code. How can I access those coordinates.
I don't know exactly which corner coordinates you want to extract. But I'm quite sure you can calculate them from the result points got from the Result.getResultPoints() method.
Example: With the following image (200x200 pixels) and code snippet
BufferedImage image = ImageIO.read(new File("QRCode-1.png"));
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
new BufferedImageLuminanceSource(image)));
Reader reader = new QRCodeReader();
Result result = reader.decode(binaryBitmap);
System.out.println("text: " + result.getText());
ResultPoint[] resultPoints = result.getResultPoints();
System.out.println("resultPoints:");
for (int i = 0; i < resultPoints.length; i++) {
ResultPoint resultPoint = resultPoints[i];
System.out.print(" [" + i + "]:");
System.out.print(" x = " + resultPoint.getX());
System.out.print(", y = " + resultPoint.getY());
if (resultPoint instanceof FinderPattern)
System.out.print(", estimatedModuleSize = "
+ ((FinderPattern) resultPoint).getEstimatedModuleSize());
System.out.println();
}
I get this output:
text: Hello World!
resultPoints:
[0]: x = 36.5, y = 162.5, estimatedModuleSize = 9.0
[1]: x = 36.5, y = 36.5, estimatedModuleSize = 9.0
[2]: x = 162.5, y = 36.5, estimatedModuleSize = 9.0
x
and y
are the center coordinates of the square finder patterns.
Knowing that the QRCode finder patterns have size of 7x7 modules,
you can easily calculate the corner coordinates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With