public class RecognizerRunner
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
RecognizerRunner.State |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
If there is ongoing recognition process, this method will request cancellation of it and wait for
recognition process to complete.
|
RecognizerRunner.State |
getCurrentState()
Returns the current state of the recognizer.
|
static RecognizerRunner |
getSingletonInstance()
Returns the recognizer singleton.
|
void |
initialize(android.content.Context context,
RecognizerBundle recognizerBundle,
DirectApiErrorListener errorListener)
Initialize native library for recognition and returns true if initialization has been performed.
|
void |
recognizeBitmap(android.graphics.Bitmap image,
Orientation imageOrientation,
Rectangle scanRegion,
ScanResultListener resultListener)
Perform recognition of image represented as Android Bitmap.
|
void |
recognizeBitmap(android.graphics.Bitmap image,
Orientation imageOrientation,
ScanResultListener resultListener)
Perform recognition of image represented as Android Bitmap.
|
void |
recognizeBitmapWithRecognizers(android.graphics.Bitmap image,
Orientation imageOrientation,
Rectangle scanRegion,
ScanResultListener resultListener,
RecognizerBundle recognizerBundle)
Perform recognition of image represented as Android Bitmap.
|
void |
recognizeBitmapWithRecognizers(android.graphics.Bitmap image,
Orientation imageOrientation,
ScanResultListener resultListener,
RecognizerBundle recognizerBundle)
Perform recognition of image represented as Android Bitmap.
|
void |
recognizeImage(Image image,
ScanResultListener resultListener)
Use this method to directly recognize Image object obtained via MetadataListener while recognizer is active.
|
void |
recognizeImageWithRecognizers(Image image,
ScanResultListener resultListener,
RecognizerBundle recognizerBundle)
Use this method to directly recognize Image object obtained via MetadataListener while recognizer is active.
|
void |
recognizeString(java.lang.String stringData,
ScanResultListener resultListener)
Use this method to directly recognize given string data without performing the OCR, while recognizer is active.
|
void |
recognizeStringWithRecognizers(java.lang.String stringData,
ScanResultListener resultListener,
RecognizerBundle recognizerBundle)
Use this method to directly recognize given string data without performing the OCR, while recognizer is active.
|
void |
resetRecognitionState()
Resets the recognition state, i.e.
|
void |
resetRecognitionState(boolean hardReset)
Resets the recognition state.
|
void |
setMetadataCallbacks(MetadataCallbacks metadataCallbacks)
Sets the metadata callbacks that will obtain metadata during processing.
|
void |
terminate()
Terminates the native library.
|
@NonNull public static RecognizerRunner getSingletonInstance()
@NonNull public final RecognizerRunner.State getCurrentState()
public final void initialize(@NonNull android.content.Context context, @NonNull RecognizerBundle recognizerBundle, @NonNull DirectApiErrorListener errorListener)
context
- Application context used for loading required resources.recognizerBundle
- RecognizerRunner bundle defining a recognition process.errorListener
- Listener that will be notified of any error in native library in background thread.java.lang.IllegalStateException
- if recognizer is already initializedjava.lang.NullPointerException
- if context, settings array or errorListener is nullpublic final void recognizeBitmap(@NonNull android.graphics.Bitmap image, @NonNull Orientation imageOrientation, @NonNull ScanResultListener resultListener)
image
- Image that needs to be recognized.imageOrientation
- Orientation of the bitmap image.resultListener
- Result listener that will handle recognition done event.java.lang.IllegalStateException
- if recognizer is not initialized or is currently workingjava.lang.NullPointerException
- if given null scan result listenerpublic final void recognizeBitmap(@NonNull android.graphics.Bitmap image, @NonNull Orientation imageOrientation, @NonNull Rectangle scanRegion, @NonNull ScanResultListener resultListener)
image
- Image that needs to be recognized.imageOrientation
- Orientation of the bitmap image.scanRegion
- Region of image that needs to be recognized. Rectangle is given as percentages
of image size - x coordinate and width are percentages of image width and y coordinate
and height are percentages of image height. Therefore, rectangle(0.f, 0.f, 1.f, 1.f)
represents the whole image, whilst rectangle(0.5f, 0.f, 0.5f, 1.f) represents the
right half of the image.resultListener
- Result listener that will handle recognition done event.java.lang.IllegalStateException
- if recognizer is not initialized or is currently workingjava.lang.NullPointerException
- if given null scan result listenerpublic final void recognizeBitmapWithRecognizers(@NonNull android.graphics.Bitmap image, @NonNull Orientation imageOrientation, @NonNull ScanResultListener resultListener, @NonNull RecognizerBundle recognizerBundle)
image
- Image that needs to be recognized.imageOrientation
- Orientation of the bitmap image.resultListener
- Result listener that will handle recognition done event.recognizerBundle
- Recognizer bundle that will be used to perform this recognition.java.lang.IllegalStateException
- if recognizer is not initialized or is currently workingjava.lang.NullPointerException
- if given null scan result listenerpublic final void recognizeBitmapWithRecognizers(@NonNull android.graphics.Bitmap image, @NonNull Orientation imageOrientation, @NonNull Rectangle scanRegion, @NonNull ScanResultListener resultListener, @NonNull RecognizerBundle recognizerBundle)
image
- Image that needs to be recognized.imageOrientation
- Orientation of the bitmap image.scanRegion
- Region of image that needs to be recognized. Rectangle is given as percentages
of image size - x coordinate and width are percentages of image width and y coordinate
and height are percentages of image height. Therefore, rectangle(0.f, 0.f, 1.f, 1.f)
represents the whole image, whilst rectangle(0.5f, 0.f, 0.5f, 1.f) represents the
right half of the image.resultListener
- Result listener that will handle recognition done event.recognizerBundle
- Recognizer bundle that will be used to perform this recognition.java.lang.IllegalStateException
- if recognizer is not initialized or is currently workingjava.lang.NullPointerException
- if given null scan result listener@AnyThread public final void resetRecognitionState()
@AnyThread public final void resetRecognitionState(boolean hardReset)
hardReset
- true
to request hard reset, false
for the soft reset.@UiThread public final void recognizeImage(@NonNull Image image, @NonNull ScanResultListener resultListener)
Recognition will be performed with same settings that were used for initialization of recognizer singleton.
Please note that Image object will be disposed as soon as onMetadataAvailable method ends. You must clone the Image object by calling its clone() method to ensure Image lives long enough to be processed.
image
- Image to be processed (usually obtained from DebugImageListener)resultListener
- Listener that will be invoked with recognition result.@UiThread public final void recognizeImageWithRecognizers(@NonNull Image image, @NonNull ScanResultListener resultListener, @NonNull RecognizerBundle recognizerBundle)
If error happens due to illegal settings, onError will be invoked of the DirectApiErrorListener that was set in initialize method.
image
- Image to be processed (usually obtained from MetadataListener).resultListener
- Listener that will be invoked with recognition result.recognizerBundle
- Recognizer bundle that will be used to perform this recognition.java.lang.IllegalStateException
- if recognizer is not initialized or is currently working or Image object is already disposedjava.lang.NullPointerException
- if given null scan result listener@UiThread public final void recognizeString(@NonNull java.lang.String stringData, @NonNull ScanResultListener resultListener)
Recognition will be performed with same settings that were used for initialization of recognizer singleton.
stringData
- String to be processed.resultListener
- Listener that will be invoked with recognition result.java.lang.IllegalStateException
- if recognizer is not initialized or is currently workingjava.lang.NullPointerException
- if given null scan result listener@UiThread public final void recognizeStringWithRecognizers(@NonNull java.lang.String stringData, @NonNull ScanResultListener resultListener, @NonNull RecognizerBundle recognizerBundle)
If error happens due to illegal settings, onError will be invoked of the DirectApiErrorListener that was set in initialize method.
stringData
- String to be processed.resultListener
- Listener that will be invoked with recognition result.recognizerBundle
- Recognizer bundle that will be used to perform this recognition.java.lang.IllegalStateException
- if recognizer is not initialized or is currently workingjava.lang.NullPointerException
- if given null scan result listenerpublic void cancel()
ScanResultListener
given to last
recognition requiest will be called with result or not - in some cases it could happen, in some it
would not.public void terminate()
@AnyThread public void setMetadataCallbacks(@Nullable MetadataCallbacks metadataCallbacks)
metadataCallbacks
- collection of metadata callbacks tha will obtain metadata during processing.
If set to null, all callbacks will be disabled.