-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathqrcode.js
More file actions
41 lines (28 loc) · 944 Bytes
/
Copy pathqrcode.js
File metadata and controls
41 lines (28 loc) · 944 Bytes
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
let qrCodeDetector = new cv.QRCodeDetector();
function getQRCode(image) {
let [decodedText, ..._] = qrCodeDetector.detectAndDecode(image)
return decodedText;
}
function test(file) {
let img = cv.imread(file);
// let gray = cv.cvtColor(img, cv.COLOR_RGB2GRAY)
let result = "";
let num = 0;
result = getQRCode(img);
if (result == "") {
let [t, newImg] = cv.threshold(img, 0, 255, cv.THRESH_OTSU);
console.log(file);
while (result == "" && t < 255) {
num++
[t, newImg] = cv.threshold(newImg, t, 255, cv.THRESH_BINARY);
result = getQRCode(newImg);
t += 20;
}
}
console.log("try ", num, " and result: ", result);
}
test("./opencv/qrcode/2020-8-14-11-18-43-0.png");
let dir = new Qt.DirIterator("./opencv/qrcode/", Qt.Dir.Filter.NoDotAndDotDot | Qt.Dir.Filter.Files);
while (dir.hasNext()) {
//test(dir.next());
}