Search in sources :

Example 6 with TextBlock

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);
    }
}
Also used : RectF(android.graphics.RectF) Text(com.google.android.gms.vision.text.Text) TextBlock(com.google.android.gms.vision.text.TextBlock)

Example 7 with TextBlock

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);
}
Also used : RectF(android.graphics.RectF) TextBlock(com.google.android.gms.vision.text.TextBlock)

Example 8 with TextBlock

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();
    }
}
Also used : TextBlock(com.google.android.gms.vision.text.TextBlock)

Example 9 with TextBlock

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);
}
Also used : ImageDimensions(org.reactnative.camera.utils.ImageDimensions) TextBlock(com.google.android.gms.vision.text.TextBlock)

Example 10 with TextBlock

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;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) TextBlock(com.google.android.gms.vision.text.TextBlock)

Aggregations

TextBlock (com.google.android.gms.vision.text.TextBlock)12 RectF (android.graphics.RectF)4 Text (com.google.android.gms.vision.text.Text)3 Intent (android.content.Intent)2 WritableArray (com.facebook.react.bridge.WritableArray)2 WritableMap (com.facebook.react.bridge.WritableMap)2 Line (com.google.android.gms.vision.text.Line)1 ImageDimensions (org.reactnative.camera.utils.ImageDimensions)1