Train to recognize additional symbols
User pattern training
To train custom symbol pattern you need image of a symbol
Important! You should set the smallSymbolHeight and BaseLine properties to correct values, otherwise the trained pattern will not function properly.
smallSymbolHeight - specifies the height of small characters in pixels on the source image. By default, the value is 0.
BaseLine - contains the distance from the base line to the top edge of the cropped image of the character. The base line is the line on which the characters are located. The top edge of the image is determined by the character orientation. By default, the value is 0.
Example:
The currency image. Its BaseLine=31, smallSymbolHeight = 22;

Code:
.....
private void processWithEngine() {
try {
displayMessage( "Training user pattern..." );
// Setup FREngine
setupFREngine();
//create pattern
ITrainingImagesCollection imagesCollection = engine.CreateTrainingImagesCollection();
ITrainingImage image = loadImage("temp_images/costa_rica_currency.bmp", 31, 22);
imagesCollection.Add(image);
String filename = "costa_rica_currency.ptn";
engine.CreateEmptyUserPattern(filename);
engine.TrainUserPattern(filename, imagesCollection, "₡", 0, TextTypeEnum.TT_Normal);
image.Release();
imagesCollection.Release();
} catch( Exception ex ) {
displayMessage( ex.getMessage() );
}
}
private ITrainingImage loadImage(String filename, int baseLine, int smallSymbolHeight){
ITrainingImage image = engine.CreateTrainingImage();
image.setBaseLine(baseLine);
image.setsmallSymbolHeight(smallSymbolHeight);
IImageDocument imageDoc = engine.OpenImageFile(filename, null, null, null);
IImage bwImage = imageDoc.getBlackWhiteImage();
IRegion region = engine.CreateRegion();
region.AddRect(0, 0, bwImage.getWidth(), bwImage.getHeight());
image.SetImageData(imageDoc, region);
region.Release();
imageDoc.Release();
return image;
}
.....
How to test your code
You can look at samples in /opt/ABBYY/FREngine11/Samples/Java on an OCR server:
- create your own sample folder with java file
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/ABBYY/FREngine11/Bin
- build.sh
- run.sh
Look at the example /ocr/ABBYY/FREngine11/Samples/Java/TrainUserPattern2
How to avoid memory leaks
ABBYY FineReader Engine provide Java support through JNI (Java Native Interface). JNI allows running native code from Java using special wrapper in C++
In this case we should care about releasing objects that is created through engine methods.
For example:
IFRDocument document = engine.CreateFRDocument();
...
FRPages pages = document.getPages();
for(int i=0; i < pages.getCount(); i++) {
FRPage page = pages.getElement(i);
ILayout layout = page.getLayout();
ILayoutBlocks blocks = layout.getBlocks();
.....
.....
.....
page.Release();
layout.Release();
blocks.Release();
}
pages.Release();
.....
ITextExportParams txtParams = engine.CreateTextExportParams();
.....
txtParams.Release();
.....
document.Release();
To be sure that all objects are releasing correctly you must enable debug mode
engine.StartLogging("filename.log", true);
then check log file to be sure that following message does not appear there
Not all objects were released before DeinitializeEngine()