根据OCR TextBlock的Google文档,它包含这些方法。
有没有办法为TextBlock设置setValue()?
提前致谢。
不是.OCC设计用于从图像内容中推断文本 - 它不是为了在图像空间中重新创建文本。
您可以随时覆盖自己的文本框,具体取决于您的使用案例。
这取决于你究竟需要什么。如果您正在考虑更改视觉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的技巧。