Java Code Examples for com.google.zxing.DecodeHintType

The following are top voted examples for showing how to use com.google.zxing.DecodeHintType. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: ZXingDemo   File: DecodeThread.java   View source code 8 votes vote down vote up
DecodeThread(CaptureActivity activity,
             Vector<BarcodeFormat> decodeFormats,
             String characterSet,
             ResultPointCallback resultPointCallback) {

  this.activity = activity;
  handlerInitLatch = new CountDownLatch(1);

  hints = new Hashtable<DecodeHintType, Object>(3);

  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);

  if (characterSet != null) {
    hints.put(DecodeHintType.CHARACTER_SET, characterSet);
  }

  hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
}
 
Example 2
Project: LeCatApp   File: DecodeThread.java   View source code 6 votes vote down vote up
DecodeThread(CaptureActivity activity,
                Collection<BarcodeFormat> decodeFormats, String characterSet,
                ResultPointCallback resultPointCallback) {

	this.activity = activity;
	handlerInitLatch = new CountDownLatch(1);

	hints = new Hashtable<DecodeHintType, Object>(3);

	if (decodeFormats == null || decodeFormats.isEmpty()) {
		decodeFormats = new Vector<BarcodeFormat>();
		decodeFormats.addAll(ONE_D_FORMATS);
		decodeFormats.addAll(QR_CODE_FORMATS);
		decodeFormats.addAll(DATA_MATRIX_FORMATS);
	}
	hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);

	if (characterSet != null) {
		hints.put(DecodeHintType.CHARACTER_SET, characterSet);
	}
	hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK,
			resultPointCallback);
	Log.i("DecodeThread", "Hints: " + hints);
}
 
Example 3
Project: GitHub   File: DecodeThread.java   View source code 6 votes vote down vote up
DecodeThread(CaptureActivity activity,
             Vector<BarcodeFormat> decodeFormats,
             String characterSet,
             ResultPointCallback resultPointCallback) {

  this.activity = activity;
  handlerInitLatch = new CountDownLatch(1);

  hints = new Hashtable<DecodeHintType, Object>(3);

  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);

  if (characterSet != null) {
    hints.put(DecodeHintType.CHARACTER_SET, characterSet);
  }

  hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
}
 
Example 4
Project: CodeScaner   File: CaptureActivityHandler.java   View source code 6 votes vote down vote up
CaptureActivityHandler(CaptureActivity activity,
                       Collection<BarcodeFormat> decodeFormats,
                       Map<DecodeHintType,?> baseHints,
                       String characterSet,
                       CameraManager cameraManager) {
  this.activity = activity;
  decodeThread = new DecodeThread(activity, decodeFormats, baseHints, characterSet,
          new ViewfinderResultPointCallback(activity.getViewfinderView()));
  decodeThread.start();
  state = State.SUCCESS;

  // Start ourselves capturing previews and decoding.
  this.cameraManager = cameraManager;
  cameraManager.startPreview();
  restartPreviewAndDecode();
}
 
Example 5
Project: BarcodeReaderView   File: BarcodeReaderHandler.java   View source code 6 votes vote down vote up
BarcodeReaderHandler(BarcodeReaderView barcodeReaderView,
                     Collection<BarcodeFormat> decodeFormats,
                     Map<DecodeHintType, ?> baseHints,
                     String characterSet,
                     ResultPointCallback resultPointCallback,
                     CameraManager cameraManager) {
    this.barcodeReaderView = barcodeReaderView;
    decodeThread = new DecodeThread(barcodeReaderView, decodeFormats, baseHints, characterSet, resultPointCallback);
    decodeThread.start();
    state = State.SUCCESS;

    // Start ourselves capturing previews and decoding.
    this.cameraManager = cameraManager;
    cameraManager.startPreview();
    restartPreviewAndDecode();
}
 
Example 6
Project: iBase4J-Common   File: QrcodeUtil.java   View source code 6 votes vote down vote up
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;
}
 
Example 7
Project: boohee_v5.6   File: DecodedBitStreamParser.java   View source code 6 votes vote down vote up
private static void decodeByteSegment(BitSource bits, StringBuilder result, int count,
                                      CharacterSetECI currentCharacterSetECI,
                                      Collection<byte[]> byteSegments, Map<DecodeHintType, ?>
                                              hints) throws FormatException {
    if (count * 8 > bits.available()) {
        throw FormatException.getFormatInstance();
    }
    String encoding;
    byte[] readBytes = new byte[count];
    for (int i = 0; i < count; i++) {
        readBytes[i] = (byte) bits.readBits(8);
    }
    if (currentCharacterSetECI == null) {
        encoding = StringUtils.guessEncoding(readBytes, hints);
    } else {
        encoding = currentCharacterSetECI.name();
    }
    try {
        result.append(new String(readBytes, encoding));
        byteSegments.add(readBytes);
    } catch (UnsupportedEncodingException e) {
        throw FormatException.getFormatInstance();
    }
}
 
Example 8
Project: ZXingAndroidExt   File: CaptureActivityHandler.java   View source code 6 votes vote down vote up
CaptureActivityHandler(QrCodeScannerActivity activity,
                       Collection<BarcodeFormat> decodeFormats,
                       Map<DecodeHintType, ?> baseHints,
                       String characterSet,
                       CameraManager cameraManager) {
    this.activity = activity;
    decodeThread = new DecodeThread(activity, decodeFormats, baseHints, characterSet,
            new ViewfinderResultPointCallback(activity.getViewfinderView()));
    decodeThread.start();
    state = State.SUCCESS;

    // Start ourselves capturing previews and decoding.
    this.cameraManager = cameraManager;
    cameraManager.startPreview();
    restartPreviewAndDecode();
}
 
Example 9
Project: Tesseract-OCR-Scanner   File: RSS14Reader.java   View source code 6 votes vote down vote up
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) {
  try {
    int[] startEnd = findFinderPattern(row, right);
    FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);

    ResultPointCallback resultPointCallback = hints == null ? null :
      (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);

    if (resultPointCallback != null) {
      float center = (startEnd[0] + startEnd[1]) / 2.0f;
      if (right) {
        // row is actually reversed
        center = row.getSize() - 1 - center;
      }
      resultPointCallback.foundPossibleResultPoint(new ResultPoint(center, rowNumber));
    }

    DataCharacter outside = decodeDataCharacter(row, pattern, true);
    DataCharacter inside = decodeDataCharacter(row, pattern, false);
    return new Pair(1597 * outside.getValue() + inside.getValue(),
                    outside.getChecksumPortion() + 4 * inside.getChecksumPortion(),
                    pattern);
  } catch (NotFoundException ignored) {
    return null;
  }
}
 
Example 10
Project: CommonFramework   File: ImageUtils.java   View source code 6 votes vote down vote up
/**
 * 解析二维码图片工具类
 *
 * @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";
    }
}
 
Example 11
Project: weex-3d-map   File: MultiFormatUPCEANReader.java   View source code 6 votes vote down vote up
public MultiFormatUPCEANReader(Map<DecodeHintType,?> hints) {
  @SuppressWarnings("unchecked")
  Collection<BarcodeFormat> possibleFormats = hints == null ? null :
      (Collection<BarcodeFormat>) hints.get(DecodeHintType.POSSIBLE_FORMATS);
  Collection<UPCEANReader> readers = new ArrayList<>();
  if (possibleFormats != null) {
    if (possibleFormats.contains(BarcodeFormat.EAN_13)) {
      readers.add(new EAN13Reader());
    } else if (possibleFormats.contains(BarcodeFormat.UPC_A)) {
      readers.add(new UPCAReader());
    }
    if (possibleFormats.contains(BarcodeFormat.EAN_8)) {
      readers.add(new EAN8Reader());
    }
    if (possibleFormats.contains(BarcodeFormat.UPC_E)) {
      readers.add(new UPCEReader());
    }
  }
  if (readers.isEmpty()) {
    readers.add(new EAN13Reader());
    // UPC-A is covered by EAN-13
    readers.add(new EAN8Reader());
    readers.add(new UPCEReader());
  }
  this.readers = readers.toArray(new UPCEANReader[readers.size()]);
}
 
Example 12
Project: weex-3d-map   File: RSS14Reader.java   View source code 6 votes vote down vote up
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) {
  try {
    int[] startEnd = findFinderPattern(row, 0, right);
    FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);

    ResultPointCallback resultPointCallback = hints == null ? null :
      (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);

    if (resultPointCallback != null) {
      float center = (startEnd[0] + startEnd[1]) / 2.0f;
      if (right) {
        // row is actually reversed
        center = row.getSize() - 1 - center;
      }
      resultPointCallback.foundPossibleResultPoint(new ResultPoint(center, rowNumber));
    }

    DataCharacter outside = decodeDataCharacter(row, pattern, true);
    DataCharacter inside = decodeDataCharacter(row, pattern, false);
    return new Pair(1597 * outside.getValue() + inside.getValue(),
                    outside.getChecksumPortion() + 4 * inside.getChecksumPortion(),
                    pattern);
  } catch (NotFoundException ignored) {
    return null;
  }
}
 
Example 13
Project: weex-3d-map   File: CaptureActivityHandler.java   View source code 6 votes vote down vote up
CaptureActivityHandler(CaptureActivity activity,
                       Collection<BarcodeFormat> decodeFormats,
                       Map<DecodeHintType,?> baseHints,
                       String characterSet,
                       CameraManager cameraManager) {
  this.activity = activity;
  decodeThread = new DecodeThread(activity, decodeFormats, baseHints, characterSet,
      new ViewfinderResultPointCallback(activity.getViewfinderView()));
  decodeThread.start();
  state = State.SUCCESS;

  // Start ourselves capturing previews and decoding.
  this.cameraManager = cameraManager;
  cameraManager.startPreview();
  restartPreviewAndDecode();
}
 
Example 14
Project: JAVA-   File: QrcodeUtil.java   View source code 6 votes vote down vote up
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;
}
 
Example 15
Project: weex-3d-map   File: DataMatrixReader.java   View source code 6 votes vote down vote up
@Override
public 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);
    points = NO_POINTS;
  } else {
    DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect();
    decoderResult = decoder.decode(detectorResult.getBits());
    points = detectorResult.getPoints();
  }
  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;
}
 
Example 16
Project: weex-3d-map   File: MultiDetector.java   View source code 6 votes vote down vote up
public DetectorResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException {
  BitMatrix image = getImage();
  ResultPointCallback resultPointCallback =
      hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
  MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback);
  FinderPatternInfo[] infos = finder.findMulti(hints);

  if (infos.length == 0) {
    throw NotFoundException.getNotFoundInstance();
  }

  List<DetectorResult> result = new ArrayList<>();
  for (FinderPatternInfo info : infos) {
    try {
      result.add(processFinderPatternInfo(info));
    } catch (ReaderException e) {
      // ignore
    }
  }
  if (result.isEmpty()) {
    return EMPTY_DETECTOR_RESULTS;
  } else {
    return result.toArray(new DetectorResult[result.size()]);
  }
}
 
Example 17
Project: ZxingForAndroid   File: DefaultDecoderFactory.java   View source code 6 votes vote down vote up
@Override
public Decoder createDecoder(Map<DecodeHintType, ?> baseHints) {
    Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);

    hints.putAll(baseHints);

    if(this.hints != null) {
        hints.putAll(this.hints);
    }

    if(this.decodeFormats != null) {
        hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
    }

    if (characterSet != null) {
        hints.put(DecodeHintType.CHARACTER_SET, characterSet);
    }

    MultiFormatReader reader = new MultiFormatReader();
    reader.setHints(hints);

    return inverted ? new InvertedDecoder(reader) : new Decoder(reader);

}
 
Example 18
Project: ZxingScan   File: DecodeThread.java   View source code 6 votes vote down vote up
DecodeThread(CaptureFragment fragment,
             Vector<BarcodeFormat> decodeFormats,
             String characterSet,
             ResultPointCallback resultPointCallback) {

    this.fragment = fragment;
    handlerInitLatch = new CountDownLatch(1);

    hints = new Hashtable<DecodeHintType, Object>(3);

    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);

    if (characterSet != null) {
        hints.put(DecodeHintType.CHARACTER_SET, characterSet);
    }

    hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
}
 
Example 19
Project: react-native-camera   File: RCTCameraViewFinder.java   View source code 6 votes vote down vote up
/**
 * Initialize the barcode decoder.
 */
private void initBarcodeReader(List<String> barCodeTypes) {
    EnumMap<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
    EnumSet<BarcodeFormat> decodeFormats = EnumSet.noneOf(BarcodeFormat.class);

    if (barCodeTypes != null) {
        for (String code : barCodeTypes) {
            BarcodeFormat format = parseBarCodeString(code);
            if (format != null) {
                decodeFormats.add(format);
            }
        }
    }

    hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
    _multiFormatReader.setHints(hints);
}
 
Example 20
Project: QrCode   File: CaptureHandler.java   View source code 6 votes vote down vote up
CaptureHandler(IScanCallback iScanCallback,
               Collection<BarcodeFormat> decodeFormats,
               Map<DecodeHintType, ?> baseHints,
               String characterSet,
               CameraManager cameraManager) {
    this.mIScanCallback = iScanCallback;
    decodeThread = new DecodeThread(iScanCallback, decodeFormats, baseHints, characterSet,
            new ViewfinderResultPointCallback((ViewfinderView) mIScanCallback.getViewfinderView()));
    decodeThread.start();
    state = State.SUCCESS;

    // Start ourselves capturing previews and decoding.
    this.cameraManager = cameraManager;
    cameraManager.startPreview();
    restartPreviewAndDecode();
}
 
Example 21
Project: QrCode   File: MultiFormatUPCEANReader.java   View source code 6 votes vote down vote up
public MultiFormatUPCEANReader(Map<DecodeHintType,?> hints) {
  @SuppressWarnings("unchecked")
  Collection<BarcodeFormat> possibleFormats = hints == null ? null :
      (Collection<BarcodeFormat>) hints.get(DecodeHintType.POSSIBLE_FORMATS);
  Collection<UPCEANReader> readers = new ArrayList<>();
  if (possibleFormats != null) {
    if (possibleFormats.contains(BarcodeFormat.EAN_13)) {
      readers.add(new EAN13Reader());
    } else if (possibleFormats.contains(BarcodeFormat.UPC_A)) {
      readers.add(new UPCAReader());
    }
    if (possibleFormats.contains(BarcodeFormat.EAN_8)) {
      readers.add(new EAN8Reader());
    }
    if (possibleFormats.contains(BarcodeFormat.UPC_E)) {
      readers.add(new UPCEReader());
    }
  }
  if (readers.isEmpty()) {
    readers.add(new EAN13Reader());
    // UPC-A is covered by EAN-13
    readers.add(new EAN8Reader());
    readers.add(new UPCEReader());
  }
  this.readers = readers.toArray(new UPCEANReader[readers.size()]);
}
 
Example 22
Project: Tesseract-OCR-Scanner   File: RSSExpandedReader.java   View source code 6 votes vote down vote up
@Override
public Result decodeRow(int rowNumber,
                        BitArray row,
                        Map<DecodeHintType,?> hints) throws NotFoundException, FormatException {
  // Rows can start with even pattern in case in prev rows there where odd number of patters.
  // So lets try twice
  this.pairs.clear();
  this.startFromEven = false;
  try {
    return constructResult(decodeRow2pairs(rowNumber, row));
  } catch (NotFoundException e) {
    // OK
  }

  this.pairs.clear();
  this.startFromEven = true;
  return constructResult(decodeRow2pairs(rowNumber, row));
}
 
Example 23
Project: QrCode   File: RSSExpandedReader.java   View source code 6 votes vote down vote up
@Override
public Result decodeRow(int rowNumber,
                        BitArray row,
                        Map<DecodeHintType,?> hints) throws NotFoundException, FormatException {
  // Rows can start with even pattern in case in prev rows there where odd number of patters.
  // So lets try twice
  this.pairs.clear();
  this.startFromEven = false;
  try {
    return constructResult(decodeRow2pairs(rowNumber, row));
  } catch (NotFoundException e) {
    // OK
  }

  this.pairs.clear();
  this.startFromEven = true;
  return constructResult(decodeRow2pairs(rowNumber, row));
}
 
Example 24
Project: MeiLa_GNN   File: DecodeThread.java   View source code 6 votes vote down vote up
DecodeThread(CaptureFragment fragment,
             Vector<BarcodeFormat> decodeFormats,
             String characterSet,
             ResultPointCallback resultPointCallback) {

    this.fragment = fragment;
    handlerInitLatch = new CountDownLatch(1);

    hints = new Hashtable<DecodeHintType, Object>(3);

    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);

    if (characterSet != null) {
        hints.put(DecodeHintType.CHARACTER_SET, characterSet);
    }

    hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
}
 
Example 25
Project: Zxing-Custom   File: CaptureActivityHandler.java   View source code 6 votes vote down vote up
public CaptureActivityHandler(CaptureActivityInterface activity,
                              Collection<BarcodeFormat> decodeFormats,
                              Map<DecodeHintType, ?> baseHints,
                              String characterSet,
                              CameraManager cameraManager) {
  this.activity = activity;
  decodeThread = new DecodeThread(activity, decodeFormats, baseHints, characterSet,
      new ViewfinderResultPointCallback(activity.getViewfinderView()));
  decodeThread.start();
  state = State.SUCCESS;

  // Start ourselves capturing previews and decoding.
  this.cameraManager = cameraManager;
  cameraManager.startPreview();
  restartPreviewAndDecode();
}
 
Example 26
Project: Espresso   File: DecodeThread.java   View source code 5 votes vote down vote up
public DecodeThread(CaptureActivity activity, int decodeMode) {

		this.activity = activity;
		handlerInitLatch = new CountDownLatch(1);

		hints = new EnumMap<DecodeHintType, Object>(DecodeHintType.class);

		Collection<BarcodeFormat> decodeFormats = new ArrayList<BarcodeFormat>();
		decodeFormats.addAll(EnumSet.of(BarcodeFormat.AZTEC));
		decodeFormats.addAll(EnumSet.of(BarcodeFormat.PDF_417));

		switch (decodeMode) {
		case BARCODE_MODE:
			decodeFormats.addAll(DecodeFormatManager.getBarCodeFormats());
			break;

		case QRCODE_MODE:
			decodeFormats.addAll(DecodeFormatManager.getQrCodeFormats());
			break;

		case ALL_MODE:
			decodeFormats.addAll(DecodeFormatManager.getBarCodeFormats());
			decodeFormats.addAll(DecodeFormatManager.getQrCodeFormats());
			break;

		default:
			break;
		}

		hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
	}
 
Example 27
Project: keepass2android   File: DecodeThread.java   View source code 5 votes vote down vote up
DecodeThread(CaptureActivity activity,
             Collection<BarcodeFormat> decodeFormats,
             Map<DecodeHintType,?> baseHints,
             String characterSet,
             ResultPointCallback resultPointCallback) {

  this.activity = activity;
  handlerInitLatch = new CountDownLatch(1);

  hints = new EnumMap<DecodeHintType,Object>(DecodeHintType.class);
  if (baseHints != null) {
    hints.putAll(baseHints);
  }

  // The prefs can't change while the thread is running, so pick them up once here.
  if (decodeFormats == null || decodeFormats.isEmpty()) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
    decodeFormats = EnumSet.noneOf(BarcodeFormat.class);
    if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_1D, false)) {
      decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
    }
    if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_QR, false)) {
      decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
    }
    if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_DATA_MATRIX, false)) {
      decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
    }
  }
  hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);

  if (characterSet != null) {
    hints.put(DecodeHintType.CHARACTER_SET, characterSet);
  }
  hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
  Log.i("DecodeThread", "Hints: " + hints);
}
 
Example 28
Project: Tesseract-OCR-Scanner   File: UPCAReader.java   View source code 5 votes vote down vote up
@Override
public Result decodeRow(int rowNumber,
                        BitArray row,
                        int[] startGuardRange,
                        Map<DecodeHintType,?> hints)
    throws NotFoundException, FormatException, ChecksumException {
  return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange, hints));
}
 
Example 29
Project: CodeScaner   File: DecodeHintManager.java   View source code 5 votes vote down vote up
static Map<DecodeHintType, Object> parseDecodeHints(Intent intent) {
  Bundle extras = intent.getExtras();
  if (extras == null || extras.isEmpty()) {
    return null;
  }
  Map<DecodeHintType,Object> hints = new EnumMap<>(DecodeHintType.class);

  for (DecodeHintType hintType: DecodeHintType.values()) {

    if (hintType == DecodeHintType.CHARACTER_SET ||
        hintType == DecodeHintType.NEED_RESULT_POINT_CALLBACK ||
        hintType == DecodeHintType.POSSIBLE_FORMATS) {
      continue; // This hint is specified in another way
    }

    String hintName = hintType.name();
    if (extras.containsKey(hintName)) {
      if (hintType.getValueType().equals(Void.class)) {
        // Void hints are just flags: use the constant specified by the DecodeHintType
        hints.put(hintType, Boolean.TRUE);
      } else {
        Object hintData = extras.get(hintName);
        if (hintType.getValueType().isInstance(hintData)) {
          hints.put(hintType, hintData);
        } else {
          Log.w(TAG, "Ignoring hint " + hintType + " because it is not assignable from " + hintData);
        }
      }
    }
  }

  Log.i(TAG, "Hints from the Intent: " + hints);
  return hints;
}
 
Example 30
Project: boohee_v5.6   File: ByQuadrantReader.java   View source code 5 votes vote down vote up
public Result decode(BinaryBitmap image, Map<DecodeHintType, ?> hints) throws
        NotFoundException, ChecksumException, FormatException {
    int halfWidth = image.getWidth() / 2;
    int halfHeight = image.getHeight() / 2;
    try {
        return this.delegate.decode(image.crop(0, 0, halfWidth, halfHeight), hints);
    } catch (NotFoundException e) {
        Result result;
        try {
            result = this.delegate.decode(image.crop(halfWidth, 0, halfWidth, halfHeight),
                    hints);
            makeAbsolute(result.getResultPoints(), halfWidth, 0);
            return result;
        } catch (NotFoundException e2) {
            try {
                result = this.delegate.decode(image.crop(0, halfHeight, halfWidth,
                        halfHeight), hints);
                makeAbsolute(result.getResultPoints(), 0, halfHeight);
                return result;
            } catch (NotFoundException e3) {
                try {
                    result = this.delegate.decode(image.crop(halfWidth, halfHeight,
                            halfWidth, halfHeight), hints);
                    makeAbsolute(result.getResultPoints(), halfWidth, halfHeight);
                    return result;
                } catch (NotFoundException e4) {
                    int quarterWidth = halfWidth / 2;
                    int quarterHeight = halfHeight / 2;
                    result = this.delegate.decode(image.crop(quarterWidth, quarterHeight,
                            halfWidth, halfHeight), hints);
                    makeAbsolute(result.getResultPoints(), quarterWidth, quarterHeight);
                    return result;
                }
            }
        }
    }
}
 
Example 31
Project: code-scanner   File: Decoder.java   View source code 5 votes vote down vote up
public Decoder(@NonNull StateListener stateListener, @NonNull List<BarcodeFormat> formats,
        @Nullable DecodeCallback callback) {
    mStateListener = stateListener;
    mReader = new MultiFormatReader();
    mDecoderThread = new DecoderThread();
    mHints = new EnumMap<>(DecodeHintType.class);
    mHints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
    mReader.setHints(mHints);
    mCallback = callback;
}
 
Example 32
Project: QrCode   File: QRCodeMultiReader.java   View source code 5 votes vote down vote up
@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()]);
  }
}
 
Example 33
Project: boohee_v5.6   File: OneDReader.java   View source code 5 votes vote down vote up
public Result decode(BinaryBitmap image, Map<DecodeHintType, ?> hints) throws
        NotFoundException, FormatException {
    Result doDecode;
    try {
        doDecode = doDecode(image, hints);
    } catch (NotFoundException nfe) {
        boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
        if (tryHarder && image.isRotateSupported()) {
            BinaryBitmap rotatedImage = image.rotateCounterClockwise();
            doDecode = doDecode(rotatedImage, hints);
            Map<ResultMetadataType, ?> metadata = doDecode.getResultMetadata();
            int orientation = 270;
            if (metadata != null && metadata.containsKey(ResultMetadataType.ORIENTATION)) {
                orientation = (((Integer) metadata.get(ResultMetadataType.ORIENTATION))
                        .intValue() + 270) % 360;
            }
            doDecode.putMetadata(ResultMetadataType.ORIENTATION, Integer.valueOf(orientation));
            ResultPoint[] points = doDecode.getResultPoints();
            if (points != null) {
                int height = rotatedImage.getHeight();
                for (int i = 0; i < points.length; i++) {
                    points[i] = new ResultPoint((((float) height) - points[i].getY()) - 1.0f,
                            points[i].getX());
                }
            }
        } else {
            throw nfe;
        }
    }
    return doDecode;
}
 
Example 34
Project: okwallet   File: ScanActivity.java   View source code 5 votes vote down vote up
private void decode(final byte[] data) {
    final PlanarYUVLuminanceSource source = cameraManager.buildLuminanceSource(data);
    final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

    try {
        hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, new ResultPointCallback() {
            @Override
            public void foundPossibleResultPoint(final ResultPoint dot) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        scannerView.addDot(dot);
                    }
                });
            }
        });
        final Result scanResult = reader.decode(bitmap, hints);

        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                handleResult(scanResult);
            }
        });
    } catch (final ReaderException x) {
        // retry
        cameraHandler.post(fetchAndDecodeRunnable);
    } finally {
        reader.reset();
    }
}
 
Example 35
Project: boohee_v5.6   File: Detector.java   View source code 5 votes vote down vote up
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);
}
 
Example 36
Project: weex-3d-map   File: Detector.java   View source code 5 votes vote down vote up
/**
 * <p>Detects a QR Code in an image.</p>
 *
 * @param hints optional hints to detector
 * @return {@link DetectorResult} encapsulating results of detecting a QR Code
 * @throws NotFoundException if QR Code cannot be found
 * @throws FormatException if a QR Code cannot be decoded
 */
public final DetectorResult detect(Map<DecodeHintType,?> hints) throws NotFoundException, FormatException {

  resultPointCallback = hints == null ? null :
      (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);

  FinderPatternFinder finder = new FinderPatternFinder(image, resultPointCallback);
  FinderPatternInfo info = finder.find(hints);

  return processFinderPatternInfo(info);
}
 
Example 37
Project: weex-3d-map   File: QRCodeReader.java   View source code 5 votes vote down vote up
@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;
}
 
Example 38
Project: weex-3d-map   File: Decoder.java   View source code 5 votes vote down vote up
/**
 * <p>Convenience method that can decode a QR Code represented as a 2D array of booleans.
 * "true" is taken to mean a black module.</p>
 *
 * @param image booleans representing white/black QR Code modules
 * @param hints decoding hints that should be used to influence decoding
 * @return text and bytes encoded within the QR Code
 * @throws FormatException if the QR Code cannot be decoded
 * @throws ChecksumException if error correction fails
 */
public DecoderResult decode(boolean[][] image, Map<DecodeHintType,?> hints)
    throws ChecksumException, FormatException {
  int dimension = image.length;
  BitMatrix bits = new BitMatrix(dimension);
  for (int i = 0; i < dimension; i++) {
    for (int j = 0; j < dimension; j++) {
      if (image[i][j]) {
        bits.set(j, i);
      }
    }
  }
  return decode(bits, hints);
}
 
Example 39
Project: weex-3d-map   File: MultiFormatOneDReader.java   View source code 5 votes vote down vote up
@Override
public Result decodeRow(int rowNumber,
                        BitArray row,
                        Map<DecodeHintType,?> hints) throws NotFoundException {
  for (OneDReader reader : readers) {
    try {
      return reader.decodeRow(rowNumber, row, hints);
    } catch (ReaderException re) {
      // continue
    }
  }

  throw NotFoundException.getNotFoundInstance();
}
 
Example 40
Project: weex-3d-map   File: UPCAReader.java   View source code 5 votes vote down vote up
@Override
public Result decodeRow(int rowNumber,
                        BitArray row,
                        int[] startGuardRange,
                        Map<DecodeHintType,?> hints)
    throws NotFoundException, FormatException, ChecksumException {
  return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange, hints));
}