-->

不能够在图像读取二维数据矩阵(Not able to read 2D data matrix in

2019-10-21 16:46发布

我已经从图像读出的2D数据矩阵条形码。 我使用斑马线读取条形码。 这是我使用的代码。

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”例外,虽然它的数据。 任何人都可以帮助解决这个问题或提供替代解决方案来读取二维数据矩阵!

谢谢

图片:

Answer 1:

其因为2D矩阵不是在所提取的图像的中心。 所以,我一直在使用图片类,那么它的工作调整图像。



文章来源: Not able to read 2D data matrix in Image