Repository navigation
Expand file tree
/
Copy pathget_frame_tool.html
More file actions
108 lines (96 loc) · 4.11 KB
/
Copy pathget_frame_tool.html
File metadata and controls
108 lines (96 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Get_Frame_Tool</title>
<script src="https://cdn.jsdelivr.net/npm/jszip@3.10.1/dist/jszip.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/file-saver@2.0.5/dist/FileSaver.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@3.1.0/dist/dce.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-document-normalizer@1.0.11/dist/ddn.js"></script>
</head>
<body>
<select id="proSelect">
<option value="dce">Only DCE</option>
<option value="ddn">Use DDN</option>
</select>
<button id="openCamera">open camera</button><br>
Set number : <input id="getFrameNumIpt" type="number" value="8" style="width: 50px;">
<button id="getFrameBtn">get frame</button>
<span id="capturing" style="display: none;margin-left: 5px;">Capturing...</span>
<div id="dceUIContainer" style="width:100%;height:70vh;margin-top: 10px;"></div>
<script>
Dynamsoft.DDN.DocumentNormalizer.license = "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9";
let downloadImg = [];
let getFrameNum = 8;
let selectedPro = "dce";
let dce = null;
let ddn = null;
let actionMap = {
dce() {dce.open(true);},
ddn() {useDdn();},
};
(async()=>{
dce = await Dynamsoft.DCE.CameraEnhancer.createInstance();
await dce.setUIElement(Dynamsoft.DCE.CameraEnhancer.defaultUIElementURL);
document.getElementById("dceUIContainer").appendChild(dce.getUIElement());
})();
document.querySelector("#getFrameNumIpt").addEventListener("change", (e)=>{
getFrameNum = +e.target.value;
})
document.querySelector("#getFrameBtn").addEventListener("click", async ()=>{
document.querySelector("#capturing").style.display = "inline";
await getImages();
document.querySelector("#capturing").style.display = "none";
})
async function getImages() {
await this.saveImages();
const zip = new JSZip();
for(let i=0;i<downloadImg.length;i++) {
zip.file(downloadImg[i].name, downloadImg[i].blob);
}
const content = await zip.generateAsync({type: "blob"});
saveAs(content, `screenshot-${getDate()}.zip`);
downloadImg = [];
}
async function saveImages() {
return new Promise(async (rs,rj)=>{
let index = 0;
while(index < getFrameNum) {
const cvs = dce.getFrame().toCanvas();
if (cvs != null) {
const blob = cvs.convertToBlob ? await cvs.convertToBlob() : await new Promise(resolve => {
cvs.toBlob(blob => resolve(blob));
});
downloadImg.push({ name: "Screenshot - " + new Date().toISOString().replace(/\:/g, "-") + ".png", blob});
index++;
}
}
rs();
})
}
function getDate() {
const date = new Date();
return `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()}`;
}
document.querySelector("#proSelect").addEventListener("change", (e) => {
selectedPro = e.target.value;
})
document.querySelector("#openCamera").addEventListener("click", async () => {
await actionMap[selectedPro]();
document.querySelector("#proSelect").disabled = true;
})
async function useDce() {
await dce.open(true);
}
async function useDdn() {
if(!ddn) {
ddn = await Dynamsoft.DDN.DocumentNormalizer.createInstance();
await ddn.setImageSource(dce, {resultsHighlightBaseShapes: Dynamsoft.DCE.DrawingItem});
await ddn.startScanning(true);
}
}
</script>
</body>
</html>