无法读取图像中的二维数据矩阵 [英] Not able to read 2D data matrix in Image

查看:44
本文介绍了无法读取图像中的二维数据矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have to read the 2D data matrix bar code from an Image. I am using zxing to read the barcode. This is the code i am using.

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"异常.任何人都可以帮助克服这个问题或提供替代解决方案来读取二维数据矩阵.

The problem is i am not getting the output for all the images. I have downloaded an image from net which is working fine. But for the actual input image i am getting the "com.google.zxing.NotFoundException" exception though it has the data. Can anyone help to overcome this problem or give alternate solution to read 2D Data Matrix.!

谢谢

图片:和

推荐答案

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

Its because the 2d matrix is not in the center of the extracted image. So i have resized the image using Image class then it worked.

这篇关于无法读取图像中的二维数据矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆