31 lines
1.3 KiB
JavaScript
31 lines
1.3 KiB
JavaScript
// 只截图并比较 OCR 返回值,不点击、不滑动、不启动业务流程。
|
|
function report(message) {
|
|
console.log("[ocr_probe] " + message);
|
|
}
|
|
function inspect(name, value) {
|
|
report(name + " type=" + typeof value + " array=" + Array.isArray(value));
|
|
try { report(name + " value=" + String(value).slice(0, 1600)); } catch (e) {}
|
|
try { report(name + " keys=" + Object.keys(value).slice(0, 30).join(",")); } catch (e) {}
|
|
try {
|
|
if (value && value.length > 0) {
|
|
var first = value[0];
|
|
report(name + " count=" + value.length + " firstType=" + typeof first);
|
|
report(name + " first=" + String(first));
|
|
report(name + " text=" + String(first.text) + " label=" + String(first.label) +
|
|
" bounds=" + String(first.bounds) + " confidence=" + String(first.confidence));
|
|
}
|
|
} catch (e) { report(name + " inspect error=" + e); }
|
|
}
|
|
try {
|
|
report("start (no clicks)");
|
|
if (!requestScreenCapture(false)) { throw new Error("截图权限未允许"); }
|
|
sleep(1500);
|
|
var frame = captureScreen();
|
|
report("image=" + frame.getWidth() + "x" + frame.getHeight());
|
|
inspect("recognizeText", ocr.recognizeText(frame));
|
|
inspect("detect", ocr.detect(frame));
|
|
report("done");
|
|
} catch (error) {
|
|
report("failed=" + String(error.stack || error));
|
|
}
|