我们可以设置或编辑com.google.android.gms.vision.text.Text.TextBlock的内容吗?

问题描述 投票:1回答:2

根据OCR TextBlock的Google文档,它包含这些方法。

  • getBoundingBox()
  • getComponents()
  • getCornerPoints()
  • Getlanagaji()
  • 的getValue()

有没有办法为TextBlock设置setValue()?

提前致谢。

android textblock
2个回答
0
投票

不是.OCC设计用于从图像内容中推断文本 - 它不是为了在图像空间中重新创建文本。

您可以随时覆盖自己的文本框,具体取决于您的使用案例。


0
投票

这取决于你究竟需要什么。如果您正在考虑更改视觉API识别的显示文本,则可以。

在我使用Vision API的OCR示例的情况下,您只需要在OcrGraphic类中创建另一个构造函数。

private TextBlock mText;
private String cText;

OcrGraphic(GraphicOverlay overlay, TextBlock text, String caption){
    super(overlay);
    mText = text;
    cText = caption;
    .
    .
    .

    // Redraw the overlay, as this graphic has been added.
    postInvalidate();
}

然后修改以前的构造函数

OcrGraphic(GraphicOverlay overlay, TextBlock text) {
    super(overlay);

    mText = text;
    cText = text.getValue();
    .
    .
    .

    // Redraw the overlay, as this graphic has been added.
    postInvalidate();
}

在绘制方法中,您需要从变量中绘制文本

public void draw(Canvas canvas) {
    TextBlock text = mText;
    if (text == null) {
        return;
    }
    .
    .
    .
    // we replaced text.getValue() with cText that string are set by either constructors
    canvas.drawText(cText, rect.left, rect.bottom, sTextPaint);

}

现在你可以通过两种方式调用,它可以工作,只需在检测器处理器中使用,如下所示:(在receiveDetections方法中的OcrDetectorProcessor类中)

OcrGraphic graphic = new OcrGraphic(mGraphicOverlay, item);
// Or use new one for your custom text
OcrGraphic graphic = new OcrGraphic(mGraphicOverlay, item, textValue);

mGraphicOverlay.add(graphic);

请让我知道你想要做的事情。接受的答案也是正确的,但这是一个外部视觉API的技巧。

© www.soinside.com 2019 - 2024. All rights reserved.