我正在使用管道检测文本,就像Google CodeLabs sample code一样。如何获取 CameraSource 发送到 TextRecognizer 的预览帧?
最佳答案
预览帧不会发送到文本识别器之外。但是,您可以创建一个包装文本识别器的类,在检测之前接收预览帧。查看类似的讨论 here .
首先,实现一个检测器类来包装文本识别器:
class MyTextRecognizer extends Detector<TextBlock> {
private Detector<TextBlock> mDelegate;
MyTextRecognizer(Detector<TextBlock> delegate) {
mDelegate = delegate;
}
public SparseArray<TextBlock> detect(Frame frame) {
// *** add your code to access the preview frame here
return mDelegate.detect(frame);
}
public boolean isOperational() {
return mDelegate.isOperational();
}
public boolean setFocus(int id) {
return mDelegate.setFocus(id);
}
}
用您的类包装文本识别器,并将您的类传递到相机源中。它看起来像这样:
TextRecognizer textRecognizer = new TextRecognizer.Builder(context)
.build();
TextRecognizer myTextRecognizer = new MyTextRecognizer(textRecognizer);
myTextRecognizer.setProcessor(/* include your processor here */);
mCameraSource = new CameraSource.Builder(context, myTextRecognizer)
.build();
您的 MyTextRecognizer 将首先使用原始帧数据调用。
请注意,如果设备旋转,图像可能不会直立。您可以通过框架的metadata.getRotation方法获取方向。
需要注意的是:一旦检测方法返回,您就不应该访问帧像素数据。由于相机源会回收图像缓冲区,因此一旦方法返回,帧对象的内容最终将被覆盖。
关于android - 在 Android Mobile Vision 中使用管道检测文本时获取框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39281557/