使用 zxing 库从扫描的 PDF 中读取多个 QR 码时结果不一致
我是 zxing 库
的新手,也是 QR 码的新手。使用zxing库1.7
我生成了QR码,这些QR码被粘贴在论文上,然后将论文扫描成PDF格式。当然,我确实使用 zxing
库本身创建了客户端程序,该程序逐页读取此扫描的 PDF,并在页面上找到任何 QR 码时显示 QR 码文本。我正在尝试从扫描的 PDF 的每一页中读取多个 QR。
虽然我可以读取一些二维码,但结果不一致。意味着我能够读取 PDF 页面中的一些二维码,而其中一些二维码无法被我的客户端程序识别。我已经浏览同一主题的其他线程。并修改了我的代码,尽管我无法获得 100% 的结果。
这是我的代码片段,可以让您更多地了解我正在做什么。
注意:我使用itext PDF库的PdfReaderContentParser来提取每个pdf页面的扫描图像如图所示
private void extractBarcodeText(BufferedImage bufferedImage) {
try {
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.TRY_HARDER, BarcodeFormat.QR_CODE);
LuminanceSource source = new com.google.zxing.client.j2se.BufferedImageLuminanceSource(bufferedImage);
BinaryBitmap bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source));
List<String> innerTextList = new ArrayList<String>();
QRCodeMultiReader multiReader = new QRCodeMultiReader();
Result[] results = multiReader.decodeMultiple(bitmap, hints);
for (int k = 0; k < results.length; k++) {
String text = results[k].getText();
innerTextList.add(text);
System.out.println("#################### Rendered Text from Image #################"+ " " + text);
}
} catch (NotFoundException e) {
e.printStackTrace();
}
}
我尝试了很多组合但没有运气。是因为图像质量差吗?但是有些图像是如何被识别的,而有些图像仍然是个谜:(
有人知道我应该做什么来克服这个问题吗?这是一个 示例图像位于底部供您参考,其中第一张图像使用上面的代码得到识别,而第二张图像(HRA)则不能识别。!
I am new to zxing library
and so to QR Codes. Using zxing library 1.7
I have generated QR codes, those QR codes are sticked to the papers and papers are later scanned in a PDF. I do have created client program of course using zxing
library itself which reads this scanned PDF page by page and shows QR Code text if any QR Code is found on a page. I am trying to read multiple QR from each page of scanned PDF.
Though I am able to read some QR code the result is inconsistent. Means I am able to read some QR code in a PDF page while some of them are not getting recognized by my client program. I have gone through other threads for same topic. and modified my code a little though I am not able to get 100% result.
Here is my code snippet to give more idea about what I am exactly doing.
Note: I am using PdfReaderContentParser of itext PDF library to extract scanned image of each pdf page as shown here
private void extractBarcodeText(BufferedImage bufferedImage) {
try {
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.TRY_HARDER, BarcodeFormat.QR_CODE);
LuminanceSource source = new com.google.zxing.client.j2se.BufferedImageLuminanceSource(bufferedImage);
BinaryBitmap bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source));
List<String> innerTextList = new ArrayList<String>();
QRCodeMultiReader multiReader = new QRCodeMultiReader();
Result[] results = multiReader.decodeMultiple(bitmap, hints);
for (int k = 0; k < results.length; k++) {
String text = results[k].getText();
innerTextList.add(text);
System.out.println("#################### Rendered Text from Image #################"+ " " + text);
}
} catch (NotFoundException e) {
e.printStackTrace();
}
}
I have tried many combinations but no luck. Is it due to poor image quality ? But then how some images are getting recognized and some remains as a mystery :(
Do anyone know what should I do to overcome this issue? Here is one sample image at bottom for your reference, in that first image is getting recognized using above code where second one (HRA) is not.!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您所说的,我的猜测是您需要对图像进行轻微模糊或下采样。大量白噪声干扰检测。
My guess based on what you've said is that you need to lightly blur or down-sample the image. The large amount of white noise interferes with detection.