Search in sources :

Example 1 with Text

use of com.google.mlkit.vision.text.Text 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 2 with Text

use of com.google.mlkit.vision.text.Text in project react-native-camera by lwansbrough.

the class TextRecognizerAsyncTask method serializeText.

private WritableMap serializeText(Line text) {
    WritableMap encodedText = Arguments.createMap();
    WritableArray components = Arguments.createArray();
    for (Text.Element component : text.getElements()) {
        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", "line");
    return encodedText;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) Text(com.google.mlkit.vision.text.Text)

Aggregations

WritableArray (com.facebook.react.bridge.WritableArray)2 Text (com.google.mlkit.vision.text.Text)2 WritableMap (com.facebook.react.bridge.WritableMap)1 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)1 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)1 InputImage (com.google.mlkit.vision.common.InputImage)1 TextRecognizer (com.google.mlkit.vision.text.TextRecognizer)1