Search in sources :

Example 1 with TextBlock

use of com.google.android.gms.vision.text.TextBlock in project react-native-camera by react-native-community.

the class TextRecognizedEvent method serializeText.

private WritableMap serializeText(Text text) {
    WritableMap encodedText = Arguments.createMap();
    WritableArray components = Arguments.createArray();
    for (Text component : text.getComponents()) {
        components.pushMap(serializeText(component));
    }
    encodedText.putArray("components", components);
    encodedText.putString("value", text.getValue());
    WritableMap origin = Arguments.createMap();
    origin.putDouble("x", text.getBoundingBox().left * this.mScaleX);
    origin.putDouble("y", text.getBoundingBox().top * this.mScaleY);
    WritableMap size = Arguments.createMap();
    size.putDouble("width", text.getBoundingBox().width() * this.mScaleX);
    size.putDouble("height", text.getBoundingBox().height() * this.mScaleY);
    WritableMap bounds = Arguments.createMap();
    bounds.putMap("origin", origin);
    bounds.putMap("size", size);
    encodedText.putMap("bounds", bounds);
    String type_;
    if (text instanceof TextBlock) {
        type_ = "block";
    } else if (text instanceof Line) {
        type_ = "line";
    } else /*if (text instanceof Element)*/
    {
        type_ = "element";
    }
    encodedText.putString("type", type_);
    return encodedText;
}
Also used : Line(com.google.android.gms.vision.text.Line) WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) Text(com.google.android.gms.vision.text.Text) TextBlock(com.google.android.gms.vision.text.TextBlock)

Example 2 with TextBlock

use of com.google.android.gms.vision.text.TextBlock in project android-vision by googlesamples.

the class OcrCaptureActivity method onTap.

/**
 * onTap is called to capture the first TextBlock under the tap location and return it to
 * the Initializing Activity.
 *
 * @param rawX - the raw position of the tap
 * @param rawY - the raw position of the tap.
 * @return true if the activity is ending.
 */
private boolean onTap(float rawX, float rawY) {
    OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY);
    TextBlock text = null;
    if (graphic != null) {
        text = graphic.getTextBlock();
        if (text != null && text.getValue() != null) {
            Intent data = new Intent();
            data.putExtra(TextBlockObject, text.getValue());
            setResult(CommonStatusCodes.SUCCESS, data);
            finish();
        } else {
            Log.d(TAG, "text data is null");
        }
    } else {
        Log.d(TAG, "no text detected");
    }
    return text != null;
}
Also used : Intent(android.content.Intent) TextBlock(com.google.android.gms.vision.text.TextBlock)

Example 3 with TextBlock

use of com.google.android.gms.vision.text.TextBlock in project android-vision by googlesamples.

the class OcrGraphic method contains.

/**
 * Checks whether a point is within the bounding box of this graphic.
 * The provided point should be relative to this graphic's containing overlay.
 * @param x An x parameter in the relative context of the canvas.
 * @param y A y parameter in the relative context of the canvas.
 * @return True if the provided point is contained within this graphic's bounding box.
 */
public boolean contains(float x, float y) {
    TextBlock text = mText;
    if (text == null) {
        return false;
    }
    RectF rect = new RectF(text.getBoundingBox());
    rect.left = translateX(rect.left);
    rect.top = translateY(rect.top);
    rect.right = translateX(rect.right);
    rect.bottom = translateY(rect.bottom);
    return (rect.left < x && rect.right > x && rect.top < y && rect.bottom > y);
}
Also used : RectF(android.graphics.RectF) TextBlock(com.google.android.gms.vision.text.TextBlock)

Example 4 with TextBlock

use of com.google.android.gms.vision.text.TextBlock in project android-vision by googlesamples.

the class OcrGraphic method draw.

/**
 * Draws the text block annotations for position, size, and raw value on the supplied canvas.
 */
@Override
public void draw(Canvas canvas) {
    TextBlock text = mText;
    if (text == null) {
        return;
    }
    // Draws the bounding box around the TextBlock.
    RectF rect = new RectF(text.getBoundingBox());
    rect.left = translateX(rect.left);
    rect.top = translateY(rect.top);
    rect.right = translateX(rect.right);
    rect.bottom = translateY(rect.bottom);
    canvas.drawRect(rect, sRectPaint);
    // Break the text into multiple lines and draw each one according to its own bounding box.
    List<? extends Text> textComponents = text.getComponents();
    for (Text currentText : textComponents) {
        float left = translateX(currentText.getBoundingBox().left);
        float bottom = translateY(currentText.getBoundingBox().bottom);
        canvas.drawText(currentText.getValue(), left, bottom, sTextPaint);
    }
}
Also used : RectF(android.graphics.RectF) Text(com.google.android.gms.vision.text.Text) TextBlock(com.google.android.gms.vision.text.TextBlock)

Example 5 with TextBlock

use of com.google.android.gms.vision.text.TextBlock in project Moneycim by volkansahin45.

the class OcrCaptureActivity method onTap.

/**
 * onTap is called to capture the first TextBlock under the tap location and return it to
 * the Initializing Activity.
 *
 * @param rawX - the raw position of the tap
 * @param rawY - the raw position of the tap.
 * @return true if the activity is ending.
 */
private boolean onTap(float rawX, float rawY) {
    OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY);
    TextBlock text = null;
    if (graphic != null) {
        text = graphic.getTextBlock();
        if (text != null && text.getValue() != null) {
            Intent data = new Intent();
            data.putExtra(TextBlockObject, text.getValue());
            setResult(CommonStatusCodes.SUCCESS, data);
            finish();
        } else {
            Log.d(TAG, "text data is null");
        }
    } else {
        Log.d(TAG, "no text detected");
    }
    return text != null;
}
Also used : Intent(android.content.Intent) TextBlock(com.google.android.gms.vision.text.TextBlock)

Aggregations

TextBlock (com.google.android.gms.vision.text.TextBlock)12 RectF (android.graphics.RectF)4 Text (com.google.android.gms.vision.text.Text)3 Intent (android.content.Intent)2 WritableArray (com.facebook.react.bridge.WritableArray)2 WritableMap (com.facebook.react.bridge.WritableMap)2 Line (com.google.android.gms.vision.text.Line)1 ImageDimensions (org.reactnative.camera.utils.ImageDimensions)1