Skip to content

Commit 5edaea2

Browse files
update to internal commit cb4e9b34
1 parent b0d089a commit 5edaea2

File tree

1 file changed

+78
-68
lines changed
  • programming/javascript/user-guide

1 file changed

+78
-68
lines changed

programming/javascript/user-guide/index.md

Lines changed: 78 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ In this guide, you'll learn step-by-step how to build such a simple solution in
2424
- [Run the example](#run-the-example)
2525
- [Building your own page](#building-your-own-page)
2626
- [Include the SDK](#include-the-sdk)
27-
- [Use a public CDN](#use-a-public-cdn)
28-
- [Host the SDK yourself (Optional)](#host-the-sdk-yourself-optional)
27+
- [Use a CDN](#use-a-cdn)
28+
- [Host the SDK yourself](#host-the-sdk-yourself)
2929
- [Specify the location of the "engine" files (optional)](#specify-the-location-of-the-engine-files-optional)
3030
- [Define necessary HTML elements](#define-necessary-html-elements)
3131
- [Prepare the SDK for the task](#prepare-the-sdk-for-the-task)
@@ -55,7 +55,12 @@ The following sample code sets up the SDK and implements boundary detection on a
5555

5656
<head>
5757
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
58-
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-document-normalizer-bundle@2.2.1000/dist/ddn.js"></script>
58+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-core@3.2.10/dist/core.js"></script>
59+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-license@3.2.10/dist/license.js"></script>
60+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-utility@1.2.10/dist/utility.js"></script>
61+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-document-normalizer@2.2.10/dist/ddn.js"></script>
62+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-capture-vision-router@2.2.10/dist/cvr.js"></script>
63+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@4.0.2/dist/dce.js"></script>
5964
</head>
6065

6166
<body>
@@ -67,26 +72,26 @@ The following sample code sets up the SDK and implements boundary detection on a
6772
const cameraViewContainer = document.querySelector(
6873
"#cameraViewContainer"
6974
);
70-
let cvRouter;
75+
let router;
7176
let cameraEnhancer;
7277
Dynamsoft.License.LicenseManager.initLicense(
7378
"DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"
7479
);
7580
Dynamsoft.Core.CoreModule.loadWasm(["DDN"]);
7681
7782
(async function() {
78-
cvRouter = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
83+
router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
7984
let view = await Dynamsoft.DCE.CameraView.createInstance();
8085
cameraEnhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance(
8186
view
8287
);
8388
cameraViewContainer.append(view.getUIElement());
84-
cvRouter.setInput(cameraEnhancer);
89+
router.setInput(cameraEnhancer);
8590
})();
8691
async function startDetection() {
8792
cameraViewContainer.style.display = "block";
8893
await cameraEnhancer.open();
89-
await cvRouter.startCapturing("DetectDocumentBoundaries_Default");
94+
await router.startCapturing("DetectDocumentBoundaries_Default");
9095
};
9196
</script>
9297
</body>
@@ -102,13 +107,13 @@ The following sample code sets up the SDK and implements boundary detection on a
102107

103108
- `Dynamsoft.Core.CoreModule.loadWasm(["DDN"])`: preloads the `DocumentNormalizer` module, saving time in preparing for document border detection and image normalization.
104109

105-
- `Dynamsoft.CVR.CaptureVisionRouter.createInstance()`: initializes the `cvRouter` variable by creating an instance of the `CaptureVisionRouter` class. An instance of `CaptureVisionRouter` is the core of any solution based on Dynamsoft Capture Vision architecture.
110+
- `Dynamsoft.CVR.CaptureVisionRouter.createInstance()`: initializes the `router` variable by creating an instance of the `CaptureVisionRouter` class. An instance of `CaptureVisionRouter` is the core of any solution based on Dynamsoft Capture Vision architecture.
106111

107112
> Read more on [what is CaptureVisionRouter](https://www.dynamsoft.com/capture-vision/docs/core/architecture/#capture-vision-router)
108113
109114
- `Dynamsoft.DCE.CameraEnhancer.createInstance(view)`: initializes the `cameraEnhancer` variable by creating an instance of the `CameraEnhancer` class.
110115

111-
- `setInput()`: `cvRouter` connects to the image source through the [Image Source Adapter](https://www.dynamsoft.com/capture-vision/docs/web//programming/javascript/api-reference/core/image-source-adapter.html) interface with the method `setInput()`.
116+
- `setInput()`: `router` connects to the image source through the [Image Source Adapter](https://www.dynamsoft.com/capture-vision/docs/web//programming/javascript/api-reference/core/image-source-adapter.html) interface with the method `setInput()`.
112117

113118
> The image source in our case is a CameraEnhancer object created with `Dynamsoft.DCE.CameraEnhancer.createInstance(view)`
114119
@@ -168,46 +173,33 @@ To utilize the SDK, the initial step involves including the corresponding resour
168173
* `cvr.js`: Required, introduces the `CaptureVisionRouter` class, which governs the entire image processing workflow.
169174
* `dce.js`: Recommended, comprises classes that offer camera support and basic user interface functionalities.
170175

171-
For simplification, starting from version 2.2.10, we introduced ddn.bundle.js. Including this file is equivalent to incorporating all six packages.
172-
173-
* dynamsoft-core@3.2.30/dist/core.js
174-
* dynamsoft-license@3.2.21/dist/license.js
175-
* dynamsoft-utility@1.2.20/dist/utility.js
176-
* dynamsoft-document-normalizer@3.2.30/dist/ddn.js
177-
* dynamsoft-capture-vision-router@2.2.30/dist/cvr.js
178-
* dynamsoft-camera-enhancer@4.0.3/dist/dce.js
179-
180-
Equivalent to
181-
182-
* dynamsoft-document-normalizer-bundle@2.2.1000/dist/ddn.bundle.js
183-
184-
In the following chapters, we will use `ddn.bundle.js`.
185-
186-
#### Use a public CDN
176+
#### Use a CDN
187177

188178
The simplest way to include the SDK is to use either the [jsDelivr](https://jsdelivr.com/) or [UNPKG](https://unpkg.com/) CDN.
189179

190180
- jsDelivr
191181

192182
```html
193-
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-document-normalizer-bundle@2.2.1000/dist/ddn.js"></script>
183+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-core@3.2.10/dist/core.js"></script>
184+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-license@3.2.10/dist/license.js"></script>
185+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-utility@1.2.10/dist/utility.js"></script>
186+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-document-normalizer@2.2.10/dist/ddn.js"></script>
187+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-capture-vision-router@2.2.10/dist/cvr.js"></script>
188+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@4.0.2/dist/dce.js"></script>
194189
```
195190

196191
- UNPKG
197192

198193
```html
199-
<script src="https://unpkg.com/dynamsoft-document-normalizer-bundle@2.2.1000/dist/ddn.js"></script>
200-
```
201-
202-
- In some rare cases (such as some restricted areas), you might not be able to access the CDN. If this happens, you can use the following files for the test.
203-
204-
```html
205-
<script src="download2.dynamsoft.com/packages/dynamsoft-document-normalizer-bundle@2.2.1000/dist/ddn.js"></script>
194+
<script src="https://unpkg.com/dynamsoft-core@3.2.10/dist/core.js"></script>
195+
<script src="https://unpkg.com/dynamsoft-license@3.2.10/dist/license.js"></script>
196+
<script src="https://unpkg.com/dynamsoft-utility@1.2.10/dist/utility.js"></script>
197+
<script src="https://unpkg.com/dynamsoft-document-normalizer@2.2.10/dist/ddn.js"></script>
198+
<script src="https://unpkg.com/dynamsoft-capture-vision-router@2.2.10/dist/cvr.js"></script>
199+
<script src="https://unpkg.com/dynamsoft-camera-enhancer@4.0.2/dist/dce.js"></script>
206200
```
207201

208-
However, please **DO NOT** use `download2.dynamsoft.com` resources in a production application as they are for temporary testing purposes only. Instead, you can try hosting the SDK yourself.
209-
210-
#### Host the SDK yourself (Optional)
202+
#### Host the SDK yourself
211203

212204
Besides using the CDN, you can also download the SDK and host its files on your own website / server before including it in your application. When using a CDN, resources related to `dynamsoft-image-processing` and `dynamsoft-capture-vision-std` are automatically loaded over the network; When using them locally, these two packages need to be configured manually.
213205

@@ -217,35 +209,53 @@ Options to download the SDK:
217209

218210
[Download the JavaScript ZIP package](https://www.dynamsoft.com/document-normalizer/downloads/?ver=2.2.10&utm_source=guide)
219211

220-
- npm
212+
- yarn
221213

222214
```cmd
223-
npm i dynamsoft-document-normalizer-bundle@2.2.1000 -E
224-
npm i dynamsoft-capture-vision-std@1.2.0 -E
225-
npm i dynamsoft-image-processing@2.2.10 -E
215+
yarn add dynamsoft-core@3.2.10 --save
216+
yarn add dynamsoft-license@3.2.10 --save
217+
yarn add dynamsoft-utility@1.2.10 --save
218+
yarn add dynamsoft-document-normalizer@2.2.10 --save
219+
yarn add dynamsoft-capture-vision-router@2.2.10 --save
220+
yarn add dynamsoft-camera-enhancer@4.0.2 --save
221+
yarn add dynamsoft-capture-vision-std@1.2.0 --save
222+
yarn add dynamsoft-image-processing@2.2.10 --save
226223
```
227224

228-
- yarn
225+
- npm
229226

230227
```cmd
231-
yarn add dynamsoft-document-normalizer-bundle@2.2.1000 -E
232-
yarn add dynamsoft-capture-vision-std@1.2.0 -E
233-
yarn add dynamsoft-image-processing@2.2.10 -E
228+
npm install dynamsoft-core@3.2.10 --save
229+
npm install dynamsoft-license@3.2.10 --save
230+
npm install dynamsoft-utility@1.2.10 --save
231+
npm install dynamsoft-document-normalizer@2.2.10 --save
232+
npm install dynamsoft-capture-vision-router@2.2.10 --save
233+
npm install dynamsoft-camera-enhancer@4.0.2 --save
234+
npm install dynamsoft-capture-vision-std@1.2.0 --save
235+
npm install dynamsoft-image-processing@2.2.10 --save
234236
```
235237

236238
Depending on how you downloaded the SDK and where you put it, you can typically include it like this:
237239

238-
- From the website
239-
240240
```html
241241
<!-- Upon extracting the zip package into your project, you can generally include it in the following manner -->
242-
<script src="./dynamsoft/distributables/dynamsoft-document-normalizer-bundle@2.2.1000/dist/ddn.js"></script>
242+
<script src="./dynamsoft/distributables/dynamsoft-core@3.2.10/dist/core.js"></script>
243+
<script src="./dynamsoft/distributables/dynamsoft-license@3.2.10/dist/license.js"></script>
244+
<script src="./dynamsoft/distributables/dynamsoft-utility@1.2.10/dist/utility.js"></script>
245+
<script src="./dynamsoft/distributables/dynamsoft-document-normalizer@2.2.10/dist/ddn.js"></script>
246+
<script src="./dynamsoft/distributables/dynamsoft-capture-vision-router@2.2.10/dist/cvr.js"></script>
247+
<script src="./dynamsoft/distributables/dynamsoft-camera-enhancer@4.0.2/dist/dce.js"></script>
243248
```
244249

245-
- yarn or npm
250+
or
246251

247252
```html
248-
<script src="./node_modules/dynamsoft-document-normalizer-bundle@2.2.1000/dist/ddn.js"></script>
253+
<script src="./node_modules/dynamsoft-core/dist/core.js"></script>
254+
<script src="./node_modules/dynamsoft-license/dist/license.js"></script>
255+
<script src="./node_modules/dynamsoft-utility/dist/utility.js"></script>
256+
<script src="./node_modules/dynamsoft-document-normalizer/dist/ddn.js"></script>
257+
<script src="./node_modules/dynamsoft-capture-vision-router/dist/cvr.js"></script>
258+
<script src="./node_modules/dynamsoft-camera-enhancer/dist/dce.js"></script>
249259
```
250260

251261
#### Specify the location of the "engine" files (optional)
@@ -263,7 +273,7 @@ Object.assign(Dynamsoft.Core.CoreModule.engineResourcePaths, {
263273
cvr: "https://cdn.jsdelivr.net/npm/dynamsoft-capture-vision-router@2.2.10/dist/",
264274
dce: "https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@4.0.2/dist/",
265275
std: "https://cdn.jsdelivr.net/npm/dynamsoft-capture-vision-std@1.2.0/dist/",
266-
dip: "https://cdn.jsdelivr.net/npm/dynamsoft-image-processing@2.2.10/dist/"
276+
dip: "https://cdn.jsdelivr.net/npm/dynamsoft-image-processing@2.2.10/dist/",
267277
});
268278
```
269279

@@ -295,7 +305,7 @@ The following function executes as soon as the page loads to get the SDK prepare
295305

296306
```js
297307
let cameraEnhancer = null;
298-
let cvRouter = null;
308+
let router = null;
299309
let items;
300310
let layer;
301311
let originalImage;
@@ -318,8 +328,8 @@ async function initDCE() {
318328

319329
let cvrReady = (async function initCVR() {
320330
await initDCE();
321-
cvRouter = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
322-
cvRouter.setInput(cameraEnhancer);
331+
router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
332+
router.setInput(cameraEnhancer);
323333
})();
324334
```
325335

@@ -338,20 +348,20 @@ let cvrReady = (async function initCVR() {
338348
* Also, make sure the original image is returned after it has been processed.
339349
*/
340350
await initDCE();
341-
cvRouter = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
342-
cvRouter.setInput(cameraEnhancer);
351+
router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
352+
router.setInput(cameraEnhancer);
343353
/**
344354
* Sets the result types to be returned.
345355
* Because we need to normalize a document from the original image later, here we set the return result type to
346356
* include both the quadrilateral and original image data.
347357
*/
348-
let newSettings = await cvRouter.getSimplifiedSettings("DetectDocumentBoundaries_Default");
358+
let newSettings = await router.getSimplifiedSettings("DetectDocumentBoundaries_Default");
349359
newSettings.capturedResultItemTypes = Dynamsoft.Core.EnumCapturedResultItemType.CRIT_DETECTED_QUAD | Dynamsoft.Core.EnumCapturedResultItemType.CRIT_ORIGINAL_IMAGE;
350-
await cvRouter.updateSettings("DetectDocumentBoundaries_Default", newSettings)
360+
await router.updateSettings("DetectDocumentBoundaries_Default", newSettings)
351361
/* Defines the result receiver for the task.*/
352362
const resultReceiver = new Dynamsoft.CVR.CapturedResultReceiver();
353363
resultReceiver.onCapturedResultReceived = handleCapturedResult;
354-
cvRouter.addResultReceiver(resultReceiver);
364+
router.addResultReceiver(resultReceiver);
355365
})();
356366

357367
async function handleCapturedResult(result) {
@@ -371,7 +381,7 @@ async function startDetecting() {
371381
/* Starts streaming the video. */
372382
await cameraEnhancer.open();
373383
/* Uses the built-in template "DetectDocumentBoundaries_Default" to start a continuous boundary detection task. */
374-
await cvRouter.startCapturing("DetectDocumentBoundaries_Default");
384+
await router.startCapturing("DetectDocumentBoundaries_Default");
375385
})());
376386
} catch (ex) {
377387
let errMsg = ex.message || ex;
@@ -384,15 +394,15 @@ async function startDetecting() {
384394
The steps of the workflow is as follows
385395

386396
1. `cameraEnhancer` streams the video, captures live video frames and stores them in a buffer.
387-
2. `cvRouter` gets the video frames from `Image Source Adapter` and passes them to be processed by an internal `DocumentNormalizer` instance. The `cameraEnhancer` used here is a special implementation of the `Image Source Adapter`.
388-
3. The internal `DocumentNormalizer` instance returns the found document boundaries, known as `quadsResultItems`, to `cvRouter`.
389-
4. The `cvRouter` can output all types of CapturedResults that need to be captured through the `onCapturedResultReceived` callback function. In this example code we use the callback function to output `quadsResultItems` and `originalImageResultItem`.
397+
2. `router` gets the video frames from `Image Source Adapter` and passes them to be processed by an internal `DocumentNormalizer` instance. The `cameraEnhancer` used here is a special implementation of the `Image Source Adapter`.
398+
3. The internal `DocumentNormalizer` instance returns the found document boundaries, known as `quadsResultItems`, to `router`.
399+
4. The `router` can output all types of CapturedResults that need to be captured through the `onCapturedResultReceived` callback function. In this example code we use the callback function to output `quadsResultItems` and `originalImageResultItem`.
390400

391401
> Also note that the `quadsResultItems` are drawn over the video automatically to show the detection in action.
392402
393403
*Note*:
394404

395-
* `cvRouter` is engineered to consistently request images from the image source.
405+
* `router` is engineered to consistently request images from the image source.
396406
* Three preset templates are at your disposal for document normalizing or border detection:
397407

398408
| Template Name | Function |
@@ -431,7 +441,7 @@ async function handleCapturedResult(result) {
431441
if (frameCount === 30) {
432442
frameCount = 0;
433443
/* Stops the detection task since we assume we have found a good boundary. */
434-
cvRouter.stopCapturing();
444+
router.stopCapturing();
435445
/* Hides the cameraView and shows the imageEditorView. */
436446
cameraViewContainer.style.display = "none";
437447
imageEditorViewContainer.style.display = "block";
@@ -499,12 +509,12 @@ btnNormalize.addEventListener("click", async () => {
499509
* Sets the coordinates of the ROI (region of interest)
500510
* in the built-in template "NormalizeDocument_Default".
501511
*/
502-
let newSettings = await cvRouter.getSimplifiedSettings("NormalizeDocument_Default");
512+
let newSettings = await router.getSimplifiedSettings("NormalizeDocument_Default");
503513
newSettings.roiMeasuredInPercentage = 0;
504514
newSettings.roi.points = quad.points;
505-
await cvRouter.updateSettings("NormalizeDocument_Default", newSettings);
515+
await router.updateSettings("NormalizeDocument_Default", newSettings);
506516
/* Executes the normalization and shows the result on the page. */
507-
let normalizeResult = await cvRouter.capture(originalImageData, "NormalizeDocument_Default");
517+
let normalizeResult = await router.capture(originalImageData, "NormalizeDocument_Default");
508518
if (normalizeResult.items[0]) {
509519
normalizedImageContainer.append(normalizeResult.items[0].toCanvas());
510520
}
@@ -550,7 +560,7 @@ async function restartDetecting() {
550560
btnRestart.style.display = "none";
551561
btnNormalize.disabled = true;
552562
layer.clearDrawingItems()
553-
await cvRouter.startCapturing("DetectDocumentBoundaries_Default");
563+
await router.startCapturing("DetectDocumentBoundaries_Default");
554564
}
555565
```
556566
<!--TODO-->

0 commit comments

Comments
 (0)