com.google.zxing.common.GlobalHistogramBinarizer Java Examples

The following examples show how to use com.google.zxing.common.GlobalHistogramBinarizer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbsCodec.java    From StarBarcode with Apache License 2.0 6 votes vote down vote up
/**
 * 使用YUV解析bitmap
 *
 * @param data
 * @param width
 * @param height
 * @param hintTypeMap
 * @return
 */
private Result decodeFromYUV(int[] data, int width, int height, Map<DecodeHintType, ?> hintTypeMap) {
    Result result = null;
    byte[] yuv = convertRGBToYuv(data, new byte[width * height], width, height);
    PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(yuv, width, height, 0, 0, width, height, false);
    BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
    try {
        result = new MultiFormatReader().decode(binaryBitmap, hintTypeMap);
    } catch (NotFoundException e) {
        //使用GlobalHistogramBinarizer算法进行解析
        try {
            result = new MultiFormatReader().decode(new BinaryBitmap(new GlobalHistogramBinarizer(source)), hintTypeMap);
        } catch (NotFoundException e1) {
            e1.printStackTrace();
        }
    }
    return result;
}
 
Example #2
Source File: QrUtils.java    From Tesseract-OCR-Scanner with Apache License 2.0 5 votes vote down vote up
/**
 * Decode the data within the viewfinder rectangle, and time how long it took. For efficiency, reuse the same reader
 * objects from one decode to the next.
 */
public static Result decodeImage(byte[] data, int width, int height) {
    // 处理
    Result result = null;
    try {
        Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
        hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
        hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
        hints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
        PlanarYUVLuminanceSource source =
                new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false);
        /**
         * HybridBinarizer算法使用了更高级的算法,但使用GlobalHistogramBinarizer识别效率确实比HybridBinarizer要高一些。
         *
         * GlobalHistogram算法:(http://kuangjianwei.blog.163.com/blog/static/190088953201361015055110/)
         *
         * 二值化的关键就是定义出黑白的界限,我们的图像已经转化为了灰度图像,每个点都是由一个灰度值来表示,就需要定义出一个灰度值,大于这个值就为白(0),低于这个值就为黑(1)。
         * 在GlobalHistogramBinarizer中,是从图像中均匀取5行(覆盖整个图像高度),每行取中间五分之四作为样本;以灰度值为X轴,每个灰度值的像素个数为Y轴建立一个直方图,
         * 从直方图中取点数最多的一个灰度值,然后再去给其他的灰度值进行分数计算,按照点数乘以与最多点数灰度值的距离的平方来进行打分,选分数最高的一个灰度值。接下来在这两个灰度值中间选取一个区分界限,
         * 取的原则是尽量靠近中间并且要点数越少越好。界限有了以后就容易了,与整幅图像的每个点进行比较,如果灰度值比界限小的就是黑,在新的矩阵中将该点置1,其余的就是白,为0。
         */
        BinaryBitmap bitmap1 = new BinaryBitmap(new GlobalHistogramBinarizer(source));
        // BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
        QRCodeReader reader2 = new QRCodeReader();
        result = reader2.decode(bitmap1, hints);
    } catch (ReaderException e) {
    }
    return result;
}
 
Example #3
Source File: QrUtils.java    From Mobike with Apache License 2.0 5 votes vote down vote up
/**
 * Decode the data within the viewfinder rectangle, and time how long it took. For efficiency, reuse the same reader
 * objects from one decode to the next.
 */
public static Result decodeImage(byte[] data, int width, int height) {
    // 处理
    Result result = null;
    try {
        Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
        hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
        hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
        hints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
        PlanarYUVLuminanceSource source =
            new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false);
        /**
         * HybridBinarizer算法使用了更高级的算法,但使用GlobalHistogramBinarizer识别效率确实比HybridBinarizer要高一些。
         * 
         * GlobalHistogram算法:(http://kuangjianwei.blog.163.com/blog/static/190088953201361015055110/)
         * 
         * 二值化的关键就是定义出黑白的界限,我们的图像已经转化为了灰度图像,每个点都是由一个灰度值来表示,就需要定义出一个灰度值,大于这个值就为白(0),低于这个值就为黑(1)。
         * 在GlobalHistogramBinarizer中,是从图像中均匀取5行(覆盖整个图像高度),每行取中间五分之四作为样本;以灰度值为X轴,每个灰度值的像素个数为Y轴建立一个直方图,
         * 从直方图中取点数最多的一个灰度值,然后再去给其他的灰度值进行分数计算,按照点数乘以与最多点数灰度值的距离的平方来进行打分,选分数最高的一个灰度值。接下来在这两个灰度值中间选取一个区分界限,
         * 取的原则是尽量靠近中间并且要点数越少越好。界限有了以后就容易了,与整幅图像的每个点进行比较,如果灰度值比界限小的就是黑,在新的矩阵中将该点置1,其余的就是白,为0。
         */
        BinaryBitmap bitmap1 = new BinaryBitmap(new GlobalHistogramBinarizer(source));
        // BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
        QRCodeReader reader2 = new QRCodeReader();
        result = reader2.decode(bitmap1, hints);
    } catch (ReaderException e) {
    }
    return result;
}
 
Example #4
Source File: QrUtils.java    From QrCodeScanner with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Decode the data within the viewfinder rectangle, and time how long it took. For efficiency, reuse the same reader
 * objects from one decode to the next.
 */
public static Result decodeImage(byte[] data, int width, int height) {
    // 处理
    Result result = null;
    try {
        Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
        hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
        hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
        hints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
        PlanarYUVLuminanceSource source =
                new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false);
        /**
         * HybridBinarizer算法使用了更高级的算法,但使用GlobalHistogramBinarizer识别效率确实比HybridBinarizer要高一些。
         *
         * GlobalHistogram算法:(http://kuangjianwei.blog.163.com/blog/static/190088953201361015055110/)
         *
         * 二值化的关键就是定义出黑白的界限,我们的图像已经转化为了灰度图像,每个点都是由一个灰度值来表示,就需要定义出一个灰度值,大于这个值就为白(0),低于这个值就为黑(1)。
         * 在GlobalHistogramBinarizer中,是从图像中均匀取5行(覆盖整个图像高度),每行取中间五分之四作为样本;以灰度值为X轴,每个灰度值的像素个数为Y轴建立一个直方图,
         * 从直方图中取点数最多的一个灰度值,然后再去给其他的灰度值进行分数计算,按照点数乘以与最多点数灰度值的距离的平方来进行打分,选分数最高的一个灰度值。接下来在这两个灰度值中间选取一个区分界限,
         * 取的原则是尽量靠近中间并且要点数越少越好。界限有了以后就容易了,与整幅图像的每个点进行比较,如果灰度值比界限小的就是黑,在新的矩阵中将该点置1,其余的就是白,为0。
         */
        BinaryBitmap bitmap1 = new BinaryBitmap(new GlobalHistogramBinarizer(source));
        // BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
        QRCodeReader reader2 = new QRCodeReader();
        result = reader2.decode(bitmap1, hints);
    } catch (ReaderException e) {
    }
    return result;
}