use of com.google.android.gms.vision.text.TextBlock in project Moneycim by volkansahin45.
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 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 Moneycim by volkansahin45.
the class OcrDetectorProcessor method receiveDetections.
/**
* Called by the detector to deliver detection results.
* If your application called for it, this could be a place to icon_save for
* equivalent detections by tracking TextBlocks that are similar in location and content from
* previous frames, or reduce noise by eliminating TextBlocks that have not persisted through
* multiple detections.
*/
@Override
public void receiveDetections(Detector.Detections<TextBlock> detections) {
mGraphicOverlay.clear();
SparseArray<TextBlock> items = detections.getDetectedItems();
for (int i = 0; i < items.size(); ++i) {
final TextBlock item = items.valueAt(i);
OcrGraphic graphic = new OcrGraphic(mGraphicOverlay, item);
mGraphicOverlay.add(graphic);
// detectedText += item.getValue();
}
}
use of com.google.android.gms.vision.text.TextBlock in project react-native-camera by react-native-community.
the class RNCameraView method onTextRecognized.
@Override
public void onTextRecognized(SparseArray<TextBlock> textBlocks, int sourceWidth, int sourceHeight, int sourceRotation) {
if (!mShouldRecognizeText) {
return;
}
SparseArray<TextBlock> textBlocksDetected = textBlocks == null ? new SparseArray<TextBlock>() : textBlocks;
ImageDimensions dimensions = new ImageDimensions(sourceWidth, sourceHeight, sourceRotation, getFacing());
RNCameraViewHelper.emitTextRecognizedEvent(this, textBlocksDetected, dimensions);
}
use of com.google.android.gms.vision.text.TextBlock in project react-native-camera by react-native-community.
the class TextRecognizedEvent method serializeEventData.
private WritableMap serializeEventData() {
WritableArray textBlocksList = Arguments.createArray();
for (int i = 0; i < mTextBlocks.size(); ++i) {
TextBlock textBlock = mTextBlocks.valueAt(i);
WritableMap serializedTextBlock = serializeText(textBlock);
if (mImageDimensions.getFacing() == CameraView.FACING_FRONT) {
serializedTextBlock = rotateTextX(serializedTextBlock);
}
textBlocksList.pushMap(serializedTextBlock);
}
WritableMap event = Arguments.createMap();
event.putString("type", "textBlock");
event.putArray("textBlocks", textBlocksList);
event.putInt("target", getViewTag());
return event;
}
Aggregations