OCR SDK Knowledge Base

Article ID: 1555 | Category: Engine Initialization | Type: How To | Last Modified: 1/26/2017

How to initialize Engine in Android application?

Description

Which values should be passed to dataSource and license parameters of the Engine.createInstance method call?

Solution

The dataSource is a list of DataSource objects. The program searches files with the data required for recognition (pattern, dictionary, keyword files, and so on) in the list. Usually and it is recommended to put patterns, dictionaries, keywords files etc. into the “assets” folder. More information about this moment you can find in the “Adding library to Java Project in Eclipse” article http://knowledgebase.ocrsdk.com/article/734.

The second parameter, “license” requires the link to the License object. This object containing the license information. You need to create FileLicense class object, by passing the same dataSource object, path to the license file and string containing the application identification (ApplicationID). The following code snippet will be helpful in this question:

 

private void startRecognition() {

final DataSource assetDataSrouce = new AssetDataSource(this.getAssets());

final List<DataSource> dataSources = new ArrayList<DataSource>();

dataSources.add(assetDataSrouce);

Engine.loadNativeLibrary();

try {

final FileLicense fileLicense = new FileLicense(assetDataSrouce, LICENSE_FILE, APPLICATION_ID);

final DataFilesExtensions dataFilesExtensions = new DataFilesExtensions(

PATTERNS_FILE_EXTENSION,

DICTIONARIES_FILE_EXTENSION,

KEYWORDS_FILE_EXTENSION);

Engine.createInstance(dataSources, fileLicense, dataFilesExtensions);

} catch(final IOException e) {

e.printStackTrace();

} catch(final License.BadLicenseException e) {

e.printStackTrace();

}

}

259 people think this is helpful.
Was this information helpful to you?