Search in sources :

Example 11 with DecodeHintType

use of com.google.zxing.DecodeHintType in project zxing by zxing.

the class AbstractNegativeBlackBoxTestCase method checkForFalsePositives.

/**
   * Make sure ZXing does NOT find a barcode in the image.
   *
   * @param image The image to test
   * @param rotationInDegrees The amount of rotation to apply
   * @return true if nothing found, false if a non-existent barcode was detected
   */
private boolean checkForFalsePositives(BufferedImage image, float rotationInDegrees) {
    BufferedImage rotatedImage = rotateImage(image, rotationInDegrees);
    LuminanceSource source = new BufferedImageLuminanceSource(rotatedImage);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    Result result;
    try {
        result = getReader().decode(bitmap);
        log.info(String.format("Found false positive: '%s' with format '%s' (rotation: %d)", result.getText(), result.getBarcodeFormat(), (int) rotationInDegrees));
        return false;
    } catch (ReaderException re) {
    // continue
    }
    // Try "try harder" getMode
    Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
    hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
    try {
        result = getReader().decode(bitmap, hints);
        log.info(String.format("Try harder found false positive: '%s' with format '%s' (rotation: %d)", result.getText(), result.getBarcodeFormat(), (int) rotationInDegrees));
        return false;
    } catch (ReaderException re) {
    // continue
    }
    return true;
}
Also used : LuminanceSource(com.google.zxing.LuminanceSource) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) DecodeHintType(com.google.zxing.DecodeHintType) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) BinaryBitmap(com.google.zxing.BinaryBitmap) EnumMap(java.util.EnumMap) BufferedImage(java.awt.image.BufferedImage) Result(com.google.zxing.Result) ReaderException(com.google.zxing.ReaderException)

Example 12 with DecodeHintType

use of com.google.zxing.DecodeHintType in project zxing-android-embedded by journeyapps.

the class DecoratedBarcodeView method initializeFromIntent.

/**
     * Convenience method to initialize camera id, decode formats and prompt message from an intent.
     *
     * @param intent the intent, as generated by IntentIntegrator
     */
public void initializeFromIntent(Intent intent) {
    // Scan the formats the intent requested, and return the result to the calling activity.
    Set<BarcodeFormat> decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);
    Map<DecodeHintType, Object> decodeHints = DecodeHintManager.parseDecodeHints(intent);
    CameraSettings settings = new CameraSettings();
    if (intent.hasExtra(Intents.Scan.CAMERA_ID)) {
        int cameraId = intent.getIntExtra(Intents.Scan.CAMERA_ID, -1);
        if (cameraId >= 0) {
            settings.setRequestedCameraId(cameraId);
        }
    }
    String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE);
    if (customPromptMessage != null) {
        setStatusText(customPromptMessage);
    }
    // Check to see if the scan should be inverted.
    boolean inverted = intent.getBooleanExtra(Intents.Scan.INVERTED_SCAN, false);
    String characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);
    MultiFormatReader reader = new MultiFormatReader();
    reader.setHints(decodeHints);
    barcodeView.setCameraSettings(settings);
    barcodeView.setDecoderFactory(new DefaultDecoderFactory(decodeFormats, decodeHints, characterSet, inverted));
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) DecodeHintType(com.google.zxing.DecodeHintType) BarcodeFormat(com.google.zxing.BarcodeFormat) CameraSettings(com.journeyapps.barcodescanner.camera.CameraSettings) ResultPoint(com.google.zxing.ResultPoint)

Example 13 with DecodeHintType

use of com.google.zxing.DecodeHintType in project zxing-android-embedded by journeyapps.

the class DefaultDecoderFactory method createDecoder.

@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);
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) DecodeHintType(com.google.zxing.DecodeHintType) EnumMap(java.util.EnumMap)

Example 14 with DecodeHintType

use of com.google.zxing.DecodeHintType in project zxing-android-embedded by journeyapps.

the class DecodeHintManager method parseDecodeHints.

public 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) {
            // This hint is specified in another way
            continue;
        }
        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;
}
Also used : DecodeHintType(com.google.zxing.DecodeHintType) Bundle(android.os.Bundle) EnumMap(java.util.EnumMap)

Example 15 with DecodeHintType

use of com.google.zxing.DecodeHintType in project react-native-camera by lwansbrough.

the class RCTCameraViewFinder method initBarcodeReader.

/**
     * 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);
}
Also used : DecodeHintType(com.google.zxing.DecodeHintType) BarcodeFormat(com.google.zxing.BarcodeFormat) EnumMap(java.util.EnumMap)

Aggregations

DecodeHintType (com.google.zxing.DecodeHintType)22 EnumMap (java.util.EnumMap)17 Bundle (android.os.Bundle)5 Result (com.google.zxing.Result)5 MultiFormatReader (com.google.zxing.MultiFormatReader)4 ReaderException (com.google.zxing.ReaderException)4 BarcodeFormat (com.google.zxing.BarcodeFormat)3 BinaryBitmap (com.google.zxing.BinaryBitmap)3 NotFoundException (com.google.zxing.NotFoundException)3 ResultPoint (com.google.zxing.ResultPoint)3 BitmapFactory (android.graphics.BitmapFactory)2 BitArray (com.google.zxing.common.BitArray)2 HybridBinarizer (com.google.zxing.common.HybridBinarizer)2 Hashtable (java.util.Hashtable)2 Test (org.junit.Test)2 Bitmap (android.graphics.Bitmap)1 BufferedImageLuminanceSource (com.google.zxing.BufferedImageLuminanceSource)1 ChecksumException (com.google.zxing.ChecksumException)1 FormatException (com.google.zxing.FormatException)1 LuminanceSource (com.google.zxing.LuminanceSource)1