Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

OCR.Initialize

Initializes tesseract.

Component Version macOS Windows Linux Server iOS SDK
OCR 2.9 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "OCR.Initialize"; Path; Lang { ; Options } )   More

Parameters

Parameter Description Example Flags
Path The path to the folder where to find tessdata folder.
Must end with tessdata as folder name.
$path
Lang The language to use. "eng"
Options For tessertact 4 or newer, pass here optional option list. Optional

Result

Returns OK on success.

Description

Initializes tesseract.
Pass path to parent folder of tessdata folder and language you need.
The language is (usually) an ISO 639-3 string.
To use multiple languages, please concat them with plus sign: e.g. "eng+deu"

You find our language files archive here:
https://www.monkeybreadsoftware.com/filemaker/files/Libs/

The tessdata folder may need to contain additional files for some languages. If those are missing, the tesseract engine likes to abort the process.

Starting with version 11.2 of MBS Plugin, the initialization is per thread. Scripts running on FileMaker server may need to check OCR.IsInitialized and do initialization for their execution thread if needed before using OCR functions. But then each script can do OCR in parallel using multiple CPU cores.

To use tesseract 4.x, please use OCR.Load function to load the newer libraries.

Please notice that using data files for version 3 with library of version 4 (or other way around) will crash.

We intent to remove tesseract 3.x library from the plugin in summer 2022, so please move to loading the newer version.

This function requires a native path. Use Path.FileMakerPathToNativePath to convert a FileMaker path to a native path if required. If you like to have the user choose the path, you can use FileDialog functions.
For Server be aware that server has limited permissions and may not be able to access all files on a computer.

Examples

Initialize with tessdata folder in same folder as database for english:

set variable $databasePath to Get(FilePath)
set variable $databasePath to MBS("Path.FileMakerPathToNativePath"; $databasePath)
set variable $databasePath to Substitute ( $databasePath ; ".fp7" ; ".fmp12")
set variable $databaseName to Get(FileName) & ".fmp12"
set variable $path to Substitute ( $databasePath ; $databaseName ; "tessdata" )
set variable $r to MBS( "OCR.Initialize"; $path; "eng")

Initialize on Server with tessdata in Server folder:

MBS( "OCR.Initialize"; "/Library/FileMaker Server/"; "eng")

Initialize on demand:

If [MBS("OCR.IsInitialized") ≠ 1]
    Set Variable [$r; Value:MBS( "OCR.Initialize"; "/Library/FileMaker Server/"; "eng")]
End If

Initialize with hard coded path:

Set Variable [ $path ; Value: "/Users/cs/Tesseract/tesseract4/tessdata" ]
Set Variable [ $r ; Value: MBS( "OCR.Initialize"; $path; "eng") ]

Initialize for chinese:

Set Variable [ $r ; Value: MBS( "OCR.Initialize"; $path; "chi_sim") ]

See also

Example Databases

Blog Entries

This function is free to use.

Created 18th August 2014, last changed 14th March 2024


OCR.GetVariable - OCR.IsInitialized