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());
}
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);
}
Aggregations