com.google.zxing.LuminanceSource Java Examples
The following examples show how to use
com.google.zxing.LuminanceSource.
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: ZxingUtils.java From frpMgr with MIT License | 6 votes |
/** * 条形码解码 * * @param imgPath * @return String */ public static String decode(String imgPath) { BufferedImage image = null; Result result = null; try { image = ImageIO.read(new File(imgPath)); if (image == null) { System.out.println("the decode image may be not exit."); } LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); result = new MultiFormatReader().decode(bitmap, null); return result.getText(); } catch (Exception e) { e.printStackTrace(); } return null; }
Example #2
Source File: BufferedImageLuminanceSource.java From wechatGroupRobot with GNU General Public License v3.0 | 6 votes |
@Override public LuminanceSource rotateCounterClockwise() { int sourceWidth = image.getWidth(); int sourceHeight = image.getHeight(); // Rotate 90 degrees counterclockwise. AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0, 0.0, 0.0, sourceWidth); // Note width/height are flipped since we are rotating 90 degrees. BufferedImage rotatedImage = new BufferedImage(sourceHeight, sourceWidth, BufferedImage.TYPE_BYTE_GRAY); // Draw the original image into rotated, via transformation Graphics2D g = rotatedImage.createGraphics(); g.drawImage(image, transform, null); g.dispose(); // Maintain the cropped region, but rotate it too. int width = getWidth(); return new BufferedImageLuminanceSource(rotatedImage, top, sourceWidth - (left + width), getHeight(), width); }
Example #3
Source File: ZxingHandler.java From Shop-for-JavaWeb with MIT License | 6 votes |
/** * 二维码解码 * * @param imgPath * @return String */ public static String decode2(String imgPath) { BufferedImage image = null; Result result = null; try { image = ImageIO.read(new File(imgPath)); if (image == null) { System.out.println("the decode image may be not exit."); } LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(); hints.put(DecodeHintType.CHARACTER_SET, "GBK"); result = new MultiFormatReader().decode(bitmap, hints); return result.getText(); } catch (Exception e) { e.printStackTrace(); } return null; }
Example #4
Source File: ZxingHandler.java From Shop-for-JavaWeb with MIT License | 6 votes |
/** * 条形码解码 * * @param imgPath * @return String */ public static String decode(String imgPath) { BufferedImage image = null; Result result = null; try { image = ImageIO.read(new File(imgPath)); if (image == null) { System.out.println("the decode image may be not exit."); } LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); result = new MultiFormatReader().decode(bitmap, null); return result.getText(); } catch (Exception e) { e.printStackTrace(); } return null; }
Example #5
Source File: CameraPreview.java From Android-Barcode-Reader with MIT License | 6 votes |
@Override public void onPreviewFrame(byte[] data, Camera camera) { // TODO Auto-generated method stub if (mDialog.isShowing()) return; LuminanceSource source = new PlanarYUVLuminanceSource(data, mWidth, mHeight, mLeft, mTop, mAreaWidth, mAreaHeight, false); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer( source)); Result result; try { result = mMultiFormatReader.decode(bitmap, null); if (result != null) { mDialog.setTitle("Result"); mDialog.setMessage(result.getText()); mDialog.show(); } } catch (NotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example #6
Source File: QrCodeCreateUtil.java From java-study with Apache License 2.0 | 6 votes |
/** * 读二维码并输出携带的信息 */ public static void readQrCode(InputStream inputStream) throws IOException { //从输入流中获取字符串信息 BufferedImage image = ImageIO.read(inputStream); //将图像转换为二进制位图源 LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); QRCodeReader reader = new QRCodeReader(); Result result = null; try { result = reader.decode(bitmap); } catch (ReaderException e) { e.printStackTrace(); } System.out.println(result.getText()); }
Example #7
Source File: BufferedImageLuminanceSource.java From RipplePower with Apache License 2.0 | 5 votes |
@Override public LuminanceSource rotateCounterClockwise45() { int width = getWidth(); int height = getHeight(); int oldCenterX = left + width / 2; int oldCenterY = top + height / 2; // Rotate 45 degrees counterclockwise. AffineTransform transform = AffineTransform.getRotateInstance(MINUS_45_IN_RADIANS, oldCenterX, oldCenterY); int sourceDimension = Math.max(image.getWidth(), image.getHeight()); BufferedImage rotatedImage = new BufferedImage(sourceDimension, sourceDimension, BufferedImage.TYPE_BYTE_GRAY); // Draw the original image into rotated, via transformation Graphics2D g = rotatedImage.createGraphics(); g.drawImage(image, transform, null); g.dispose(); int halfDimension = Math.max(width, height) / 2; int newLeft = Math.max(0, oldCenterX - halfDimension); int newTop = Math.max(0, oldCenterY - halfDimension); int newRight = Math.min(sourceDimension - 1, oldCenterX + halfDimension); int newBottom = Math.min(sourceDimension - 1, oldCenterY + halfDimension); return new BufferedImageLuminanceSource(rotatedImage, newLeft, newTop, newRight - newLeft, newBottom - newTop); }
Example #8
Source File: GlobalHistogramBinarizer.java From QrCodeScanner with GNU General Public License v3.0 | 5 votes |
@Override public BitArray getBlackRow(int y, BitArray row) throws NotFoundException { LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); if (row == null || row.getSize() < width) { row = new BitArray(width); } else { row.clear(); } initArrays(width); byte[] localLuminances = source.getRow(y, luminances); int[] localBuckets = buckets; for (int x = 0; x < width; x++) { localBuckets[(localLuminances[x] & 0xff) >> LUMINANCE_SHIFT]++; } int blackPoint = estimateBlackPoint(localBuckets); if (width < 3) { // Special case for very small images for (int x = 0; x < width; x++) { if ((localLuminances[x] & 0xff) < blackPoint) { row.set(x); } } } else { int left = localLuminances[0] & 0xff; int center = localLuminances[1] & 0xff; for (int x = 1; x < width - 1; x++) { int right = localLuminances[x + 1] & 0xff; // A simple -1 4 -1 box filter with a weight of 2. if (((center * 4) - left - right) / 2 < blackPoint) { row.set(x); } left = center; center = right; } } return row; }
Example #9
Source File: HybridBinarizer.java From weex with Apache License 2.0 | 5 votes |
/** * Calculates the final BitMatrix once for all requests. This could be called once from the * constructor instead, but there are some advantages to doing it lazily, such as making * profiling easier, and not doing heavy lifting when callers don't expect it. */ @Override public BitMatrix getBlackMatrix() throws NotFoundException { if (matrix != null) { return matrix; } LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); int height = source.getHeight(); if (width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION) { byte[] luminances = source.getMatrix(); int subWidth = width >> BLOCK_SIZE_POWER; if ((width & BLOCK_SIZE_MASK) != 0) { subWidth++; } int subHeight = height >> BLOCK_SIZE_POWER; if ((height & BLOCK_SIZE_MASK) != 0) { subHeight++; } int[][] blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height); BitMatrix newMatrix = new BitMatrix(width, height); calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints, newMatrix); matrix = newMatrix; } else { // If the image is too small, fall back to the global histogram approach. matrix = super.getBlackMatrix(); } return matrix; }
Example #10
Source File: GlobalHistogramBinarizer.java From RipplePower with Apache License 2.0 | 5 votes |
@Override public BitArray getBlackRow(int y, BitArray row) throws NotFoundException { LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); if (row == null || row.getSize() < width) { row = new BitArray(width); } else { row.clear(); } initArrays(width); byte[] localLuminances = source.getRow(y, luminances); int[] localBuckets = buckets; for (int x = 0; x < width; x++) { int pixel = localLuminances[x] & 0xff; localBuckets[pixel >> LUMINANCE_SHIFT]++; } int blackPoint = estimateBlackPoint(localBuckets); int left = localLuminances[0] & 0xff; int center = localLuminances[1] & 0xff; for (int x = 1; x < width - 1; x++) { int right = localLuminances[x + 1] & 0xff; // A simple -1 4 -1 box filter with a weight of 2. int luminance = ((center * 4) - left - right) / 2; if (luminance < blackPoint) { row.set(x); } left = center; center = right; } return row; }
Example #11
Source File: QRcode.java From maven-framework-project with MIT License | 5 votes |
/** * 读取二维码 * @param file 二维码源 * @throws Exception */ private static void readCode(File file) throws Exception{ BufferedImage encodedBufferedImage = ImageIO.read(file) ; LuminanceSource source = new BufferedImageLuminanceSource(encodedBufferedImage); Result result = new QRCodeReader().decode(new BinaryBitmap(new HybridBinarizer(source))); System.out.println(result.getText()); }
Example #12
Source File: HybridBinarizer.java From barcodescanner-lib-aar with MIT License | 5 votes |
/** * Calculates the final BitMatrix once for all requests. This could be called once from the * constructor instead, but there are some advantages to doing it lazily, such as making * profiling easier, and not doing heavy lifting when callers don't expect it. */ @Override public BitMatrix getBlackMatrix() throws NotFoundException { if (matrix != null) { return matrix; } LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); int height = source.getHeight(); if (width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION) { byte[] luminances = source.getMatrix(); int subWidth = width >> BLOCK_SIZE_POWER; if ((width & BLOCK_SIZE_MASK) != 0) { subWidth++; } int subHeight = height >> BLOCK_SIZE_POWER; if ((height & BLOCK_SIZE_MASK) != 0) { subHeight++; } int[][] blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height); BitMatrix newMatrix = new BitMatrix(width, height); calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints, newMatrix); matrix = newMatrix; } else { // If the image is too small, fall back to the global histogram approach. matrix = super.getBlackMatrix(); } return matrix; }
Example #13
Source File: Utils.java From code-scanner with MIT License | 5 votes |
@Nullable public static Result decodeLuminanceSource(@NonNull final MultiFormatReader reader, @NonNull final LuminanceSource luminanceSource) throws ReaderException { try { return reader.decodeWithState(new BinaryBitmap(new HybridBinarizer(luminanceSource))); } catch (final NotFoundException e) { return reader.decodeWithState( new BinaryBitmap(new HybridBinarizer(luminanceSource.invert()))); } finally { reader.reset(); } }
Example #14
Source File: GlobalHistogramBinarizer.java From ScreenCapture with MIT License | 5 votes |
@Override public BitArray getBlackRow(int y, BitArray row) throws NotFoundException { LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); if (row == null || row.getSize() < width) { row = new BitArray(width); } else { row.clear(); } initArrays(width); byte[] localLuminances = source.getRow(y, luminances); int[] localBuckets = buckets; for (int x = 0; x < width; x++) { localBuckets[(localLuminances[x] & 0xff) >> LUMINANCE_SHIFT]++; } int blackPoint = estimateBlackPoint(localBuckets); if (width < 3) { // Special case for very small images for (int x = 0; x < width; x++) { if ((localLuminances[x] & 0xff) < blackPoint) { row.set(x); } } } else { int left = localLuminances[0] & 0xff; int center = localLuminances[1] & 0xff; for (int x = 1; x < width - 1; x++) { int right = localLuminances[x + 1] & 0xff; // A simple -1 4 -1 box filter with a weight of 2. if (((center * 4) - left - right) / 2 < blackPoint) { row.set(x); } left = center; center = right; } } return row; }
Example #15
Source File: HybridBinarizer.java From RipplePower with Apache License 2.0 | 5 votes |
/** * Calculates the final BitMatrix once for all requests. This could be * called once from the constructor instead, but there are some advantages * to doing it lazily, such as making profiling easier, and not doing heavy * lifting when callers don't expect it. */ @Override public BitMatrix getBlackMatrix() throws NotFoundException { if (matrix != null) { return matrix; } LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); int height = source.getHeight(); if (width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION) { byte[] luminances = source.getMatrix(); int subWidth = width >> BLOCK_SIZE_POWER; if ((width & BLOCK_SIZE_MASK) != 0) { subWidth++; } int subHeight = height >> BLOCK_SIZE_POWER; if ((height & BLOCK_SIZE_MASK) != 0) { subHeight++; } int[][] blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height); BitMatrix newMatrix = new BitMatrix(width, height); calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints, newMatrix); matrix = newMatrix; } else { // If the image is too small, fall back to the global histogram // approach. matrix = super.getBlackMatrix(); } return matrix; }
Example #16
Source File: HybridBinarizer.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * Calculates the final BitMatrix once for all requests. This could be called once from the * constructor instead, but there are some advantages to doing it lazily, such as making * profiling easier, and not doing heavy lifting when callers don't expect it. */ @Override public BitMatrix getBlackMatrix() throws NotFoundException { if (matrix != null) { return matrix; } LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); int height = source.getHeight(); if (width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION) { byte[] luminances = source.getMatrix(); int subWidth = width >> BLOCK_SIZE_POWER; if ((width & BLOCK_SIZE_MASK) != 0) { subWidth++; } int subHeight = height >> BLOCK_SIZE_POWER; if ((height & BLOCK_SIZE_MASK) != 0) { subHeight++; } int[][] blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height); BitMatrix newMatrix = new BitMatrix(width, height, 1); calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints, newMatrix); matrix = newMatrix; } else { // If the image is too small, fall back to the global histogram approach. matrix = super.getBlackMatrix(); } return matrix; }
Example #17
Source File: GlobalHistogramBinarizer.java From reacteu-app with MIT License | 5 votes |
@Override public BitArray getBlackRow(int y, BitArray row) throws NotFoundException { LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); if (row == null || row.getSize() < width) { row = new BitArray(width); } else { row.clear(); } initArrays(width); byte[] localLuminances = source.getRow(y, luminances); int[] localBuckets = buckets; for (int x = 0; x < width; x++) { int pixel = localLuminances[x] & 0xff; localBuckets[pixel >> LUMINANCE_SHIFT]++; } int blackPoint = estimateBlackPoint(localBuckets); int left = localLuminances[0] & 0xff; int center = localLuminances[1] & 0xff; for (int x = 1; x < width - 1; x++) { int right = localLuminances[x + 1] & 0xff; // A simple -1 4 -1 box filter with a weight of 2. int luminance = ((center << 2) - left - right) >> 1; if (luminance < blackPoint) { row.set(x); } left = center; center = right; } return row; }
Example #18
Source File: DecodeHandler.java From reacteu-app with MIT License | 5 votes |
private static Bitmap toBitmap(LuminanceSource source, int[] pixels) { int width = source.getWidth(); int height = source.getHeight(); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.setPixels(pixels, 0, width, 0, 0, width, height); return bitmap; }
Example #19
Source File: HybridBinarizer.java From QrCodeScanner with GNU General Public License v3.0 | 5 votes |
/** * Calculates the final BitMatrix once for all requests. This could be called once from the * constructor instead, but there are some advantages to doing it lazily, such as making * profiling easier, and not doing heavy lifting when callers don't expect it. */ @Override public BitMatrix getBlackMatrix() throws NotFoundException { if (matrix != null) { return matrix; } LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); int height = source.getHeight(); if (width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION) { byte[] luminances = source.getMatrix(); int subWidth = width >> BLOCK_SIZE_POWER; if ((width & BLOCK_SIZE_MASK) != 0) { subWidth++; } int subHeight = height >> BLOCK_SIZE_POWER; if ((height & BLOCK_SIZE_MASK) != 0) { subHeight++; } int[][] blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height); BitMatrix newMatrix = new BitMatrix(width, height); calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints, newMatrix); matrix = newMatrix; } else { // If the image is too small, fall back to the global histogram approach. matrix = super.getBlackMatrix(); } return matrix; }
Example #20
Source File: MainActivity.java From Aegis with GNU General Public License v3.0 | 5 votes |
private void onScanImageResult(Intent intent) { Uri inputFile = (intent.getData()); Bitmap bitmap; try { BitmapFactory.Options bmOptions = new BitmapFactory.Options(); try (InputStream inputStream = getContentResolver().openInputStream(inputFile)) { bitmap = BitmapFactory.decodeStream(inputStream, null, bmOptions); } int[] intArray = new int[bitmap.getWidth() * bitmap.getHeight()]; bitmap.getPixels(intArray, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight()); LuminanceSource source = new RGBLuminanceSource(bitmap.getWidth(), bitmap.getHeight(), intArray); BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source)); Reader reader = new MultiFormatReader(); Result result = reader.decode(binaryBitmap); GoogleAuthInfo info = GoogleAuthInfo.parseUri(result.getText()); VaultEntry entry = new VaultEntry(info); startEditEntryActivity(CODE_ADD_ENTRY, entry, true); } catch (NotFoundException | IOException | ChecksumException | FormatException | GoogleAuthInfoException e) { e.printStackTrace(); Dialogs.showErrorDialog(this, R.string.unable_to_read_qrcode, e); } }
Example #21
Source File: GlobalHistogramBinarizer.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
public BitArray getBlackRow(int i, BitArray bitarray) { int j = 1; LuminanceSource luminancesource = getLuminanceSource(); int k = luminancesource.getWidth(); byte abyte0[]; int ai[]; if (bitarray == null || bitarray.getSize() < k) { bitarray = new BitArray(k); } else { bitarray.clear(); } a(k); abyte0 = luminancesource.getRow(i, d); ai = e; for (int l = 0; l < k; l++) { int j2 = (0xff & abyte0[l]) >> 3; ai[j2] = 1 + ai[j2]; } int i1 = a(ai); int j1 = 0xff & abyte0[0]; int k1 = 0xff & abyte0[j]; int l1 = j1; while (j < k - 1) { int i2 = 0xff & abyte0[j + 1]; if ((k1 << 2) - l1 - i2 >> 1 < i1) { bitarray.set(j); } j++; l1 = k1; k1 = i2; } return bitarray; }
Example #22
Source File: HybridBinarizer.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
public BitMatrix getBlackMatrix() { if (e != null) { return e; } LuminanceSource luminancesource = getLuminanceSource(); if (luminancesource.getWidth() >= 40 && luminancesource.getHeight() >= 40) { byte abyte0[] = luminancesource.getMatrix(); int i = luminancesource.getWidth(); int j = luminancesource.getHeight(); int k = i >> 3; if ((i & 7) != 0) { k++; } int l = j >> 3; if ((j & 7) != 0) { l++; } int ai[][] = a(abyte0, k, l, i, j); BitMatrix bitmatrix = new BitMatrix(i, j); a(abyte0, k, l, i, j, ai, bitmatrix); e = bitmatrix; } else { e = super.getBlackMatrix(); } return e; }
Example #23
Source File: RxQrCode.java From RxQrCode with MIT License | 5 votes |
private static Observable<Result> resolve(LuminanceSource source, boolean failWhenNotFound) { BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); QRCodeReader reader = new QRCodeReader(); try { return Observable.just(reader.decode(bitmap, TRY_HARDER)); } catch (NotFoundException | ChecksumException | FormatException e) { if (failWhenNotFound) { return Observable.error(e); } } finally { reader.reset(); } return Observable.empty(); }
Example #24
Source File: QRCodeUtil.java From JavaWeb with Apache License 2.0 | 5 votes |
public LuminanceSource rotateCounterClockwise() { int sourceWidth = image.getWidth(); int sourceHeight = image.getHeight(); AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0, 0.0, 0.0, sourceWidth); BufferedImage rotatedImage = new BufferedImage(sourceHeight, sourceWidth, BufferedImage.TYPE_BYTE_GRAY); Graphics2D g = rotatedImage.createGraphics(); g.drawImage(image, transform, null); g.dispose(); int width = getWidth(); return new BufferedImageLuminanceSource(rotatedImage, top, sourceWidth - (left + width), getHeight(), width); }
Example #25
Source File: GlobalHistogramBinarizer.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
@Override public BitArray getBlackRow(int y, BitArray row) throws NotFoundException { LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); if (row == null || row.getSize() < width) { row = new BitArray(width); } else { row.clear(); } initArrays(width); byte[] localLuminances = source.getRow(y, luminances); int[] localBuckets = buckets; for (int x = 0; x < width; x++) { localBuckets[(localLuminances[x] & 0xff) >> LUMINANCE_SHIFT]++; } int blackPoint = estimateBlackPoint(localBuckets); if (width < 3) { // Special case for very small images for (int x = 0; x < width; x++) { if ((localLuminances[x] & 0xff) < blackPoint) { row.set(x); } } } else { int left = localLuminances[0] & 0xff; int center = localLuminances[1] & 0xff; for (int x = 1; x < width - 1; x++) { int right = localLuminances[x + 1] & 0xff; // A simple -1 4 -1 box filter with a weight of 2. if (((center * 4) - left - right) / 2 < blackPoint) { row.set(x); } left = center; center = right; } } return row; }
Example #26
Source File: GlobalHistogramBinarizer.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
public BitMatrix getBlackMatrix() { LuminanceSource luminancesource = getLuminanceSource(); int i = luminancesource.getWidth(); int j = luminancesource.getHeight(); BitMatrix bitmatrix = new BitMatrix(i, j); a(i); int ai[] = e; for (int k = 1; k < 5; k++) { byte abyte1[] = luminancesource.getRow((j * k) / 5, d); int l1 = (i << 2) / 5; for (int i2 = i / 5; i2 < l1; i2++) { int j2 = (0xff & abyte1[i2]) >> 3; ai[j2] = 1 + ai[j2]; } } int l = a(ai); byte abyte0[] = luminancesource.getMatrix(); for (int i1 = 0; i1 < j; i1++) { int j1 = i1 * i; for (int k1 = 0; k1 < i; k1++) { if ((0xff & abyte0[j1 + k1]) < l) { bitmatrix.set(k1, i1); } } } return bitmatrix; }
Example #27
Source File: ImageProcessor.java From Document-Scanner with GNU General Public License v3.0 | 5 votes |
public Result[] zxing( Mat inputImage ) throws ChecksumException, FormatException { int w = inputImage.width(); int h = inputImage.height(); Mat southEast; if (mBugRotate) { southEast = inputImage.submat(h-h/4 , h , 0 , w/2 - h/4 ); } else { southEast = inputImage.submat(0, h / 4, w / 2 + h / 4, w); } Bitmap bMap = Bitmap.createBitmap(southEast.width(), southEast.height(), Bitmap.Config.ARGB_8888); org.opencv.android.Utils.matToBitmap(southEast, bMap); southEast.release(); int[] intArray = new int[bMap.getWidth()*bMap.getHeight()]; //copy pixel data from the Bitmap into the 'intArray' array bMap.getPixels(intArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight()); LuminanceSource source = new RGBLuminanceSource(bMap.getWidth(), bMap.getHeight(),intArray); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); Result[] results = {}; try { results = qrCodeMultiReader.decodeMultiple(bitmap); } catch (NotFoundException ignored) { } return results; }
Example #28
Source File: HybridBinarizer.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 5 votes |
/** * Calculates the final BitMatrix once for all requests. This could be called once from the * constructor instead, but there are some advantages to doing it lazily, such as making * profiling easier, and not doing heavy lifting when callers don't expect it. */ @Override public BitMatrix getBlackMatrix() throws NotFoundException { if (matrix != null) { return matrix; } LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); int height = source.getHeight(); if (width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION) { byte[] luminances = source.getMatrix(); int subWidth = width >> BLOCK_SIZE_POWER; if ((width & BLOCK_SIZE_MASK) != 0) { subWidth++; } int subHeight = height >> BLOCK_SIZE_POWER; if ((height & BLOCK_SIZE_MASK) != 0) { subHeight++; } int[][] blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height); BitMatrix newMatrix = new BitMatrix(width, height); calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints, newMatrix); matrix = newMatrix; } else { // If the image is too small, fall back to the global histogram approach. matrix = super.getBlackMatrix(); } return matrix; }
Example #29
Source File: DecoderThread.java From Viewer with Apache License 2.0 | 5 votes |
protected LuminanceSource createSource(SourceData sourceData) { if (this.cropRect == null) { return null; } else { return sourceData.createSource(); } }
Example #30
Source File: GlobalHistogramBinarizer.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 5 votes |
@Override public BitArray getBlackRow(int y, BitArray row) throws NotFoundException { LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); if (row == null || row.getSize() < width) { row = new BitArray(width); } else { row.clear(); } initArrays(width); byte[] localLuminances = source.getRow(y, luminances); int[] localBuckets = buckets; for (int x = 0; x < width; x++) { int pixel = localLuminances[x] & 0xff; localBuckets[pixel >> LUMINANCE_SHIFT]++; } int blackPoint = estimateBlackPoint(localBuckets); int left = localLuminances[0] & 0xff; int center = localLuminances[1] & 0xff; for (int x = 1; x < width - 1; x++) { int right = localLuminances[x + 1] & 0xff; // A simple -1 4 -1 box filter with a weight of 2. int luminance = ((center * 4) - left - right) / 2; if (luminance < blackPoint) { row.set(x); } left = center; center = right; } return row; }