使用ETEXT_DESC在Tesseract中进行/取消回调

时间:2020-12-10 08:54:18

Is there a way to specify a progress and cancel callback in Tesseract? I'm using Tesseract in Android, using the tess-two project.

有没有办法在Tesseract中指定进度并取消回调?我在Android中使用Tesseract,使用tess-two项目。

There is already a previous question - Android Tesseract progress callback. However, the answers there imply that it's not possible.

已经有一个先前的问题 - Android Tesseract进展回调。然而,那里的答案意味着它是不可能的。

I have another crucial detail to add - I checked the source code and found a class called ETEXT_DESC, which looks like it can be used for just this purpose.

我还有另外一个重要的细节 - 我检查了源代码并找到了一个名为ETEXT_DESC的类,看起来它可以用于此目的。

My question is - can ETEXT_DESC be used for progress and cancel callbacks, and if it can, how do I use it?

我的问题是 - 可以将ETEXT_DESC用于进度并取消回调,如果可以,我该如何使用它?

1 个解决方案

#1


Yes, you can get progress callbacks by implementing the ProgressNotifier interface and overriding the onProgressValues method. (Behind the scenes, it uses the ETEXT_DESC class that you mention.) Provide your notifier object as a parameter to the TessBaseAPI constructor.

是的,您可以通过实现ProgressNotifier接口并覆盖onProgressValues方法来获得进度回调。 (在后台,它使用您提到的ETEXT_DESC类。)将通知程序对象作为参数提供给TessBaseAPI构造函数。

You can cancel OCR that's in progress using the stop method.

您可以使用stop方法取消正在进行的OCR。

I wrote a blog post about this recently. If you run into problems please open a new issue on the tess-two project.

我最近写了一篇关于此的博客文章。如果您遇到问题,请在tess-two项目上打开一个新问题。

EDIT:

From the blog post:

来自博文:

The progress percentage can be used in a thermometer-style ProgressBar. The bounding boxes can be drawn on top of the display of the input image during recognition.

进度百分比可用于温度计式ProgressBar。可以在识别期间在输入图像的显示器上绘制边界框。

Implementing this callback requires using an alternate constructor for the TessBaseAPI object and implementation of the ProgressNotifier interface:

实现此回调需要使用TessBaseAPI对象的替代构造函数和ProgressNotifier接口的实现:

Registering to receive updates:

注册接收更新:

ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar1);

// Create the TessBaseAPI object, and register to receive OCR progress updates
TessBaseAPI baseApi = new TessBaseAPI(this);

baseApi.getHOCRText(myImage);

Receiving the udpates:

接收udpates:

@Override
public void onProgressValues(ProgressValues progressValues) {
    progressBar.setProgress(progressValues.getPercent());
}

#1


Yes, you can get progress callbacks by implementing the ProgressNotifier interface and overriding the onProgressValues method. (Behind the scenes, it uses the ETEXT_DESC class that you mention.) Provide your notifier object as a parameter to the TessBaseAPI constructor.

是的,您可以通过实现ProgressNotifier接口并覆盖onProgressValues方法来获得进度回调。 (在后台,它使用您提到的ETEXT_DESC类。)将通知程序对象作为参数提供给TessBaseAPI构造函数。

You can cancel OCR that's in progress using the stop method.

您可以使用stop方法取消正在进行的OCR。

I wrote a blog post about this recently. If you run into problems please open a new issue on the tess-two project.

我最近写了一篇关于此的博客文章。如果您遇到问题,请在tess-two项目上打开一个新问题。

EDIT:

From the blog post:

来自博文:

The progress percentage can be used in a thermometer-style ProgressBar. The bounding boxes can be drawn on top of the display of the input image during recognition.

进度百分比可用于温度计式ProgressBar。可以在识别期间在输入图像的显示器上绘制边界框。

Implementing this callback requires using an alternate constructor for the TessBaseAPI object and implementation of the ProgressNotifier interface:

实现此回调需要使用TessBaseAPI对象的替代构造函数和ProgressNotifier接口的实现:

Registering to receive updates:

注册接收更新:

ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar1);

// Create the TessBaseAPI object, and register to receive OCR progress updates
TessBaseAPI baseApi = new TessBaseAPI(this);

baseApi.getHOCRText(myImage);

Receiving the udpates:

接收udpates:

@Override
public void onProgressValues(ProgressValues progressValues) {
    progressBar.setProgress(progressValues.getPercent());
}