Search in sources :

Example 11 with GlobalHistogramBinarizer

use of com.google.zxing.common.GlobalHistogramBinarizer in project zxing by zxing.

the class RSSExpandedInternalTestCase method testRetrieveNextPairPatterns.

@Test
public void testRetrieveNextPairPatterns() throws Exception {
    BufferedImage image = readImage("3.png");
    BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
    int rowNumber = binaryMap.getHeight() / 2;
    BitArray row = binaryMap.getBlackRow(rowNumber, null);
    List<ExpandedPair> previousPairs = new ArrayList<>();
    RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
    ExpandedPair pair1 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
    previousPairs.add(pair1);
    FinderPattern finderPattern = pair1.getFinderPattern();
    assertNotNull(finderPattern);
    assertEquals(0, finderPattern.getValue());
    ExpandedPair pair2 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
    previousPairs.add(pair2);
    finderPattern = pair2.getFinderPattern();
    assertNotNull(finderPattern);
    assertEquals(0, finderPattern.getValue());
}
Also used : GlobalHistogramBinarizer(com.google.zxing.common.GlobalHistogramBinarizer) FinderPattern(com.google.zxing.oned.rss.FinderPattern) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) ArrayList(java.util.ArrayList) BitArray(com.google.zxing.common.BitArray) BinaryBitmap(com.google.zxing.BinaryBitmap) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Example 12 with GlobalHistogramBinarizer

use of com.google.zxing.common.GlobalHistogramBinarizer in project BGAQRCode-Android by bingoogolapple.

the class ZXingView method processData.

@Override
protected ScanResult processData(byte[] data, int width, int height, boolean isRetry) {
    Result rawResult = null;
    Rect scanBoxAreaRect = null;
    try {
        PlanarYUVLuminanceSource source;
        scanBoxAreaRect = mScanBoxView.getScanBoxAreaRect(height);
        if (scanBoxAreaRect != null) {
            source = new PlanarYUVLuminanceSource(data, width, height, scanBoxAreaRect.left, scanBoxAreaRect.top, scanBoxAreaRect.width(), scanBoxAreaRect.height(), false);
        } else {
            source = new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false);
        }
        rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new GlobalHistogramBinarizer(source)));
        if (rawResult == null) {
            rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(source)));
            if (rawResult != null) {
                BGAQRCodeUtil.d("GlobalHistogramBinarizer 没识别到,HybridBinarizer 能识别到");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        mMultiFormatReader.reset();
    }
    if (rawResult == null) {
        return null;
    }
    String result = rawResult.getText();
    if (TextUtils.isEmpty(result)) {
        return null;
    }
    BarcodeFormat barcodeFormat = rawResult.getBarcodeFormat();
    BGAQRCodeUtil.d("格式为:" + barcodeFormat.name());
    // 处理自动缩放和定位点
    boolean isNeedAutoZoom = isNeedAutoZoom(barcodeFormat);
    if (isShowLocationPoint() || isNeedAutoZoom) {
        ResultPoint[] resultPoints = rawResult.getResultPoints();
        final PointF[] pointArr = new PointF[resultPoints.length];
        int pointIndex = 0;
        for (ResultPoint resultPoint : resultPoints) {
            pointArr[pointIndex] = new PointF(resultPoint.getX(), resultPoint.getY());
            pointIndex++;
        }
        if (transformToViewCoordinates(pointArr, scanBoxAreaRect, isNeedAutoZoom, result)) {
            return null;
        }
    }
    return new ScanResult(result);
}
Also used : GlobalHistogramBinarizer(com.google.zxing.common.GlobalHistogramBinarizer) Rect(android.graphics.Rect) ScanResult(cn.bingoogolapple.qrcode.core.ScanResult) ResultPoint(com.google.zxing.ResultPoint) BarcodeFormat(com.google.zxing.BarcodeFormat) PointF(android.graphics.PointF) HybridBinarizer(com.google.zxing.common.HybridBinarizer) ResultPoint(com.google.zxing.ResultPoint) Result(com.google.zxing.Result) ScanResult(cn.bingoogolapple.qrcode.core.ScanResult) PlanarYUVLuminanceSource(com.google.zxing.PlanarYUVLuminanceSource) BinaryBitmap(com.google.zxing.BinaryBitmap)

Aggregations

GlobalHistogramBinarizer (com.google.zxing.common.GlobalHistogramBinarizer)12 BinaryBitmap (com.google.zxing.BinaryBitmap)11 BufferedImageLuminanceSource (com.google.zxing.BufferedImageLuminanceSource)8 BufferedImage (java.awt.image.BufferedImage)8 BitArray (com.google.zxing.common.BitArray)7 Result (com.google.zxing.Result)6 ReaderException (com.google.zxing.ReaderException)4 HybridBinarizer (com.google.zxing.common.HybridBinarizer)4 FinderPattern (com.google.zxing.oned.rss.FinderPattern)4 Test (org.junit.Test)4 MultiFormatReader (com.google.zxing.MultiFormatReader)3 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 LuminanceSource (com.google.zxing.LuminanceSource)2 DataCharacter (com.google.zxing.oned.rss.DataCharacter)2 PointF (android.graphics.PointF)1 Rect (android.graphics.Rect)1 ScanResult (cn.bingoogolapple.qrcode.core.ScanResult)1 BarcodeFormat (com.google.zxing.BarcodeFormat)1 ChecksumException (com.google.zxing.ChecksumException)1