首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Zxing +5补充条形码检测

Zxing +5补充条形码检测
EN

Stack Overflow用户
提问于 2014-01-09 19:51:06
回答 1查看 345关注 0票数 0

我一直试图使用Zxing2.3.0来读取UPC条形码的图片,并在java中添加了+5,但是我无法读取条形码的补充部分。代码只读取第一部分。在搜索多个网站后,除了我目前的方法之外,我找不到任何关于如何阅读补充信息的进一步指示。任何帮助都将不胜感激。

代码语言:javascript
复制
public static void main(String[] args) {
    decodeUPC5();
}

public static void decodeUPC5(){

    InputStream barCodeInputStream = null;
    try {
        barCodeInputStream = new FileInputStream("C:/Users/apoclyps/git/zxing-barcoder/Zxing-Test/img/upc5.png");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    BufferedImage barCodeBufferedImage = null;
    try {
        barCodeBufferedImage = ImageIO.read(barCodeInputStream);
    } catch (IOException e) {
        e.printStackTrace();
    }

    LuminanceSource source = new BufferedImageLuminanceSource(barCodeBufferedImage);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

    // Attempting to read UPC + 5 Supplement
    GenericMultipleBarcodeReader  multiReader = new GenericMultipleBarcodeReader(new MultiFormatReader());
    try {
        multiReader.decodeMultiple(bitmap);
    } catch (NotFoundException e1) {
        e1.printStackTrace();
    }
    Result[] result = null;
    try {
        result = multiReader.decodeMultiple(bitmap);
    } catch (NotFoundException e) {
        e.printStackTrace();
    }

    System.out.println("Results length "+result.length);
    for(Result r : result ){
        System.out.println("Barcode text is " + r.toString());
    }
}

条码图像

输出结果长度1条码文本为9780735200449

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-09 21:49:08

请记住,条形码的内容是9780735200449而不是9780735200449 51299。它将始终(正确)返回9780735200449作为条形码的内容。

+5扩展名以ResultMetadata的形式返回,位于ResultMetadatatype.UPC_EAN_EXTENSION键下。

请注意,它仍然将返回UPC条形码,即使它没有看到一个+5的扩展,很明显。因此,您可能会看到它在这个图像上没有+5扩展名而返回。不过,它对我适用于这个应用程序,因此可以想象它很容易检测到+5。(如果您使用该应用程序进行扫描,请查看左边的“元数据12.99美元”)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21029805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档