use of com.google.zxing.common.HybridBinarizer in project zxingfragmentlib by mitoyarzun.
the class DecodeHandler method decode.
/**
* 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.
*
* @param data The YUV preview frame.
* @param width The width of the preview frame.
* @param height The height of the preview frame.
*/
private void decode(byte[] data, int width, int height) {
long start = System.currentTimeMillis();
Result rawResult = null;
PlanarYUVLuminanceSource source = fragment.getCameraManager().buildLuminanceSource(data, width, height);
if (source != null) {
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
rawResult = multiFormatReader.decodeWithState(bitmap);
} catch (ReaderException re) {
// continue
} finally {
multiFormatReader.reset();
}
}
Handler handler = fragment.getHandler();
if (rawResult != null) {
// Don't log the barcode contents for security.
long end = System.currentTimeMillis();
Log.d(TAG, "Found barcode in " + (end - start) + " ms");
if (handler != null) {
Message message = Message.obtain(handler, IConstants.DECODE_SUCCEDED, rawResult);
Bundle bundle = new Bundle();
bundleThumbnail(source, bundle);
message.setData(bundle);
message.sendToTarget();
}
} else {
if (handler != null) {
Message message = Message.obtain(handler, IConstants.DECODE_FAILED);
message.sendToTarget();
}
}
}
use of com.google.zxing.common.HybridBinarizer in project titanium-barcode by mwaylabs.
the class DecodeThread method decode.
/**
* 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.
*
* @param data
* The YUV preview frame.
* @param width
* The width of the preview frame.
* @param height
* The height of the preview frame.
*/
private void decode(byte[] data, int width, int height) {
long start = System.currentTimeMillis();
Result rawResult = null;
PlanarYUVLuminanceSource source = CameraManager.get().buildLuminanceSource(data, width, height);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
rawResult = multiFormatReader.decodeWithState(bitmap);
} catch (ReaderException re) {
// Log and continue
Log.d("DecodeThread", re.toString());
} finally {
multiFormatReader.reset();
}
if (rawResult != null) {
long end = System.currentTimeMillis();
Log.v(TAG, "Found barcode (" + (end - start) + " ms):\n" + rawResult.toString());
Message message = Message.obtain(activity.getHandler(), Id.DECODE_SUCCEEDED, rawResult);
Bundle bundle = new Bundle();
bundle.putParcelable(BARCODE_BITMAP, source.renderCroppedGreyscaleBitmap());
message.setData(bundle);
message.sendToTarget();
} else {
Message message = Message.obtain(activity.getHandler(), Id.DECODE_FAILED);
message.sendToTarget();
}
}
use of com.google.zxing.common.HybridBinarizer in project QRCode by 5peak2me.
the class DecodeHandler method decode.
/**
* 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.
*
* @param data
* The YUV preview frame.
* @param width
* The width of the preview frame.
* @param height
* The height of the preview frame.
*/
private void decode(byte[] data, int width, int height) {
Size size = activity.getCameraManager().getPreviewSize();
// 这里需要将获取的data翻转一下,因为相机默认拿的的横屏的数据
byte[] rotatedData = new byte[data.length];
for (int y = 0; y < size.height; y++) {
for (int x = 0; x < size.width; x++) rotatedData[x * size.height + size.height - y - 1] = data[x + y * size.width];
}
// 宽高也要调整
int tmp = size.width;
size.width = size.height;
size.height = tmp;
Result rawResult = null;
PlanarYUVLuminanceSource source = buildLuminanceSource(rotatedData, size.width, size.height);
if (source != null) {
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
rawResult = multiFormatReader.decodeWithState(bitmap);
} catch (ReaderException re) {
// continue
} finally {
multiFormatReader.reset();
}
}
Handler handler = activity.getHandler();
if (rawResult != null) {
// Don't log the barcode contents for security.
if (handler != null) {
Message message = Message.obtain(handler, R.id.decode_succeeded, rawResult);
Bundle bundle = new Bundle();
bundleThumbnail(source, bundle);
message.setData(bundle);
message.sendToTarget();
}
} else {
if (handler != null) {
Message message = Message.obtain(handler, R.id.decode_failed);
message.sendToTarget();
}
}
}
use of com.google.zxing.common.HybridBinarizer in project zxing by zxing.
the class DecodeHandler method decode.
/**
* 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.
*
* @param data The YUV preview frame.
* @param width The width of the preview frame.
* @param height The height of the preview frame.
*/
private void decode(byte[] data, int width, int height) {
long start = System.currentTimeMillis();
Result rawResult = null;
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(data, width, height);
if (source != null) {
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
rawResult = multiFormatReader.decodeWithState(bitmap);
} catch (ReaderException re) {
// continue
} finally {
multiFormatReader.reset();
}
}
Handler handler = activity.getHandler();
if (rawResult != null) {
// Don't log the barcode contents for security.
long end = System.currentTimeMillis();
Log.d(TAG, "Found barcode in " + (end - start) + " ms");
if (handler != null) {
Message message = Message.obtain(handler, R.id.decode_succeeded, rawResult);
Bundle bundle = new Bundle();
bundleThumbnail(source, bundle);
message.setData(bundle);
message.sendToTarget();
}
} else {
if (handler != null) {
Message message = Message.obtain(handler, R.id.decode_failed);
message.sendToTarget();
}
}
}
use of com.google.zxing.common.HybridBinarizer in project zxing by zxing.
the class DecodeWorker method decode.
private Result[] decode(URI uri, Map<DecodeHintType, ?> hints) throws IOException {
BufferedImage image = ImageReader.readImage(uri);
LuminanceSource source;
if (config.crop == null) {
source = new BufferedImageLuminanceSource(image);
} else {
List<Integer> crop = config.crop;
source = new BufferedImageLuminanceSource(image, crop.get(0), crop.get(1), crop.get(2), crop.get(3));
}
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
if (config.dumpBlackPoint) {
dumpBlackPoint(uri, image, bitmap);
}
MultiFormatReader multiFormatReader = new MultiFormatReader();
Result[] results;
try {
if (config.multi) {
MultipleBarcodeReader reader = new GenericMultipleBarcodeReader(multiFormatReader);
results = reader.decodeMultiple(bitmap, hints);
} else {
results = new Result[] { multiFormatReader.decode(bitmap, hints) };
}
} catch (NotFoundException ignored) {
System.out.println(uri + ": No barcode found");
return null;
}
if (config.brief) {
System.out.println(uri + ": Success");
} else {
StringWriter output = new StringWriter();
for (Result result : results) {
ParsedResult parsedResult = ResultParser.parseResult(result);
output.write(uri + " (format: " + result.getBarcodeFormat() + ", type: " + parsedResult.getType() + "):\n" + "Raw result:\n" + result.getText() + "\n" + "Parsed result:\n" + parsedResult.getDisplayResult() + "\n");
output.write("Found " + result.getResultPoints().length + " result points.\n");
for (int pointIndex = 0; pointIndex < result.getResultPoints().length; pointIndex++) {
ResultPoint rp = result.getResultPoints()[pointIndex];
output.write(" Point " + pointIndex + ": (" + rp.getX() + ',' + rp.getY() + ')');
if (pointIndex != result.getResultPoints().length - 1) {
output.write('\n');
}
}
output.write('\n');
}
System.out.println(output);
}
return results;
}
Aggregations