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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations