Java 类com.google.zxing.BinaryBitmap 实例源码

项目:IJPay    文件:ZxingKit.java   
/**
 * @param srcImgFilePath
 *            要解码的图片地址
 * @return {Result}
 */
@SuppressWarnings("finally")
public static Result decode(String srcImgFilePath) {
    Result result = null;
    BufferedImage image;
    try {
        File srcFile = new File(srcImgFilePath);
        image = ImageIO.read(srcFile);
        if (null != image) {
            LuminanceSource source = new BufferedImageLuminanceSource(image);
            BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

            Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
            hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
            result = new MultiFormatReader().decode(bitmap, hints);
        } else {
            throw new IllegalArgumentException ("Could not decode image.");
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        return result;
    }
}
项目:framework    文件:BarCodeUtils.java   
/**
 * 条形码解码
 */
public static String decode(BufferedImage image) {
    Result result = null;
    try {
        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;
}
项目:framework    文件:QRCodeUtils.java   
/**
 * 解析二维码
 *
 * @param file 二维码图片
 * @return
 * @throws Exception
 */
public static String decode(File file) throws Exception {
    BufferedImage image;
    image = ImageIO.read(file);
    if (image == null) {
        return null;
    }
    BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(image);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    Result result;
    Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
    hints.put(DecodeHintType.CHARACTER_SET, CHARSET);
    result = new MultiFormatReader().decode(bitmap, hints);
    String resultStr = result.getText();
    return resultStr;
}
项目:MyFire    文件:BitmapDecoder.java   
/**
 * 获取解码结果
 * 
 * @param bitmap
 * @return
 */
public Result getRawResult(Bitmap bitmap) {
    if (bitmap == null) {
        return null;
    }

    try {
        return multiFormatReader.decodeWithState(new BinaryBitmap(
                new HybridBinarizer(new BitmapLuminanceSource(bitmap))));
    }
    catch (NotFoundException e) {
        e.printStackTrace();
    }

    return null;
}
项目:iBase4J-Common    文件:QrcodeUtil.java   
public static String decodeQr(String filePath) {
    String retStr = "";
    if ("".equalsIgnoreCase(filePath) && filePath.length() == 0) {
        return "图片路径为空!";
    }
    try {
        BufferedImage bufferedImage = ImageIO.read(new FileInputStream(filePath));
        LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
        Binarizer binarizer = new HybridBinarizer(source);
        BinaryBitmap bitmap = new BinaryBitmap(binarizer);
        HashMap<DecodeHintType, Object> hintTypeObjectHashMap = new HashMap<>();
        hintTypeObjectHashMap.put(DecodeHintType.CHARACTER_SET, "UTF-8");
        Result result = new MultiFormatReader().decode(bitmap, hintTypeObjectHashMap);
        retStr = result.getText();
    } catch (Exception e) {
        logger.error("", e);
    }
    return retStr;
}
项目:Hitalk    文件:QRCodeDecoder.java   
/**
 * 同步解析bitmap二维码。该方法是耗时操作,请在子线程中调用。
 *
 * @param bitmap 要解析的二维码图片
 * @return 返回二维码图片里的内容 或 null
 */
public static String syncDecodeQRCode(Bitmap bitmap) {
    try {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int[] pixels = new int[width * height];
        bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
        RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
        Result result = new MultiFormatReader().decode(new BinaryBitmap(new HybridBinarizer(source)), HINTS);
        return result.getText();
    } catch (Exception e) {
        return null;
    }
}
项目:automat    文件:QrcodeUtil.java   
public static String decodeQr(String filePath) {
    String retStr = "";
    if ("".equalsIgnoreCase(filePath) && filePath.length() == 0) {
        return "图片路径为空!";
    }
    try {
        BufferedImage bufferedImage = ImageIO.read(new FileInputStream(filePath));
        LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
        Binarizer binarizer = new HybridBinarizer(source);
        BinaryBitmap bitmap = new BinaryBitmap(binarizer);
        HashMap<DecodeHintType, Object> hintTypeObjectHashMap = new HashMap<>();
        hintTypeObjectHashMap.put(DecodeHintType.CHARACTER_SET, "UTF-8");
        Result result = new MultiFormatReader().decode(bitmap, hintTypeObjectHashMap);
        retStr = result.getText();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return retStr;
}
项目:weex-3d-map    文件:PDF417Reader.java   
private static Result[] decode(BinaryBitmap image, Map<DecodeHintType, ?> hints, boolean multiple) 
    throws NotFoundException, FormatException, ChecksumException {
  List<Result> results = new ArrayList<>();
  PDF417DetectorResult detectorResult = Detector.detect(image, hints, multiple);
  for (ResultPoint[] points : detectorResult.getPoints()) {
    DecoderResult decoderResult = PDF417ScanningDecoder.decode(detectorResult.getBits(), points[4], points[5],
        points[6], points[7], getMinCodewordWidth(points), getMaxCodewordWidth(points));
    Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.PDF_417);
    result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel());
    PDF417ResultMetadata pdf417ResultMetadata = (PDF417ResultMetadata) decoderResult.getOther();
    if (pdf417ResultMetadata != null) {
      result.putMetadata(ResultMetadataType.PDF417_EXTRA_METADATA, pdf417ResultMetadata);
    }
    results.add(result);
  }
  return results.toArray(new Result[results.size()]);
}
项目:weex-3d-map    文件:OneDReader.java   
@Override
public Result decode(BinaryBitmap image,
                     Map<DecodeHintType,?> hints) throws NotFoundException, FormatException {
  try {
    return doDecode(image, hints);
  } catch (NotFoundException nfe) {
    boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
    if (tryHarder && image.isRotateSupported()) {
      BinaryBitmap rotatedImage = image.rotateCounterClockwise();
      Result result = doDecode(rotatedImage, hints);
      // Record that we found it rotated 90 degrees CCW / 270 degrees CW
      Map<ResultMetadataType,?> metadata = result.getResultMetadata();
      int orientation = 270;
      if (metadata != null && metadata.containsKey(ResultMetadataType.ORIENTATION)) {
        // But if we found it reversed in doDecode(), add in that result here:
        orientation = (orientation +
            (Integer) metadata.get(ResultMetadataType.ORIENTATION)) % 360;
      }
      result.putMetadata(ResultMetadataType.ORIENTATION, orientation);
      // Update result points
      ResultPoint[] points = result.getResultPoints();
      if (points != null) {
        int height = rotatedImage.getHeight();
        for (int i = 0; i < points.length; i++) {
          points[i] = new ResultPoint(height - points[i].getY() - 1, points[i].getX());
        }
      }
      return result;
    } else {
      throw nfe;
    }
  }
}
项目:weex-3d-map    文件:MaxiCodeReader.java   
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
    throws NotFoundException, ChecksumException, FormatException {
  DecoderResult decoderResult;
  if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
    BitMatrix bits = extractPureBits(image.getBlackMatrix());
    decoderResult = decoder.decode(bits, hints);
  } else {
    throw NotFoundException.getNotFoundInstance();
  }

  ResultPoint[] points = NO_POINTS;
  Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.MAXICODE);

  String ecLevel = decoderResult.getECLevel();
  if (ecLevel != null) {
    result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
  }
  return result;
}
项目:ZxingForAndroid    文件:Decoder.java   
/**
 * Decode a binary bitmap.
 *
 * @param bitmap the binary bitmap
 * @return a Result or null
 */
protected Result decode(BinaryBitmap bitmap) {
    possibleResultPoints.clear();
    try {
        if (reader instanceof MultiFormatReader) {
            // Optimization - MultiFormatReader's normal decode() method is slow.
            return ((MultiFormatReader) reader).decodeWithState(bitmap);
        } else {
            return reader.decode(bitmap);
        }
    } catch (Exception e) {
        // Decode error, try again next frame
        return null;
    } finally {
        reader.reset();
    }
}
项目:androidscan    文件:DecodeUtils.java   
public String decodeWithZxing(byte[] data, int width, int height, Rect crop) {
    MultiFormatReader multiFormatReader = new MultiFormatReader();
    multiFormatReader.setHints(changeZXingDecodeDataMode());

    Result rawResult = null;
    PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height,
            crop.left, crop.top, crop.width(), crop.height(), false);

    if (source != null) {
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
        try {
            rawResult = multiFormatReader.decodeWithState(bitmap);
        } catch (ReaderException re) {
            // continue
        } finally {
            multiFormatReader.reset();
        }
    }

    return rawResult != null ? rawResult.getText() : null;
}
项目:androidscan    文件:DecodeUtils.java   
public String decodeWithZxing(Bitmap bitmap) {
    MultiFormatReader multiFormatReader = new MultiFormatReader();
    multiFormatReader.setHints(changeZXingDecodeDataMode());

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);

    Result rawResult = null;
    RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);

    if (source != null) {
        BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
        try {
            rawResult = multiFormatReader.decodeWithState(binaryBitmap);
        } catch (ReaderException re) {
            // continue
        } finally {
            multiFormatReader.reset();
        }
    }

    return rawResult != null ? rawResult.getText() : null;
}
项目:CommonFramework    文件:ImageUtils.java   
/**
 * 解析二维码图片工具类
 *
 * @param bitmap
 */
public static String analyzeBitmap(Bitmap bitmap) {
    MultiFormatReader multiFormatReader = new MultiFormatReader();

    // 解码的参数
    Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(2);
    // 可以解析的编码类型
    Vector<BarcodeFormat> decodeFormats = new Vector<BarcodeFormat>();
    if (decodeFormats == null || decodeFormats.isEmpty()) {
        decodeFormats = new Vector<BarcodeFormat>();

        // 这里设置可扫描的类型,我这里选择了都支持
        decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
        decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
        decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
    }
    hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
    // 设置继续的字符编码格式为UTF8
    hints.put(DecodeHintType.CHARACTER_SET, "UTF8");
    // 设置解析配置参数
    multiFormatReader.setHints(hints);

    // 开始对图像资源解码
    Result rawResult = null;
    try {
        rawResult = multiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(new BitmapLuminanceSource(bitmap))));
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (rawResult != null) {
        return rawResult.getText();
    } else {
        return "Failed";
    }
}
项目:Zxing    文件:CaptureActivity.java   
protected Result scanningImage(Uri path) {
    if (path == null || path.equals("")) {
        return null;
    }
    // DecodeHintType 和EncodeHintType
    Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
    hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); // 设置二维码内容的编码
    try {
        Bitmap scanBitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));

        RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap);
        BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
        QRCodeReader reader = new QRCodeReader();
        return reader.decode(bitmap1, hints);

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
项目:Fetax-AI    文件:CodeUtil.java   
public static String decode(File file) throws Exception {
    BufferedImage image;
    image = ImageIO.read(file);
    if (image == null) {
        return null;
    }
    CodeImage source = new CodeImage(
            image);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    Result result;
    Hashtable hints = new Hashtable();
    hints.put(DecodeHintType.CHARACTER_SET, CHARSET);
    result = new MultiFormatReader().decode(bitmap, hints);
    String resultStr = result.getText();
    return resultStr;
}
项目:Fetax-AI    文件:CodeUtil.java   
/**
* 解析条形码
*/
  public static String decodes(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;
  }
项目:JAVA-    文件:QrcodeUtil.java   
public static String decodeQr(String filePath) {
    String retStr = "";
    if ("".equalsIgnoreCase(filePath) && filePath.length() == 0) {
        return "图片路径为空!";
    }
    try {
        BufferedImage bufferedImage = ImageIO.read(new FileInputStream(filePath));
        LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
        Binarizer binarizer = new HybridBinarizer(source);
        BinaryBitmap bitmap = new BinaryBitmap(binarizer);
        HashMap<DecodeHintType, Object> hintTypeObjectHashMap = new HashMap<>();
        hintTypeObjectHashMap.put(DecodeHintType.CHARACTER_SET, "UTF-8");
        Result result = new MultiFormatReader().decode(bitmap, hintTypeObjectHashMap);
        retStr = result.getText();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return retStr;
}
项目:awe-awesomesky    文件:CodeUtil.java   
public static String decode(File file) throws Exception {
    BufferedImage image;
    image = ImageIO.read(file);
    if (image == null) {
        return null;
    }
    CodeImage source = new CodeImage(
            image);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    Result result;
    Hashtable hints = new Hashtable();
    hints.put(DecodeHintType.CHARACTER_SET, CHARSET);
    result = new MultiFormatReader().decode(bitmap, hints);
    String resultStr = result.getText();
    return resultStr;
}
项目:Mobike    文件:QrUtils.java   
public static Result decodeImage(final String path) {
        Bitmap bitmap = QrUtils.decodeSampledBitmapFromFile(path, 256, 256);
        // Google Photo 相册中选取云照片是会出现 Bitmap == null
        if (bitmap == null) return null;
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int[] pixels = new int[width * height];
        bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
//                RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
        PlanarYUVLuminanceSource source1 = new PlanarYUVLuminanceSource(getYUV420sp(width, height, bitmap), width, height, 0, 0, width, height, false);
        BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source1));
//                BinaryBitmap binaryBitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source1));
        HashMap<DecodeHintType, Object> hints = new HashMap<>();

        hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
        hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");

        try {
            return new MultiFormatReader().decode(binaryBitmap, hints);
        } catch (NotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
项目:boohee_v5.6    文件:PDF417Reader.java   
private static Result[] decode(BinaryBitmap image, Map<DecodeHintType, ?> hints, boolean
        multiple) throws NotFoundException, FormatException, ChecksumException {
    List<Result> results = new ArrayList();
    PDF417DetectorResult detectorResult = Detector.detect(image, hints, multiple);
    for (ResultPoint[] points : detectorResult.getPoints()) {
        DecoderResult decoderResult = PDF417ScanningDecoder.decode(detectorResult.getBits(),
                points[4], points[5], points[6], points[7], getMinCodewordWidth(points),
                getMaxCodewordWidth(points));
        Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(),
                points, BarcodeFormat.PDF_417);
        result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult
                .getECLevel());
        PDF417ResultMetadata pdf417ResultMetadata = (PDF417ResultMetadata) decoderResult
                .getOther();
        if (pdf417ResultMetadata != null) {
            result.putMetadata(ResultMetadataType.PDF417_EXTRA_METADATA, pdf417ResultMetadata);
        }
        results.add(result);
    }
    return (Result[]) results.toArray(new Result[results.size()]);
}
项目:boohee_v5.6    文件:DataMatrixReader.java   
public Result decode(BinaryBitmap image, Map<DecodeHintType, ?> hints) throws
        NotFoundException, ChecksumException, FormatException {
    DecoderResult decoderResult;
    ResultPoint[] points;
    if (hints == null || !hints.containsKey(DecodeHintType.PURE_BARCODE)) {
        DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect();
        decoderResult = this.decoder.decode(detectorResult.getBits());
        points = detectorResult.getPoints();
    } else {
        decoderResult = this.decoder.decode(extractPureBits(image.getBlackMatrix()));
        points = NO_POINTS;
    }
    Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points,
            BarcodeFormat.DATA_MATRIX);
    List<byte[]> byteSegments = decoderResult.getByteSegments();
    if (byteSegments != null) {
        result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
    }
    String ecLevel = decoderResult.getECLevel();
    if (ecLevel != null) {
        result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
    }
    return result;
}
项目:awe-awesomesky    文件:CodeUtil.java   
/**
* 解析条形码
*/
  public static String decodes(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;
  }
项目:angit    文件:ZxingHelper.java   
/**
 * 条形码解码
 *
 * @param imgPath 文件路径
 * @return String string
 */
public static String decode(String imgPath) {
    BufferedImage image;
    Result result;
    try {
        image = ImageIO.read(new File(imgPath));
        if (image == null) {
            LOGGER.error("the decode image may be not exit.");
            return null;
        }
        LuminanceSource source = new BufferedImageLuminanceSource(image);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

        result = new MultiFormatReader().decode(bitmap, null);
        return result.getText();
    } catch (Exception e) {
        LOGGER.error("条形码解析错误", e);
    }
    return null;
}
项目:angit    文件:ZxingHelper.java   
/**
 * 二维码解码
 *
 * @param imgPath 文件路径
 * @return String string
 */
public static String decode2(String imgPath) {
    BufferedImage image;
    Result result;
    try {
        image = ImageIO.read(new File(imgPath));
        if (image == null) {
            LOGGER.error("the decode image may be not exit.");
            return null;
        }
        LuminanceSource source = new BufferedImageLuminanceSource(image);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

        EnumMap<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
        hints.put(DecodeHintType.CHARACTER_SET, "GBK");

        result = new MultiFormatReader().decode(bitmap, hints);
        return result.getText();
    } catch (Exception e) {
        LOGGER.error("二维码解码错误", e);
    }
    return null;
}
项目:code-scanner    文件:DecodeTask.java   
@NonNull
@SuppressWarnings("SuspiciousNameCombination")
public Result decode(@NonNull MultiFormatReader reader) throws ReaderException {
    int imageWidth = mImageSize.getX();
    int imageHeight = mImageSize.getY();
    byte[] image;
    int width;
    int height;
    if (mOrientation == 0) {
        image = mImage;
        width = imageWidth;
        height = imageHeight;
    } else {
        image = Utils.rotateNV21(mImage, imageWidth, imageHeight, mOrientation);
        if (mOrientation == 90 || mOrientation == 270) {
            width = imageHeight;
            height = imageWidth;
        } else {
            width = imageWidth;
            height = imageHeight;
        }
    }
    Rect frameRect = Utils.getImageFrameRect(mSquareFrame, width, height, mPreviewSize, mViewSize);
    return reader.decodeWithState(new BinaryBitmap(new HybridBinarizer(
            new PlanarYUVLuminanceSource(image, width, height, frameRect.getLeft(), frameRect.getTop(),
                    frameRect.getWidth(), frameRect.getHeight(), mReverseHorizontal))));
}
项目:weex-3d-map    文件:PDF417Reader.java   
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException, FormatException,
    ChecksumException {
  Result[] result = decode(image, hints, false);
  if (result == null || result.length == 0 || result[0] == null) {
    throw NotFoundException.getNotFoundInstance();
  }
  return result[0];
}
项目:weex-3d-map    文件:PDF417Reader.java   
@Override
public Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException {
  try {
    return decode(image, hints, true);
  } catch (FormatException | ChecksumException ignored) {
    throw NotFoundException.getNotFoundInstance();
  }
}
项目:weex-3d-map    文件:QRCodeReader.java   
@Override
public final Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
    throws NotFoundException, ChecksumException, FormatException {
  DecoderResult decoderResult;
  ResultPoint[] points;
  if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
    BitMatrix bits = extractPureBits(image.getBlackMatrix());
    decoderResult = decoder.decode(bits, hints);
    points = NO_POINTS;
  } else {
    DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(hints);
    decoderResult = decoder.decode(detectorResult.getBits(), hints);
    points = detectorResult.getPoints();
  }

  // If the code was mirrored: swap the bottom-left and the top-right points.
  if (decoderResult.getOther() instanceof QRCodeDecoderMetaData) {
    ((QRCodeDecoderMetaData) decoderResult.getOther()).applyMirroredCorrection(points);
  }

  Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE);
  List<byte[]> byteSegments = decoderResult.getByteSegments();
  if (byteSegments != null) {
    result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
  }
  String ecLevel = decoderResult.getECLevel();
  if (ecLevel != null) {
    result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
  }
  if (decoderResult.hasStructuredAppend()) {
    result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE,
                       decoderResult.getStructuredAppendSequenceNumber());
    result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY,
                       decoderResult.getStructuredAppendParity());
  }
  return result;
}
项目:QRCodeScanner    文件:DecodeManger.java   
private Result decode(LuminanceSource source) {
    Result rawResult = null;
    if (source != null) {
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
        try {
            rawResult = multiFormatReader.decodeWithState(bitmap);
        } catch (ReaderException re) {
            //continue
        } finally {
            multiFormatReader.reset();
        }
    }
    return rawResult;
}
项目:weex-3d-map    文件:GenericMultipleBarcodeReader.java   
@Override
public Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints)
    throws NotFoundException {
  List<Result> results = new ArrayList<>();
  doDecodeMultiple(image, hints, results, 0, 0, 0);
  if (results.isEmpty()) {
    throw NotFoundException.getNotFoundInstance();
  }
  return results.toArray(new Result[results.size()]);
}
项目:Tesseract-OCR-Scanner    文件:QRCodeMultiReader.java   
@Override
public Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException {
  List<Result> results = new ArrayList<>();
  DetectorResult[] detectorResults = new MultiDetector(image.getBlackMatrix()).detectMulti(hints);
  for (DetectorResult detectorResult : detectorResults) {
    try {
      DecoderResult decoderResult = getDecoder().decode(detectorResult.getBits(), hints);
      ResultPoint[] points = detectorResult.getPoints();
      // If the code was mirrored: swap the bottom-left and the top-right points.
      if (decoderResult.getOther() instanceof QRCodeDecoderMetaData) {
        ((QRCodeDecoderMetaData) decoderResult.getOther()).applyMirroredCorrection(points);
      }
      Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points,
                                 BarcodeFormat.QR_CODE);
      List<byte[]> byteSegments = decoderResult.getByteSegments();
      if (byteSegments != null) {
        result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
      }
      String ecLevel = decoderResult.getECLevel();
      if (ecLevel != null) {
        result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
      }
      if (decoderResult.hasStructuredAppend()) {
        result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE,
                           decoderResult.getStructuredAppendSequenceNumber());
        result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY,
                           decoderResult.getStructuredAppendParity());
      }
      results.add(result);
    } catch (ReaderException re) {
      // ignore and continue 
    }
  }
  if (results.isEmpty()) {
    return EMPTY_RESULT_ARRAY;
  } else {
    results = processStructuredAppend(results);
    return results.toArray(new Result[results.size()]);
  }
}
项目:weex-3d-map    文件:QRCodeMultiReader.java   
@Override
public Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException {
  List<Result> results = new ArrayList<>();
  DetectorResult[] detectorResults = new MultiDetector(image.getBlackMatrix()).detectMulti(hints);
  for (DetectorResult detectorResult : detectorResults) {
    try {
      DecoderResult decoderResult = getDecoder().decode(detectorResult.getBits(), hints);
      ResultPoint[] points = detectorResult.getPoints();
      // If the code was mirrored: swap the bottom-left and the top-right points.
      if (decoderResult.getOther() instanceof QRCodeDecoderMetaData) {
        ((QRCodeDecoderMetaData) decoderResult.getOther()).applyMirroredCorrection(points);
      }
      Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points,
                                 BarcodeFormat.QR_CODE);
      List<byte[]> byteSegments = decoderResult.getByteSegments();
      if (byteSegments != null) {
        result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
      }
      String ecLevel = decoderResult.getECLevel();
      if (ecLevel != null) {
        result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
      }
      if (decoderResult.hasStructuredAppend()) {
        result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE,
                           decoderResult.getStructuredAppendSequenceNumber());
        result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY,
                           decoderResult.getStructuredAppendParity());
      }
      results.add(result);
    } catch (ReaderException re) {
      // ignore and continue 
    }
  }
  if (results.isEmpty()) {
    return EMPTY_RESULT_ARRAY;
  } else {
    results = processStructuredAppend(results);
    return results.toArray(new Result[results.size()]);
  }
}
项目:QrCode    文件:QRCodeReader.java   
@Override
public final Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
    throws NotFoundException, ChecksumException, FormatException {
  DecoderResult decoderResult;
  ResultPoint[] points;
  if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
    BitMatrix bits = extractPureBits(image.getBlackMatrix());
    decoderResult = decoder.decode(bits, hints);
    points = NO_POINTS;
  } else {
    DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(hints);
    decoderResult = decoder.decode(detectorResult.getBits(), hints);
    points = detectorResult.getPoints();
  }

  // If the code was mirrored: swap the bottom-left and the top-right points.
  if (decoderResult.getOther() instanceof QRCodeDecoderMetaData) {
    ((QRCodeDecoderMetaData) decoderResult.getOther()).applyMirroredCorrection(points);
  }

  Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE);
  List<byte[]> byteSegments = decoderResult.getByteSegments();
  if (byteSegments != null) {
    result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
  }
  String ecLevel = decoderResult.getECLevel();
  if (ecLevel != null) {
    result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
  }
  if (decoderResult.hasStructuredAppend()) {
    result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE,
                       decoderResult.getStructuredAppendSequenceNumber());
    result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY,
                       decoderResult.getStructuredAppendParity());
  }
  return result;
}
项目:QrCode    文件:OneDReader.java   
@Override
public Result decode(BinaryBitmap image,
                     Map<DecodeHintType,?> hints) throws NotFoundException, FormatException {
  try {
    return doDecode(image, hints);
  } catch (NotFoundException nfe) {
    boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
    if (tryHarder && image.isRotateSupported()) {
      BinaryBitmap rotatedImage = image.rotateCounterClockwise();
      Result result = doDecode(rotatedImage, hints);
      // Record that we found it rotated 90 degrees CCW / 270 degrees CW
      Map<ResultMetadataType,?> metadata = result.getResultMetadata();
      int orientation = 270;
      if (metadata != null && metadata.containsKey(ResultMetadataType.ORIENTATION)) {
        // But if we found it reversed in doDecode(), add in that result here:
        orientation = (orientation +
            (Integer) metadata.get(ResultMetadataType.ORIENTATION)) % 360;
      }
      result.putMetadata(ResultMetadataType.ORIENTATION, orientation);
      // Update result points
      ResultPoint[] points = result.getResultPoints();
      if (points != null) {
        int height = rotatedImage.getHeight();
        for (int i = 0; i < points.length; i++) {
          points[i] = new ResultPoint(height - points[i].getY() - 1, points[i].getX());
        }
      }
      return result;
    } else {
      throw nfe;
    }
  }
}
项目:QrCode    文件:GenericMultipleBarcodeReader.java   
@Override
public Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints)
    throws NotFoundException {
  List<Result> results = new ArrayList<>();
  doDecodeMultiple(image, hints, results, 0, 0, 0);
  if (results.isEmpty()) {
    throw NotFoundException.getNotFoundInstance();
  }
  return results.toArray(new Result[results.size()]);
}
项目:QrCode    文件:QRCodeMultiReader.java   
@Override
public Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException {
  List<Result> results = new ArrayList<>();
  DetectorResult[] detectorResults = new MultiDetector(image.getBlackMatrix()).detectMulti(hints);
  for (DetectorResult detectorResult : detectorResults) {
    try {
      DecoderResult decoderResult = getDecoder().decode(detectorResult.getBits(), hints);
      ResultPoint[] points = detectorResult.getPoints();
      // If the code was mirrored: swap the bottom-left and the top-right points.
      if (decoderResult.getOther() instanceof QRCodeDecoderMetaData) {
        ((QRCodeDecoderMetaData) decoderResult.getOther()).applyMirroredCorrection(points);
      }
      Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points,
                                 BarcodeFormat.QR_CODE);
      List<byte[]> byteSegments = decoderResult.getByteSegments();
      if (byteSegments != null) {
        result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
      }
      String ecLevel = decoderResult.getECLevel();
      if (ecLevel != null) {
        result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
      }
      if (decoderResult.hasStructuredAppend()) {
        result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE,
                           decoderResult.getStructuredAppendSequenceNumber());
        result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY,
                           decoderResult.getStructuredAppendParity());
      }
      results.add(result);
    } catch (ReaderException re) {
      // ignore and continue 
    }
  }
  if (results.isEmpty()) {
    return EMPTY_RESULT_ARRAY;
  } else {
    results = processStructuredAppend(results);
    return results.toArray(new Result[results.size()]);
  }
}
项目:boohee_v5.6    文件:Detector.java   
public static PDF417DetectorResult detect(BinaryBitmap image, Map<DecodeHintType, ?> map,
                                          boolean multiple) throws NotFoundException {
    BitMatrix bitMatrix = image.getBlackMatrix();
    List<ResultPoint[]> barcodeCoordinates = detect(multiple, bitMatrix);
    if (barcodeCoordinates.isEmpty()) {
        bitMatrix = bitMatrix.clone();
        bitMatrix.rotate180();
        barcodeCoordinates = detect(multiple, bitMatrix);
    }
    return new PDF417DetectorResult(bitMatrix, barcodeCoordinates);
}
项目:boohee_v5.6    文件:PDF417Reader.java   
public Result decode(BinaryBitmap image, Map<DecodeHintType, ?> hints) throws
        NotFoundException, FormatException, ChecksumException {
    Result[] result = decode(image, hints, false);
    if (result != null && result.length != 0 && result[0] != null) {
        return result[0];
    }
    throw NotFoundException.getNotFoundInstance();
}
项目:boohee_v5.6    文件:QRCodeReader.java   
public final Result decode(BinaryBitmap image, Map<DecodeHintType, ?> hints) throws
        NotFoundException, ChecksumException, FormatException {
    DecoderResult decoderResult;
    ResultPoint[] points;
    if (hints == null || !hints.containsKey(DecodeHintType.PURE_BARCODE)) {
        DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(hints);
        decoderResult = this.decoder.decode(detectorResult.getBits(), (Map) hints);
        points = detectorResult.getPoints();
    } else {
        decoderResult = this.decoder.decode(extractPureBits(image.getBlackMatrix()), (Map)
                hints);
        points = NO_POINTS;
    }
    if (decoderResult.getOther() instanceof QRCodeDecoderMetaData) {
        ((QRCodeDecoderMetaData) decoderResult.getOther()).applyMirroredCorrection(points);
    }
    Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points,
            BarcodeFormat.QR_CODE);
    List<byte[]> byteSegments = decoderResult.getByteSegments();
    if (byteSegments != null) {
        result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
    }
    String ecLevel = decoderResult.getECLevel();
    if (ecLevel != null) {
        result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
    }
    if (decoderResult.hasStructuredAppend()) {
        result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, Integer.valueOf
                (decoderResult.getStructuredAppendSequenceNumber()));
        result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY, Integer.valueOf
                (decoderResult.getStructuredAppendParity()));
    }
    return result;
}