Initialization Control
The following methods and properties help with the initialization of the library.
License Control
API Name | Description |
---|---|
license | Use an alphanumeric string to specify the license. |
Create and Destroy Instances
API Name | Description |
---|---|
createInstance() | Creates a LabelRecognizer instance. |
destroyContext() | Destroies the LabelRecognizer instance. |
isContextDestroyed() | Returns whether the instance has been destroyed. |
Set Up the Environment
API Name | Description |
---|---|
engineResourcePath | Specifies the path from where the recognition engine and models, etc. can be loaded. |
loadWasm() | Loads the recognition engine and models. |
isWasmLoaded() | Returns whether the recognition engine and models have been loaded. |
getVersion() | Returns the version of the library. |
detectEnvironment() | Assess the running environment regarding the features the library requires to run. |
license
Use an alphanumeric string to specify the license. Note that the license must be specified before the methods createInstance()
and loadWasm()
.
static license: string;
createInstance
Creates a LabelRecognizer
instance.
static createInstance(config?: any): Promise<LabelRecognizer>
Parameters
config
: Configures how to create the instance. At present, it only specifies one of the built-in runtimeSettings
templates which include
Name | Description |
---|---|
number |
For pure number recognition. |
numberLetter |
For number and English letter recognition. |
numberUpperCase |
For number and uppercase English letter recognition. |
letter |
For pure English letter recognition. |
passportMRZ |
For passport MRZ recognition. |
visaMRZ_A |
For Visa (Country not Credit Card) MRZ recognition. |
VIN |
For VIN (vehicle identification number) recognition. |
VIN_NA |
For North American VIN (vehicle identification number) recognition. |
When recognizing from video input, add the prefix “video-“ for a slightly different template optimized for continuous frame recognition. For example, use video-passportMRZ
to read the MRZ on passports with a camera.
Return value
A promise resolving to the created LabelRecognizer
object.
Code Snippet
let recognizer = await Dynamsoft.DLR.LabelRecognizer.createInstance({
runtimeSettings: "video-passportMRZ"
});
recognizer.startScanning();
destroyContext
Destroys the LabelRecognizer
instance. If your page needs to create a new instance from time to time, don’t forget to destroy unused old instances.
destroyContext(): Promise<void>
Parameters
None.
Return value
A promise that resolves when the operation succeeds.
Code Snippet
let recognizer = await Dynamsoft.DLR.LabelRecognizer.createInstance();
// ... decode ...
recognizer.destroyContext();
isContextDestroyed
Returns whether the instance has been destroyed.
isContextDestroyed(): boolean
engineResourcePath
Specifies the path to find the engine(s). The property needs to be set before loadWasm. If not specified, the library will try to find the engine in the same location as the main JavaScript file (dlr.js).
static engineResourcePath: string
Code Snippet
Dynamsoft.DLR.LabelRecognizer.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.0/dist/";
await Dynamsoft.DLR.LabelRecognizer.loadWasm();
loadWasm
Downloads and compiles the engine to get it loaded/ready for a LabelRecognizer instance to be created. You can call this API to silently set the operating environment of the library as soon as the page is loaded, avoiding unnecessary waiting time when using the library later.
If this API is not called beforehand, it will be called automatically when creating a LabelRecognizer instance.
static loadWasm(): Promise<void>
Code Snippet
window.addEventListener('DOMContentLoaded', (event) => {
Dynamsoft.DLR.LabelRecognizer.loadWasm();
});
isWasmLoaded
Returns whether the engine is loaded/ready.
static isWasmLoaded(): boolean
getVersion
Returns the version of the library including the detailed version numbers of the engine and the main JavaScript code.
Only valid after loadWasm has been called.
static getVersion(): string
Code Snippet
console.log(Dynamsoft.DLR.LabelRecognizer.getVersion());
await Dynamsoft.DLR.LabelRecognizer.loadWasm();
console.log(Dynamsoft.DLR.LabelRecognizer.getVersion());
detectEnvironment
Returns a report on the current running environments.
static detectEnvironment(): Promise<any>
Code Snippet
console.log(Dynamsoft.DLR.LabelRecognizer.detectEnvironment());
// {"wasm":true, "worker":true, "getUserMedia":true, "camera":true, "browser":"Chrome", "version":90, "OS":"Windows"}