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

Can we set or edit the content of a com.google.android.gms.vision.text.Text.TextBlock?

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

有什么方法可以为 TextBlock 设置 Value() 吗?

提前致谢。

没有。 OCR 旨在从图像内容中推断文本——它不是为了在图像中重新创建文本 space。

不过,您始终可以覆盖自己的文本框,具体取决于您的用例。

这取决于您的具体需求。如果你想改变视觉识别的显示文本API,那么这是可能的。

在我使用来自 Vision API.

的 OCR 示例的情况下,您只需要在 OcrGraphic class 中创建另一个构造函数
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);

}

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

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。