【问题标题】:Not able to read 2D data matrix in Image无法读取图像中的二维数据矩阵
【发布时间】:2019-09-25 17:26:08
【问题描述】:

我必须从图像中读取二维数据矩阵条码。我正在使用 zxing 读取条形码。这是我正在使用的代码。

import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.ChecksumException;
import com.google.zxing.FormatException;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.NotFoundException;
import com.google.zxing.Reader;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;

public class BarcodeGeneration {

    public static void main(String[] args) throws IOException {
        InputStream barCodeInputStream = new FileInputStream("file.jpg");  
        BufferedImage barCodeBufferedImage = ImageIO.read(barCodeInputStream);  
        LuminanceSource source = new BufferedImageLuminanceSource(barCodeBufferedImage);  
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));  
        Reader reader = new MultiFormatReader();  
        Result result;
        try {
            result = reader.decode(bitmap);
            System.out.println("Barcode text is " + result.getText());
        } catch (NotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ChecksumException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FormatException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  


    }

}

问题是我没有得到所有图像的输出。我从网上下载了一张工作正常的图片。但是对于实际的输入图像,我得到了“com.google.zxing.NotFoundException”异常,尽管它有数据。任何人都可以帮助克服这个问题或提供替代解决方案来读取 2D 数据矩阵。!

谢谢

图片:

【问题讨论】:

标签: zxing datamatrix


【解决方案1】:

这是因为二维矩阵不在提取图像的中心。所以我使用 Image 类调整了图像的大小然后它工作了。

【讨论】:

    猜你喜欢
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    • 2018-09-17
    • 2017-08-23
    相关资源
    最近更新 更多