use of com.google.android.gms.vision.text.TextBlock 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;
}
use of com.google.android.gms.vision.text.TextBlock in project android-vision by googlesamples.
the class OcrCaptureActivity method onTap.
/**
* onTap is called to capture the first TextBlock under the tap location and return it to
* the Initializing Activity.
*
* @param rawX - the raw position of the tap
* @param rawY - the raw position of the tap.
* @return true if the activity is ending.
*/
private boolean onTap(float rawX, float rawY) {
OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY);
TextBlock text = null;
if (graphic != null) {
text = graphic.getTextBlock();
if (text != null && text.getValue() != null) {
Intent data = new Intent();
data.putExtra(TextBlockObject, text.getValue());
setResult(CommonStatusCodes.SUCCESS, data);
finish();
} else {
Log.d(TAG, "text data is null");
}
} else {
Log.d(TAG, "no text detected");
}
return text != null;
}
use of com.google.android.gms.vision.text.TextBlock in project android-vision by googlesamples.
the class OcrGraphic method contains.
/**
* Checks whether a point is within the bounding box of this graphic.
* The provided point should be relative to this graphic's containing overlay.
* @param x An x parameter in the relative context of the canvas.
* @param y A y parameter in the relative context of the canvas.
* @return True if the provided point is contained within this graphic's bounding box.
*/
public boolean contains(float x, float y) {
TextBlock text = mText;
if (text == null) {
return false;
}
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);
return (rect.left < x && rect.right > x && rect.top < y && rect.bottom > y);
}
use of com.google.android.gms.vision.text.TextBlock 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);
}
}
use of com.google.android.gms.vision.text.TextBlock in project Moneycim by volkansahin45.
the class OcrCaptureActivity method onTap.
/**
* onTap is called to capture the first TextBlock under the tap location and return it to
* the Initializing Activity.
*
* @param rawX - the raw position of the tap
* @param rawY - the raw position of the tap.
* @return true if the activity is ending.
*/
private boolean onTap(float rawX, float rawY) {
OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY);
TextBlock text = null;
if (graphic != null) {
text = graphic.getTextBlock();
if (text != null && text.getValue() != null) {
Intent data = new Intent();
data.putExtra(TextBlockObject, text.getValue());
setResult(CommonStatusCodes.SUCCESS, data);
finish();
} else {
Log.d(TAG, "text data is null");
}
} else {
Log.d(TAG, "no text detected");
}
return text != null;
}
Aggregations