Search in sources :

Example 1 with Line

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

Aggregations

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