无法使用Java中的Google Zxing从子图像获取条形码值

发布于 2025-02-13 19:02:28 字数 1053 浏览 1 评论 0原文

使用ZXing,我尝试从输入图像获取条形码值。我使用以下代码获取条形码值。

        BufferedImage img = ImageIO.read(new File("C:/Demo_Project/Project/input.jpeg"));
        BufferedImage subimage = img.getSubimage(350, 300, 600, 600); // Since few posts mentioned like if filesize exceeds Zxing not works properly. I get subimage of barcode part from actual image. 

        LuminanceSource source = new BufferedImageLuminanceSource(subimage);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
        Reader reader = new MultiFormatReader();
        Result result = reader.decode(bitmap);
        System.out.println("Barcode is ::"+result.getText());

低于例外,

com.google.zxing.notfoundexception。

任何修复或其他直接方法都可以从图像文件中获取条形码值。我的iamge文件实际上是在接近8MB的移动相机中获取的。获得子图像后,它变为4至10 kb,我的形象仍然无法正确识别。任何帮助将不胜感激。 当然,我已经验证了子图像包含条形码。请参阅附件。 “在此处输入图像描述”

Using Zxing I tried to get barcode value from input image. I used the below code for getting barcode value.

        BufferedImage img = ImageIO.read(new File("C:/Demo_Project/Project/input.jpeg"));
        BufferedImage subimage = img.getSubimage(350, 300, 600, 600); // Since few posts mentioned like if filesize exceeds Zxing not works properly. I get subimage of barcode part from actual image. 

        LuminanceSource source = new BufferedImageLuminanceSource(subimage);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
        Reader reader = new MultiFormatReader();
        Result result = reader.decode(bitmap);
        System.out.println("Barcode is ::"+result.getText());

Getting below exception,

com.google.zxing.NotFoundException .

Any fixes or other straight forward approaches to get barcode value from image files. My iamge files are actually taken in mobile camera which sizes close to 8MB. After getting subimage it become 4 to 10 KB still my image is not recognized properly. Any help would be appreciated.
Of course, I have verified the sub-image contains the barcode. Please see the attachment.enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文