Skip to content

Commit 071d1f4

Browse files
committed
update
1 parent a5c7d53 commit 071d1f4

2 files changed

Lines changed: 106 additions & 54 deletions

File tree

use-case/read-a-drivers-license.html

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,6 @@ <h1>Read A Driver's License</h1>
283283
Dynamsoft.License.LicenseManager.initLicense(
284284
"DLS2eyJoYW5kc2hha2VDb2RlIjoiNjY2Ni03Nzc3IiwibWFpblNlcnZlclVSTCI6Imh0dHBzOi8vMTkyLjE2OC44LjEyMi9kbHMvIiwib3JnYW5pemF0aW9uSUQiOiI2NjY2IiwiY2hlY2tDb2RlIjoxNTEyMTgzMzg3fQ=="
285285
);
286-
Dynamsoft.DCP.CodeParser.license =
287-
"DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9";
288286

289287
/**
290288
* 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.
@@ -293,6 +291,17 @@ <h1>Read A Driver's License</h1>
293291
* LICENSE ALERT - THE END
294292
*/
295293

294+
/** LICENSE ALERT - README
295+
* DCP
296+
* To use the library, you need to first specify a license key using the API "license" as shown below.
297+
*/
298+
Dynamsoft.DCP.CodeParser.license =
299+
"DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9";
300+
/**
301+
* You can contact Dynamsoft Support Team (https://www.dynamsoft.com/Company/Contact.aspx) to obtain a license.
302+
* LICENSE ALERT - THE END
303+
*/
304+
296305
// Preload "BarcodeReader" module for reading barcodes. It will save time on the initial decoding by skipping the module loading.
297306
Dynamsoft.CVR.CaptureVisionRouter.preloadModule(["DBR"]).catch((ex) => {
298307
let errMsg;
@@ -476,7 +485,7 @@ <h1>Read A Driver's License</h1>
476485
cameraEnhancer.close();
477486
cameraEnhancer.singleFrameMode = "disabled";
478487
await cameraEnhancer.open();
479-
await router.startCapturing("ReadSingleBarcode");
488+
await router.startCapturing("ReadDenseBarcodes");
480489

481490
timer = setTimeout(() => {
482491
if (cameraEnhancer.singleFrameMode === "disabled") {

use-case/show-result-texts-on-the-video.html

Lines changed: 94 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,36 @@
1010
<meta name="keywords" content="read barcode from camera, custom style" />
1111
<link
1212
rel="canonical"
13-
href="https://demo.dynamsoft.com/Samples/DBR/JS/4.use-case/3.show-result-texts-on-the-video.html"
13+
href="https://demo.dynamsoft.com/Samples/DBR/JS/use-case/show-result-texts-on-the-video.html"
1414
/>
1515
<title>
1616
Dynamsoft Barcode Reader Sample - Show Result Texts on the Video
1717
</title>
18+
<script src="https://npm.scannerproxy.com/cdn/@dynamsoft/dynamsoft-core@3.0.20-dev-20231010152155/dist/core.js"></script>
19+
<script src="https://npm.scannerproxy.com/cdn/@dynamsoft/dynamsoft-utility@1.0.10-dev-20231023103736/dist/utility.js"></script>
20+
<script src="https://npm.scannerproxy.com/cdn/@dynamsoft/dynamsoft-barcode-reader@10.0.20-dev-20231020140243/dist/dbr.js"></script>
21+
<script src="https://npm.scannerproxy.com/cdn/@dynamsoft/dynamsoft-capture-vision-router@2.0.20-dev-20231027145739/dist/cvr.js"></script>
22+
<script src="https://npm.scannerproxy.com/cdn/@dynamsoft/dynamsoft-camera-enhancer@4.0.1-dev-20231023131759/dist/dce.js"></script>
1823
<style>
1924
.bubble-box-container {
2025
position: absolute;
2126
display: flex;
2227
justify-content: center;
2328
}
24-
.bubble-box-container>.bubble-box{
29+
.bubble-box-container > .bubble-box {
2530
position: absolute;
2631
width: max-content;
2732
max-width: 20rem;
2833
background: white;
29-
border-radius: 4px;
34+
border-radius: 4px;
3035
padding: 4px;
3136
word-break: break-all;
3237
word-wrap: break-word;
33-
box-shadow: 5px 5px 5px 3px rgba(0,0,0,0.2);
38+
box-shadow: 5px 5px 5px 3px rgba(0, 0, 0, 0.2);
3439
transform: translateY(calc(-100% - 4px));
3540
}
36-
.bubble-box-container>.bubble-box::after{
37-
content: '';
41+
.bubble-box-container > .bubble-box::after {
42+
content: "";
3843
position: absolute;
3944
bottom: -8px;
4045
left: calc(50% - 8px);
@@ -47,96 +52,128 @@
4752
<body>
4853
<div id="div-ui-container" style="width: 100%; height: 90vh"></div>
4954
<div id="div-information-containers"></div>
50-
<!--
51-
This sample makes use of the library hosted by the CDN jsDelivr. If you would rather use the
52-
library offline. Please see the guide on how to host the library:
53-
https://www.dynamsoft.com/barcode-reader/programming/javascript/user-guide/?ver=latest#host-the-library-yourself-recommended
54-
-->
55-
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@9.6.31/dist/dbr.js"></script>
5655
<script>
5756
if (location.protocol === "file:") {
58-
const message = `The page is opened via file:// and "BarcodeScanner" may not work properly. Please open the page via https:// or host it on "http://localhost/".`;
57+
const message = `The page is opened via file:// and our SDKs may not work properly. Please open the page via https:// or host it on "http://localhost/".`;
5958
console.warn(message);
6059
alert(message);
6160
}
6261
</script>
6362
<script>
6463
/** LICENSE ALERT - README
65-
* To use the library, you need to first specify a license key using the API "license" as shown below.
64+
* To use the library, you need to first specify a license key using the API "initLicense()" as shown below.
6665
*/
6766

68-
Dynamsoft.DBR.BarcodeReader.license =
69-
"DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9";
67+
Dynamsoft.License.LicenseManager.initLicense(
68+
"DLS2eyJoYW5kc2hha2VDb2RlIjoiNjY2Ni03Nzc3IiwibWFpblNlcnZlclVSTCI6Imh0dHBzOi8vMTkyLjE2OC44LjEyMi9kbHMvIiwib3JnYW5pemF0aW9uSUQiOiI2NjY2IiwiY2hlY2tDb2RlIjoxNTEyMTgzMzg3fQ=="
69+
);
7070

7171
/**
7272
* 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.
7373
* 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.
74-
* For more information, see https://www.dynamsoft.com/barcode-reader/programming/javascript/user-guide/?ver=9.6.31&utm_source=github#specify-the-license or contact support@dynamsoft.com.
74+
* For more information, see https://www.dynamsoft.com/barcode-reader/programming/javascript/user-guide/?ver=10.0.20&utm_source=github#specify-the-license or contact support@dynamsoft.com.
7575
* LICENSE ALERT - THE END
7676
*/
7777

78-
const divInfContainers = document.querySelector("#div-information-containers");
79-
let scanner;
78+
const divInfContainers = document.querySelector(
79+
"#div-information-containers"
80+
);
8081

8182
(async () => {
8283
try {
83-
scanner = await Dynamsoft.DBR.BarcodeScanner.createInstance();
84-
await scanner.updateRuntimeSettings("speed");
85-
86-
// Get ui by 'getUIElement()' and append it to DOM.
84+
// Create a `CameraEnhancer` instance for camera control and a `CameraView` instance for UI control.
85+
const cameraView = await Dynamsoft.DCE.CameraView.createInstance();
86+
const cameraEnhancer =
87+
await Dynamsoft.DCE.CameraEnhancer.createInstance(cameraView);
8788
document
8889
.querySelector("#div-ui-container")
89-
.append(scanner.getUIElement());
90+
.append(cameraView.getUIElement()); // Get default UI and append it to DOM.
9091

91-
/**
92-
* 'onFrameRead' is triggered after the library finishes reading a frame image.
93-
* There can be multiple barcodes on one image.
94-
*/
95-
scanner.onFrameRead = (results) => {
96-
console.log(results);
92+
// Create a `CaptureVisionRouter` instance and set `CameraEnhancer` instance as its image source.
93+
const router =
94+
await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
95+
router.setInput(cameraEnhancer);
9796

98-
// Clear previous result text elements.
97+
// Define a callback for results.
98+
const resultReceiver = new Dynamsoft.CVR.CapturedResultReceiver();
99+
resultReceiver.onCapturedResultReceived = (result) => {
99100
divInfContainers.innerText = "";
100101

101-
for (let result of results) {
102-
const l = result.localizationResult;
102+
const resultItems = result.items;
103+
for (let item of resultItems) {
104+
if (
105+
item.type !=
106+
Dynamsoft.Core.EnumCapturedResultItemType.CRIT_BARCODE
107+
)
108+
continue;
109+
110+
const l = item.location;
103111
const p1 = {
104-
x: Math.min(l.x1, l.x2, l.x3, l.x4),
105-
y: Math.min(l.y1, l.y2, l.y3, l.y4),
112+
x: Math.min(
113+
l.points[0].x,
114+
l.points[1].x,
115+
l.points[2].x,
116+
l.points[3].x
117+
),
118+
y: Math.min(
119+
l.points[0].y,
120+
l.points[1].y,
121+
l.points[2].y,
122+
l.points[3].y
123+
),
106124
};
107125
const p2 = {
108-
x: Math.max(l.x1, l.x2, l.x3, l.x4),
109-
y: Math.max(l.y1, l.y2, l.y3, l.y4),
126+
x: Math.max(
127+
l.points[0].x,
128+
l.points[1].x,
129+
l.points[2].x,
130+
l.points[3].x
131+
),
132+
y: Math.max(
133+
l.points[0].y,
134+
l.points[1].y,
135+
l.points[2].y,
136+
l.points[3].y
137+
),
110138
};
111-
139+
112140
const divInfContainer = document.createElement("div");
113141
divInfContainer.className = "bubble-box-container";
114142
const divInf = document.createElement("div");
115143
divInf.className = "bubble-box";
116-
divInf.innerText = result.barcodeText;
144+
divInf.innerText = item.text;
117145
divInfContainer.append(divInf);
118146
const bodyStyle = getComputedStyle(document.body);
119147
if (bodyStyle.position === "static") {
120148
/**
121149
* 'convertToPageCoordinates()' is used to converts coordinate of a barcode location to the coordinate related to the document.
122150
* Then we can place a div element according to the converted coordinate.
123151
*/
124-
const pageP1 = scanner.convertToPageCoordinates(p1);
125-
const pageP2 = scanner.convertToPageCoordinates(p2);
152+
const pageP1 = cameraEnhancer.convertToPageCoordinates(p1);
153+
const pageP2 = cameraEnhancer.convertToPageCoordinates(p2);
126154
const pageMidX = (pageP1.x + pageP2.x) / 2;
127155
divInfContainer.style.top = `${pageP1.y}px`;
128156
divInfContainer.style.left = `${pageMidX}px`;
129-
} else { // if you set body `position` as `relative`, `absolute`, and so on, things can get complicated.
157+
} else {
158+
// if you set body `position` as `relative`, `absolute`, and so on, things can get complicated.
130159
/**
131160
* 'convertToClientCoordinates()' is used to converts coordinate of a barcode location to the coordinate related to the viewport.
132161
* Then we can place a div element according to the converted coordinate.
133162
*/
134-
const clientP1 = scanner.convertToClientCoordinates(p1);
135-
const clientP2 = scanner.convertToClientCoordinates(p2);
163+
const clientP1 = cameraEnhancer.convertToClientCoordinates(p1);
164+
const clientP2 = cameraEnhancer.convertToClientCoordinates(p2);
136165
const clientMidX = (clientP1.x + clientP2.x) / 2;
137166
const bodyRect = document.body.getBoundingClientRect();
138-
divInfContainer.style.top = `${clientP1.y - bodyRect.top - parseFloat(bodyStyle.borderTopWidth)}px`;
139-
divInfContainer.style.left = `${clientMidX - bodyRect.left - parseFloat(bodyStyle.borderLeftWidth)}px`;
167+
divInfContainer.style.top = `${
168+
clientP1.y -
169+
bodyRect.top -
170+
parseFloat(bodyStyle.borderTopWidth)
171+
}px`;
172+
divInfContainer.style.left = `${
173+
clientMidX -
174+
bodyRect.left -
175+
parseFloat(bodyStyle.borderLeftWidth)
176+
}px`;
140177
}
141178
divInfContainers.append(divInfContainer);
142179

@@ -145,12 +182,18 @@
145182
*/
146183
}
147184
};
185+
router.addResultReceiver(resultReceiver);
186+
187+
// Filter out unchecked and duplicate results.
188+
const filter = new Dynamsoft.Utility.MultiFrameResultCrossFilter();
189+
filter.enableResultCrossVerification(
190+
Dynamsoft.Core.EnumCapturedResultItemType.CRIT_BARCODE,
191+
true
192+
); // Filter out unchecked barcodes.
148193

149-
/**
150-
* 'open()' opens the camera.
151-
* After that, the library starts to scan the frame images continuously.
152-
*/
153-
await scanner.open();
194+
// Open camera and start scanning single barcode.
195+
await cameraEnhancer.open();
196+
await router.startCapturing("ReadBarcodes_SpeedFirst");
154197
} catch (ex) {
155198
let errMsg;
156199
if (ex.message.includes("network connection error")) {

0 commit comments

Comments
 (0)