Search in sources :

Example 6 with WritableArray

use of com.facebook.react.bridge.WritableArray in project react-native-camera by lwansbrough.

the class TextRecognizerAsyncTask method serializeLine.

private WritableMap serializeLine(Text.Line line) {
    WritableMap encodedText = Arguments.createMap();
    WritableArray lines = Arguments.createArray();
    for (Text.Element element : line.getElements()) {
        lines.pushMap(serializeElement(element));
    }
    encodedText.putArray("components", lines);
    encodedText.putString("value", line.getText());
    WritableMap bounds = processBounds(line.getBoundingBox());
    encodedText.putMap("bounds", bounds);
    encodedText.putString("type", "line");
    return encodedText;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) Text(com.google.mlkit.vision.text.Text)

Example 7 with WritableArray

use of com.facebook.react.bridge.WritableArray in project react-native-camera by lwansbrough.

the class TextRecognizerAsyncTask method doInBackground.

@Override
protected Void doInBackground(Void... ignored) {
    if (isCancelled() || mDelegate == null) {
        return null;
    }
    TextRecognizer detector = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS);
    InputImage image = InputImage.fromByteArray(mImageData, mWidth, mHeight, getFirebaseRotation(), InputImage.IMAGE_FORMAT_YV12);
    detector.process(image).addOnSuccessListener(new OnSuccessListener<Text>() {

        @Override
        public void onSuccess(Text firebaseVisionText) {
            List<Text.TextBlock> textBlocks = firebaseVisionText.getTextBlocks();
            WritableArray serializedData = serializeEventData(textBlocks);
            mDelegate.onTextRecognized(serializedData);
            mDelegate.onTextRecognizerTaskCompleted();
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(Exception e) {
            Log.e(TAG, "Text recognition task failed" + e);
            mDelegate.onTextRecognizerTaskCompleted();
        }
    });
    return null;
}
Also used : WritableArray(com.facebook.react.bridge.WritableArray) Text(com.google.mlkit.vision.text.Text) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) TextRecognizer(com.google.mlkit.vision.text.TextRecognizer) InputImage(com.google.mlkit.vision.common.InputImage) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 8 with WritableArray

use of com.facebook.react.bridge.WritableArray in project react-native-camera by lwansbrough.

the class TextRecognizerAsyncTask method serializeBloc.

private WritableMap serializeBloc(Text.TextBlock block) {
    WritableMap encodedText = Arguments.createMap();
    WritableArray lines = Arguments.createArray();
    for (Text.Line line : block.getLines()) {
        lines.pushMap(serializeLine(line));
    }
    encodedText.putArray("components", lines);
    encodedText.putString("value", block.getText());
    WritableMap bounds = processBounds(block.getBoundingBox());
    encodedText.putMap("bounds", bounds);
    encodedText.putString("type", "block");
    return encodedText;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) Text(com.google.mlkit.vision.text.Text)

Example 9 with WritableArray

use of com.facebook.react.bridge.WritableArray in project react-native-camera by lwansbrough.

the class TextRecognizerAsyncTask method rotateTextX.

private WritableMap rotateTextX(WritableMap text) {
    ReadableMap faceBounds = text.getMap("bounds");
    ReadableMap oldOrigin = faceBounds.getMap("origin");
    WritableMap mirroredOrigin = positionMirroredHorizontally(oldOrigin, mImageDimensions.getWidth(), mScaleX);
    double translateX = -faceBounds.getMap("size").getDouble("width");
    WritableMap translatedMirroredOrigin = positionTranslatedHorizontally(mirroredOrigin, translateX);
    WritableMap newBounds = Arguments.createMap();
    newBounds.merge(faceBounds);
    newBounds.putMap("origin", translatedMirroredOrigin);
    text.putMap("bounds", newBounds);
    ReadableArray oldComponents = text.getArray("components");
    WritableArray newComponents = Arguments.createArray();
    for (int i = 0; i < oldComponents.size(); ++i) {
        WritableMap component = Arguments.createMap();
        component.merge(oldComponents.getMap(i));
        rotateTextX(component);
        newComponents.pushMap(component);
    }
    text.putArray("components", newComponents);
    return text;
}
Also used : ReadableArray(com.facebook.react.bridge.ReadableArray) WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) ReadableMap(com.facebook.react.bridge.ReadableMap)

Example 10 with WritableArray

use of com.facebook.react.bridge.WritableArray in project react-native-camera by lwansbrough.

the class TextRecognizerAsyncTask method serializeText.

private WritableMap serializeText(TextBlock text) {
    WritableMap encodedText = Arguments.createMap();
    WritableArray components = Arguments.createArray();
    for (Line component : text.getLines()) {
        components.pushMap(serializeText(component));
    }
    encodedText.putArray("components", components);
    encodedText.putString("value", text.getText());
    WritableMap bounds = serializeBounds(text.getBoundingBox());
    encodedText.putMap("bounds", bounds);
    encodedText.putString("type", "block");
    return encodedText;
}
Also used : Line(com.google.mlkit.vision.text.Text.Line) WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray)

Aggregations

WritableArray (com.facebook.react.bridge.WritableArray)139 WritableMap (com.facebook.react.bridge.WritableMap)117 ReactMethod (com.facebook.react.bridge.ReactMethod)40 ArrayList (java.util.ArrayList)37 List (java.util.List)25 StringeeClient (com.stringee.StringeeClient)20 StringeeError (com.stringee.exception.StringeeError)20 Conversation (com.stringee.messaging.Conversation)20 WritableNativeMap (com.facebook.react.bridge.WritableNativeMap)17 WritableNativeArray (com.facebook.react.bridge.WritableNativeArray)16 Text (com.google.mlkit.vision.text.Text)10 ReadableMap (com.facebook.react.bridge.ReadableMap)9 CallbackListener (com.stringee.messaging.listeners.CallbackListener)9 SuppressLint (android.annotation.SuppressLint)7 Handler (android.os.Handler)7 Nullable (androidx.annotation.Nullable)7 Face (com.google.mlkit.vision.face.Face)7 Message (com.stringee.messaging.Message)7 Bundle (android.os.Bundle)6 RequiresApi (androidx.annotation.RequiresApi)6