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