Search in sources :

Example 1 with Text

use of com.google.android.gms.vision.text.Text 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 Text

use of com.google.android.gms.vision.text.Text 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 3 with Text

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

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)

Aggregations

Text (com.google.android.gms.vision.text.Text)3 TextBlock (com.google.android.gms.vision.text.TextBlock)3 RectF (android.graphics.RectF)2 WritableArray (com.facebook.react.bridge.WritableArray)1 WritableMap (com.facebook.react.bridge.WritableMap)1 Line (com.google.android.gms.vision.text.Line)1