@@ -8,7 +8,7 @@ Once integrated, your users can open your website in a browser, access their cam
8
8
9
9
In this guide, you will learn step by step on how to integrate this library into your website.
10
10
11
- [ TEST THE LIBRARY] ( https://www.dynamsoft.com/survey/dlr/?utm_source=github&product=dlr&package=js )
11
+ [ GET THE LIBRARY] ( https://www.dynamsoft.com/survey/dlr/?utm_source=github&product=dlr&package=js )
12
12
13
13
** Table of Contents**
14
14
@@ -44,14 +44,21 @@ The complete code of the "Hello World" example is shown below
44
44
<html >
45
45
46
46
<body >
47
- <script src =" https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.1 /dist/dlr.js" ></script >
48
- <script src =" https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@2.0.3/dist/dce.js" ></script >
47
+ <script src =" https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.2 /dist/dlr.js" ></script >
48
+ <script src =" https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@2.0.3/dist/dce.js" ></script >
49
49
<script >
50
50
// initializes and uses the library
51
51
(async () => {
52
52
Dynamsoft .DCE .CameraEnhancer .defaultUIElementURL = Dynamsoft .DLR .LabelRecognizer .defaultUIElementURL ;
53
53
let cameraEnhancer = await Dynamsoft .DCE .CameraEnhancer .createInstance ();
54
-
54
+ Dynamsoft .DLR .LabelRecognizer .onResourcesLoadStarted = (resourcePath ) => {
55
+ console .log (" Loading " + resourcePath);
56
+ // Show a visual cue that a model file is being
57
+ };
58
+ Dynamsoft .DLR .LabelRecognizer .onResourcesLoaded = (resourcePath ) => {
59
+ console .log (" Finished loading " + resourcePath);
60
+ // Hide the visual cue
61
+ };
55
62
let recognizer = await Dynamsoft .DLR .LabelRecognizer .createInstance ({
56
63
runtimeSettings: " video-letter"
57
64
});
@@ -78,15 +85,15 @@ The complete code of the "Hello World" example is shown below
78
85
<!-- <a target="_blank" href="https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/master/1.hello-world/1.minimum-code.html" title="Code in Github">
79
86
<img src="https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/github.svg" alt="Code in Github" style="width:20px;height:20px;">
80
87
</a>
81
- -->
88
+ -->
82
89
<a target =" _blank " href =" https://jsfiddle.net/DynamsoftTeam/b1w8vm0t/ " title =" Run via JSFiddle " >
83
- <img src="https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/jsfiddle.svg" alt="Run via JSFiddle" style="width:20px;height:20px;">
90
+ <img src="https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/jsfiddle.svg" alt="Run via JSFiddle" width="20" height="20" style="width:20px;height:20px;">
84
91
</a >
85
- <!--
92
+ <!--
86
93
<a target="_blank" href="https://demo.dynamsoft.com/Samples/DBR/JS/1.hello-world/1.minimum-code.html?utm_source=github" title="Run in Dynamsoft">
87
94
<img src="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.0.0/svgs/solid/circle-play.svg" alt="Run in Dynamsoft" style="width:20px;height:20px;">
88
95
</a>
89
-
96
+
90
97
<a target="_blank" href="https://tst.dynamsoft.com/public/download/dbr/browser/code/helloworld-v8.8.7.zip?utm_source=github" title="Download from Dynamsoft">
91
98
<img src="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.0.0/svgs/solid/download.svg" alt="Download from Dynamsoft" style="width:20px;height:20px; ">
92
99
</a>-->
@@ -125,6 +132,8 @@ If the test doesn't go as expected, you can check out the [FAQ](#faq) or [contac
125
132
126
133
## Building your own page
127
134
135
+ We'll show all the steps required to build a web page for reading machine-readable zones (MRZ) on passports, visas, etc.
136
+
128
137
### Include the library
129
138
130
139
#### Use a CDN
@@ -134,14 +143,14 @@ The simplest way to include the library is to use either the [jsDelivr](https://
134
143
* jsDelivr
135
144
136
145
``` html
137
- <script src =" https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.1 /dist/dlr.js" ></script >
146
+ <script src =" https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.2 /dist/dlr.js" ></script >
138
147
<script src =" https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@2.0.3/dist/dce.js" ></script >
139
148
```
140
149
141
150
* UNPKG
142
151
143
152
``` html
144
- <script src =" https://unpkg.com/dynamsoft-label-recognizer@2.2.1 /dist/dlr.js" ></script >
153
+ <script src =" https://unpkg.com/dynamsoft-label-recognizer@2.2.2 /dist/dlr.js" ></script >
145
154
<script src =" https://unpkg.com/dynamsoft-camera-enhancer@2.0.3/dist/dce.js" ></script >
146
155
```
147
156
@@ -167,15 +176,15 @@ $ yarn add dynamsoft-camera-enhancer
167
176
* npm
168
177
169
178
```
170
- $ npm install dynamsoft-label-recognizer@2.2.1 --save
179
+ $ npm install dynamsoft-label-recognizer@2.2.2 --save
171
180
$ npm install dynamsoft-camera-enhancer@2.0.3 --save
172
181
```
173
182
174
183
Depending on how you downloaded the library and where you put it. You can typically include it like this:
175
184
176
185
``` html
177
- <script src =" /dlr-js-2.2.1 /dist/dlr.js" ></script >
178
- <script src =" /dlr-js-2.2.1 /dce/dist/dce.js" ></script >
186
+ <script src =" /dlr-js-2.2.2 /dist/dlr.js" ></script >
187
+ <script src =" /dlr-js-2.2.2 /dce/dist/dce.js" ></script >
179
188
```
180
189
181
190
or
@@ -197,7 +206,7 @@ The library requires a license to work, use the API `license` to specify the lic
197
206
198
207
``` javascript
199
208
Dynamsoft .DLR .LabelRecognizer .license =
200
- " YOUR-ORGANIZATION-ID or YOUR-HANDSHAKECODE or AN-OFFLINE-LICENSE or ANY-OTHER-TYPE-OF-SUPPORTED-LICENSE-STRING" ;
209
+ " YOUR-ORGANIZATION-ID or YOUR-HANDSHAKECODE or AN-OFFLINE-LICENSE or ANY-OTHER-TYPE-OF-SUPPORTED-LICENSE-STRING" ;
201
210
```
202
211
203
212
* Note* :
@@ -208,15 +217,34 @@ Dynamsoft.DLR.LabelRecognizer.license =
208
217
209
218
#### Specify the location of the "engine" files
210
219
211
- The "engine" files refer to * .worker.js, * .wasm.js and * .wasm, etc. which are loaded by the main library at runtime. This configuration option uses the API ` engineResourcePath ` and is often not required as these files usually are in the same location with the main library file (dlr.js). However, in cases where the engine files are not in the same location as the main library file (for example, with frameworks like Angular or React, dlr.js is compiled into another file), this configuration will be required.
220
+ The "engine" files refer to * .worker.js, * .wasm.js and * .wasm, etc. which are loaded by the main library at runtime as well as model files ( \* .data) which are necessary for the recognition of specific types of text . This configuration option uses the API ` engineResourcePath ` and is often not required as these files usually are in the same location with the main library file (dlr.js). However, in cases where the engine files are not in the same location as the main library file (for example, with frameworks like Angular or React, dlr.js is compiled into another file), this configuration will be required.
212
221
213
222
The following code uses the jsDelivr CDN, feel free to change it to your own location of these files.
214
223
215
224
``` javascript
216
- Dynamsoft .DLR .LabelRecognizer .engineResourcePath = " https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.1 /dist/" ;
225
+ Dynamsoft .DLR .LabelRecognizer .engineResourcePath = " https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.2 /dist/" ;
217
226
Dynamsoft .DCE .CameraEnhancer .engineResourcePath = " https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@2.0.3/dist/" ;
218
227
```
219
228
229
+ #### Add a visual cue about the loading of a .data file
230
+
231
+ The .data files are crucial for the recognition of certain types of text. For example, to read the MRZ zone on passports, the file MRZ.data must be loaded first. These .data files are loaded from the server on demand at runtime. At present, these files are quite large, for example, MRZ.data is about 10MB. Although these files are cached locally as soon as they are downloaded, loading them for the first time can be quite time-consuming. To make the process user-friendly, it's recommended to show a visual cue about the loading process to the user with the help of the APIs ` onResourcesLoadStarted ` , ` onResourcesLoadProgress ` and ` onResourcesLoaded ` :
232
+
233
+ ``` js
234
+ Dynamsoft .DLR .LabelRecognizer .onResourcesLoadStarted = (resourcePath ) => {
235
+ console .log (" Loading " + resourcePath);
236
+ // Show a visual cue that a model file is being
237
+ }
238
+ Dynamsoft .DLR .LabelRecognizer .onResourcesLoadProgress = (resourcePath , progress ) => {
239
+ console .log (resourcePath + " loading progress: " + progress .loaded + " /" + progress .total );
240
+ // Show the progress
241
+ }
242
+ Dynamsoft .DLR .LabelRecognizer .onResourcesLoaded = (resourcePath ) => {
243
+ console .log (" Finished loading " + resourcePath);
244
+ // Hide the visual cue
245
+ }
246
+ ```
247
+
220
248
### Interact with the library
221
249
222
250
#### Create a ` LabelRecognizer ` object
@@ -226,9 +254,7 @@ To use the library, we first create a `LabelRecognizer` object.
226
254
``` javascript
227
255
let recognizer = null ;
228
256
try {
229
- recognizer = await Dynamsoft .DLR .LabelRecognizer .createInstance ({
230
- runtimeSettings: " video-letter"
231
- });
257
+ recognizer = await Dynamsoft .DLR .LabelRecognizer .createInstance ();
232
258
} catch (ex) {
233
259
console .error (ex);
234
260
}
@@ -254,9 +280,9 @@ In some cases, a different camera might be required instead of the default one.
254
280
255
281
``` javascript
256
282
// set which camera and what resolution to use
257
- let allCameras = await enhancer .getAllCameras ();
258
- await enhancer .selectCamera (allCameras[0 ]);
259
- await enhancer .setResolution (1280 , 720 );
283
+ let allCameras = await cameraEnhancer .getAllCameras ();
284
+ await cameraEnhancer .selectCamera (allCameras[0 ]);
285
+ await cameraEnhancer .setResolution (1280 , 720 );
260
286
```
261
287
262
288
#### Set up the recognition process
@@ -308,8 +334,8 @@ Dynamsoft.DLR.LabelRecognizer.defaultUIElementURL = "THE-URL-TO-THE-FILE";
308
334
```
309
335
310
336
``` javascript
311
- await enhancer .setUIElement (Dynamsoft .DLR .LabelRecognizer .defaultUIElementURL );
312
- document .getElementById (' recognizerUI' ).appendChild (enhancer .getUIElement ());
337
+ await cameraEnhancer .setUIElement (Dynamsoft .DLR .LabelRecognizer .defaultUIElementURL );
338
+ document .getElementById (' recognizerUI' ).appendChild (cameraEnhancer .getUIElement ());
313
339
document .getElementsByClassName (' dce-btn-close' )[0 ].hidden = true ; // Hide the close button
314
340
```
315
341
@@ -325,18 +351,17 @@ document.getElementsByClassName('dce-btn-close')[0].hidden = true; // Hide the c
325
351
(async () => {
326
352
let cameraEnhancer = await Dynamsoft .DCE .CameraEnhancer .createInstance ();
327
353
await cameraEnhancer .setUIElement (document .getElementById (' div-video-container' ));
328
- let recognizer = await Dynamsoft .DLR .LabelRecognizer .createInstance ({
329
- runtimeSettings: " video-passportMRZ"
330
- });
354
+ let recognizer = await Dynamsoft .DLR .LabelRecognizer .createInstance ();
331
355
recognizer .cameraEnhancer = cameraEnhancer;
356
+ await recognizer .updateRuntimeSettingsFromString (" video-MRZ" );
332
357
recognizer .onFrameRead = results => {
333
358
for (let result of results) {
334
359
for (let lineResult of result .lineResults ) {
335
360
console .log (lineResult .text );
336
361
}
337
362
}
338
363
};
339
- recognizer .onUniqueRead = (txt , results ) => {
364
+ recognizer .onMRZRead = (txt , results ) => {
340
365
alert (txt);
341
366
};
342
367
await recognizer .startScanning (true );
@@ -384,7 +409,7 @@ After that, if you want to evaluate the library further, you can [register for a
384
409
385
410
This library requires the following features which are supported by all modern mainstream browsers:
386
411
387
- * ` WebAssembly ` , ` Blob ` , ` URL ` /` createObjectURL ` , ` Web Workers `
412
+ * ` WebAssembly ` , ` Blob ` , ` URL ` /` createObjectURL ` , ` Web Workers `
388
413
389
414
The above four features are required for the library to work.
390
415
0 commit comments