Skip to content

Commit dab5475

Browse files
author
Cube
authored
Merge pull request #119 from Dynamsoft/Keillion-patch-1
Update 3.show-result-texts-on-the-video.html
2 parents 9079b1b + 08d8bcd commit dab5475

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

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

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,48 +80,37 @@
8080
divTextContainers.innerText = "";
8181

8282
for (let result of results) {
83+
const l = result.localizationResult;
8384
const p1 = {
84-
x: Math.min(
85-
result.localizationResult.x1,
86-
result.localizationResult.x2,
87-
result.localizationResult.x3,
88-
result.localizationResult.x4
89-
),
90-
y: Math.min(
91-
result.localizationResult.y1,
92-
result.localizationResult.y2,
93-
result.localizationResult.y3,
94-
result.localizationResult.y4
95-
),
85+
x: Math.min(l.x1, l.x2, l.x3, l.x4),
86+
y: Math.min(l.y1, l.y2, l.y3, l.y4),
9687
};
9788
const p2 = {
98-
x: Math.max(
99-
result.localizationResult.x1,
100-
result.localizationResult.x2,
101-
result.localizationResult.x3,
102-
result.localizationResult.x4
103-
),
104-
y: Math.max(
105-
result.localizationResult.y1,
106-
result.localizationResult.y2,
107-
result.localizationResult.y3,
108-
result.localizationResult.y4
109-
),
89+
x: Math.max(l.x1, l.x2, l.x3, l.x4),
90+
y: Math.max(l.y1, l.y2, l.y3, l.y4),
11091
};
92+
11193
/**
11294
* 'convertToPageCoordinates()' is used to converts coordinate of a barcode location to the coordinate related to the document.
11395
* Then we can place a div element according to the converted coordinate.
11496
*/
11597
const convertedP1 = scanner.convertToPageCoordinates(p1);
11698
const convertedP2 = scanner.convertToPageCoordinates(p2);
99+
117100
textContainer = document.createElement("div");
118-
textContainer.style.position = "absolute";
119-
textContainer.style.left = convertedP1.x + "px";
120-
textContainer.style.right = document.body.clientWidth - convertedP2.x + "px";
121-
textContainer.style.bottom = document.body.clientHeight - convertedP1.y + "px";
122-
textContainer.style.color = "#FE8E14";
101+
Object.assign(textContainer.style, {
102+
position: "absolute",
103+
left: convertedP1.x + "px",
104+
right: document.documentElement.clientWidth - convertedP2.x + "px",
105+
bottom: document.documentElement.clientHeight - convertedP1.y + "px",
106+
color: "#FE8E14",
107+
});
123108
textContainer.innerText = result.barcodeText;
124109
divTextContainers.append(textContainer);
110+
111+
/**
112+
* You can also add more information, such as displaying product images.
113+
*/
125114
}
126115
};
127116

0 commit comments

Comments
 (0)