问题
Is there a way to specify a progress and cancel callback in Tesseract? I'm using Tesseract in Android, using the tess-two project.
There is already a previous question - Android Tesseract progress callback. However, the answers there imply that it's not possible.
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.
My question is - can ETEXT_DESC
be used for progress and cancel callbacks, and if it can, how do I use it?
回答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.
You can cancel OCR that's in progress using the stop
method.
I wrote a blog post about this recently. If you run into problems please open a new issue on the tess-two project.
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.
Implementing this callback requires using an alternate constructor for the TessBaseAPI object and implementation of the ProgressNotifier interface:
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:
@Override
public void onProgressValues(ProgressValues progressValues) {
progressBar.setProgress(progressValues.getPercent());
}
来源:https://stackoverflow.com/questions/30025912/progress-cancel-callback-in-tesseract-using-etext-desc