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



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

  • getBoundingBox ()

  • 按照getComponents ()
  • getCornerPoints ()

  • getLanguage ()

  • getValue ()

是否有任何方法setValue()为TextBlock?

提前感谢。

这取决于你到底需要什么。如果你想改变由视觉API识别的显示文本,那么这是可能的。

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

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();
}

在draw方法中你需要从变量

中绘制文本
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之外的一个技巧。

No。OCR设计用于从图像内容中推断文本——它的目的不是在图像空间中重新创建文本。

你总是可以覆盖你自己的文本框,但这取决于你的用例。

相关内容

最新更新