|
1 | 1 | <!DOCTYPE html>
|
2 | 2 | <html lang="en">
|
3 |
| - <head> |
4 |
| - <meta charset="utf-8" /> |
5 |
| - <meta name="viewport" content="width=device-width,initial-scale=1.0" /> |
6 |
| - <meta |
7 |
| - name="description" |
8 |
| - content="Quickly read barcodes with Dynamsoft Barcode Reader from a live camera stream." |
9 |
| - /> |
10 |
| - <meta name="keywords" content="barcode, camera, es6" /> |
11 |
| - <link rel="canonical" href="https://demo.dynamsoft.com/Samples/DBR/JS/hello-world/es6.html" /> |
12 |
| - <title>Dynamsoft Barcode Reader Sample - Hello World for ES6 (Decode via Camera)</title> |
13 |
| - </head> |
| 3 | + <head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <meta name="viewport" content="width=device-width,initial-scale=1.0" /> |
| 6 | + <meta |
| 7 | + name="description" |
| 8 | + content="Quickly read barcodes with Dynamsoft Barcode Reader from a live camera stream." |
| 9 | + /> |
| 10 | + <meta name="keywords" content="barcode, camera, es6" /> |
| 11 | + <link |
| 12 | + rel="canonical" |
| 13 | + href="https://demo.dynamsoft.com/Samples/DBR/JS/hello-world/es6.html" |
| 14 | + /> |
| 15 | + <title> |
| 16 | + Dynamsoft Barcode Reader Sample - Hello World for ES6 (Decode via Camera) |
| 17 | + </title> |
| 18 | + </head> |
14 | 19 |
|
15 |
| - <body> |
16 |
| - <h1>Hello World for ES6 (Decode via Camera)</h1> |
17 |
| - <div id="camera-view-container" style="width: 100%; height: 80vh"></div> |
18 |
| - Results:<br /> |
19 |
| - <div id="results" style="width: 100%; height: 10vh; overflow: auto"></div> |
20 |
| - <script type="module"> |
21 |
| - import { |
22 |
| - CoreModule, |
23 |
| - LicenseManager, |
24 |
| - CaptureVisionRouter, |
25 |
| - CameraView, |
26 |
| - CameraEnhancer, |
27 |
| - MultiFrameResultCrossFilter, |
28 |
| - } from "https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@10.2.1000/dist/dbr.bundle.mjs"; |
| 20 | + <body> |
| 21 | + <h1>Hello World for ES6 (Decode via Camera)</h1> |
| 22 | + <div id="camera-view-container" style="width: 100%; height: 80vh"></div> |
| 23 | + Results:<br /> |
| 24 | + <div id="results" style="width: 100%; height: 10vh; overflow: auto"></div> |
| 25 | + <script type="module"> |
| 26 | + import { |
| 27 | + CoreModule, |
| 28 | + LicenseManager, |
| 29 | + CaptureVisionRouter, |
| 30 | + CameraView, |
| 31 | + CameraEnhancer, |
| 32 | + MultiFrameResultCrossFilter, |
| 33 | + } from "https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@10.2.1000/dist/dbr.bundle.mjs"; |
29 | 34 |
|
30 |
| - /** LICENSE ALERT - README |
31 |
| - * To use the library, you need to first specify a license key using the API "initLicense()" as shown below. |
32 |
| - */ |
| 35 | + /** LICENSE ALERT - README |
| 36 | + * To use the library, you need to first specify a license key using the API "initLicense()" as shown below. |
| 37 | + */ |
33 | 38 |
|
34 |
| - LicenseManager.initLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"); |
| 39 | + LicenseManager.initLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"); |
35 | 40 |
|
36 |
| - /** |
37 |
| - * You can visit https://www.dynamsoft.com/customer/license/trialLicense?utm_source=github&product=dbr&package=js to get your own trial license good for 30 days. |
38 |
| - * Note that if you downloaded this sample from Dynamsoft while logged in, the above license key may already be your own 30-day trial license. |
39 |
| - * For more information, see https://www.dynamsoft.com/barcode-reader/programming/javascript/user-guide/?ver=10.2.10&utm_source=github#specify-the-license or contact support@dynamsoft.com. |
40 |
| - * LICENSE ALERT - THE END |
41 |
| - */ |
| 41 | + /** |
| 42 | + * You can visit https://www.dynamsoft.com/customer/license/trialLicense?utm_source=github&product=dbr&package=js to get your own trial license good for 30 days. |
| 43 | + * Note that if you downloaded this sample from Dynamsoft while logged in, the above license key may already be your own 30-day trial license. |
| 44 | + * For more information, see https://www.dynamsoft.com/barcode-reader/programming/javascript/user-guide/?ver=10.2.10&utm_source=github#specify-the-license or contact support@dynamsoft.com. |
| 45 | + * LICENSE ALERT - THE END |
| 46 | + */ |
42 | 47 |
|
43 |
| - CoreModule.engineResourcePaths = { |
44 |
| - std: "https://cdn.jsdelivr.net/npm/dynamsoft-capture-vision-std@1.2.10/dist/", |
45 |
| - dip: "https://cdn.jsdelivr.net/npm/dynamsoft-image-processing@2.2.30/dist/", |
46 |
| - core: "https://cdn.jsdelivr.net/npm/dynamsoft-core@3.2.30/dist/", |
47 |
| - license: "https://cdn.jsdelivr.net/npm/dynamsoft-license@3.2.21/dist/", |
48 |
| - cvr: "https://cdn.jsdelivr.net/npm/dynamsoft-capture-vision-router@2.2.30/dist/", |
49 |
| - dbr: "https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader@10.2.10/dist/", |
50 |
| - dce: "https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@4.0.3/dist/", |
51 |
| - }; |
| 48 | + CoreModule.engineResourcePaths = { |
| 49 | + std: "https://cdn.jsdelivr.net/npm/dynamsoft-capture-vision-std@1.2.10/dist/", |
| 50 | + dip: "https://cdn.jsdelivr.net/npm/dynamsoft-image-processing@2.2.30/dist/", |
| 51 | + core: "https://cdn.jsdelivr.net/npm/dynamsoft-core@3.2.30/dist/", |
| 52 | + license: "https://cdn.jsdelivr.net/npm/dynamsoft-license@3.2.21/dist/", |
| 53 | + cvr: "https://cdn.jsdelivr.net/npm/dynamsoft-capture-vision-router@2.2.30/dist/", |
| 54 | + dbr: "https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader@10.2.10/dist/", |
| 55 | + dce: "https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@4.0.3/dist/", |
| 56 | + }; |
52 | 57 |
|
53 |
| - // Optional. Used to load wasm resources in advance, reducing latency between video playing and barcode decoding. |
54 |
| - CoreModule.loadWasm(["DBR"]); |
| 58 | + // Optional. Used to load wasm resources in advance, reducing latency between video playing and barcode decoding. |
| 59 | + CoreModule.loadWasm(["DBR"]); |
55 | 60 |
|
56 |
| - (async function () { |
57 |
| - try { |
58 |
| - // Create a `CameraEnhancer` instance for camera control and a `CameraView` instance for UI control. |
59 |
| - const cameraView = await CameraView.createInstance(); |
60 |
| - const cameraEnhancer = await CameraEnhancer.createInstance(cameraView); |
61 |
| - // Get default UI and append it to DOM. |
62 |
| - document.querySelector("#camera-view-container").append(cameraView.getUIElement()); |
| 61 | + (async function () { |
| 62 | + try { |
| 63 | + // Create a `CameraEnhancer` instance for camera control and a `CameraView` instance for UI control. |
| 64 | + const cameraView = await CameraView.createInstance(); |
| 65 | + const cameraEnhancer = await CameraEnhancer.createInstance( |
| 66 | + cameraView |
| 67 | + ); |
| 68 | + // Get default UI and append it to DOM. |
| 69 | + document |
| 70 | + .querySelector("#camera-view-container") |
| 71 | + .append(cameraView.getUIElement()); |
63 | 72 |
|
64 |
| - // Create a `CaptureVisionRouter` instance and set `CameraEnhancer` instance as its image source. |
65 |
| - const cvRouter = await CaptureVisionRouter.createInstance(); |
66 |
| - cvRouter.setInput(cameraEnhancer); |
| 73 | + // Create a `CaptureVisionRouter` instance and set `CameraEnhancer` instance as its image source. |
| 74 | + const cvRouter = await CaptureVisionRouter.createInstance(); |
| 75 | + cvRouter.setInput(cameraEnhancer); |
67 | 76 |
|
68 |
| - // Define a callback for results. |
69 |
| - cvRouter.addResultReceiver({ |
70 |
| - onDecodedBarcodesReceived: (result) => { |
71 |
| - if (!result.barcodeResultItems.length) return; |
| 77 | + // Define a callback for results. |
| 78 | + cvRouter.addResultReceiver({ |
| 79 | + onDecodedBarcodesReceived: (result) => { |
| 80 | + if (!result.barcodeResultItems.length) return; |
72 | 81 |
|
73 |
| - const resultsContainer = document.querySelector("#results"); |
74 |
| - resultsContainer.textContent = ""; |
75 |
| - console.log(result); |
76 |
| - for (let item of result.barcodeResultItems) { |
77 |
| - resultsContainer.append( |
78 |
| - `${item.formatString}: ${item.text}`, |
79 |
| - document.createElement("br"), |
80 |
| - document.createElement("hr") |
81 |
| - ); |
82 |
| - } |
83 |
| - }, |
84 |
| - }); |
| 82 | + const resultsContainer = document.querySelector("#results"); |
| 83 | + resultsContainer.textContent = ""; |
| 84 | + console.log(result); |
| 85 | + for (let item of result.barcodeResultItems) { |
| 86 | + resultsContainer.textContent += `${item.formatString}: ${item.text}\n\n`; |
| 87 | + } |
| 88 | + }, |
| 89 | + }); |
85 | 90 |
|
86 |
| - // Filter out unchecked and duplicate results. |
87 |
| - const filter = new MultiFrameResultCrossFilter(); |
88 |
| - // Filter out unchecked barcodes. |
89 |
| - filter.enableResultCrossVerification("barcode", true); |
90 |
| - // Filter out duplicate barcodes within 3 seconds. |
91 |
| - filter.enableResultDeduplication("barcode", true); |
92 |
| - await cvRouter.addResultFilter(filter); |
| 91 | + // Filter out unchecked and duplicate results. |
| 92 | + const filter = new MultiFrameResultCrossFilter(); |
| 93 | + // Filter out unchecked barcodes. |
| 94 | + filter.enableResultCrossVerification("barcode", true); |
| 95 | + // Filter out duplicate barcodes within 3 seconds. |
| 96 | + filter.enableResultDeduplication("barcode", true); |
| 97 | + await cvRouter.addResultFilter(filter); |
93 | 98 |
|
94 |
| - // Open camera and start scanning single barcode. |
95 |
| - await cameraEnhancer.open(); |
96 |
| - await cvRouter.startCapturing("ReadSingleBarcode"); |
97 |
| - } catch (ex) { |
98 |
| - let errMsg = ex.message || ex; |
99 |
| - console.error(errMsg); |
100 |
| - alert(errMsg); |
101 |
| - } |
102 |
| - })(); |
103 |
| - </script> |
104 |
| - </body> |
| 99 | + // Open camera and start scanning single barcode. |
| 100 | + await cameraEnhancer.open(); |
| 101 | + await cvRouter.startCapturing("ReadSingleBarcode"); |
| 102 | + } catch (ex) { |
| 103 | + let errMsg = ex.message || ex; |
| 104 | + console.error(errMsg); |
| 105 | + alert(errMsg); |
| 106 | + } |
| 107 | + })(); |
| 108 | + </script> |
| 109 | + </body> |
105 | 110 | </html>
|
0 commit comments