-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.js
77 lines (61 loc) · 1.81 KB
/
upload.js
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
const express = require("express");
const { execSync } = require("child_process");
const request = require("request");
const fs = require("fs");
const sharp = require("sharp");
const { Readable } = require("stream");
let stop = false;
const device = process.argv[2] || "localhost:5555";
const adb = 'E:/MT4/platform-tools/adb.exe';
const TESSDATA_PREFIX = 'E:/MT4/tesseract/tessdata';
const tesseract = 'E:/MT4/tesseract/tesseract.exe';
const cmd = `${adb} -s ${device} exec-out screencap -p`;
console.log('device', device, 'cmd', cmd);
const getStream = async () => {
const inputBuffer = execSync(cmd);
// fs.writeFileSync("test.png", inputBuffer);
// 720 × 1280
let top = 300;
let buffer = await sharp(inputBuffer)
.extract({
width: 300,
height: 1280 - top - 100,
left: 0,
top: top
})
.toBuffer();
return buffer;
};
const run = async () => {
const buffer = await getStream();
const upload = new Readable();
upload.push(buffer);
upload.push(null);
upload.pipe(request.post("http://202.134.19.119:3000/upload"));
var upload_progress = 0;
upload.on("data", function(chunk) {
upload_progress += chunk.length;
console.log(new Date(), upload_progress);
});
upload.on("end", function(res) {
console.log("Done update");
setTimeout(run, 100);
});
};
// run();
const test = async ()=>{
const start = Date.now();
try {
const buffer = await getStream();
const image = "test.png";
const tesscmd = `${tesseract} ${image} stdout`;
console.log('tesscmd', tesscmd)
fs.writeFileSync(image, buffer);
const data = execSync(tesscmd).toString();
const elapsed = Date.now() - start;
console.log("Took " + elapsed + " ms\n", data);
} catch (ex) {
console.log("Error processing", ex);
}
}
test();