js:锄地一条龙1.4.0 (#1568)
* js:锄地一条龙1.4.0 ### 1.4.0(2025.08.12) 1.增加拾取模式,模板匹配拾取并设为默认项,之前的拾取模式改名为ocr拾取 * js:性能测试 增加自定义配置选择测试项目和识图区域大小 * js:锄地一条龙 适当增加拾取后延时
This commit is contained in:
BIN
repo/js/ComputerBlower/assets/流放.png
Normal file
BIN
repo/js/ComputerBlower/assets/流放.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
@@ -1,29 +1,79 @@
|
||||
// 主函数
|
||||
(async function () {
|
||||
operationMode = settings.operationMode || "截图";
|
||||
const xRange = parseInt(+settings.xRange || 1920, 10);
|
||||
const yRange = parseInt(+settings.yRange || 1920, 10);
|
||||
let startTime = Date.now();
|
||||
const interval = +settings.interval || 1000;
|
||||
const timeout = +settings.timeout || 60;
|
||||
let lastCheck = startTime;
|
||||
let ocrcount = 0;
|
||||
let loopCount = 0;
|
||||
let logCount = 0;
|
||||
//let store = [];
|
||||
while (Date.now() - startTime < timeout * 1000) {
|
||||
loopCount++;
|
||||
try {
|
||||
let GameRegion = captureGameRegion();
|
||||
// store[loopCount] = GameRegion;
|
||||
if (settings.dispose) GameRegion.dispose();
|
||||
ocrcount++;
|
||||
} catch (error) {
|
||||
log.error(`运行时发生异常: ${error.message}`);
|
||||
break;
|
||||
}
|
||||
if (Date.now() - lastCheck >= interval) {
|
||||
logCount++;
|
||||
lastCheck = Date.now();
|
||||
log.info(`在第${logCount}个${interval}毫秒内执行了${ocrcount}次截图`);
|
||||
ocrcount = 0;
|
||||
const imagePath = "assets/流放.png";
|
||||
let template = file.ReadImageMatSync(imagePath);
|
||||
if (operationMode === "截图") {
|
||||
while (Date.now() - startTime < timeout * 1000) {
|
||||
try {
|
||||
let GameRegion = captureGameRegion();
|
||||
if (settings.dispose) GameRegion.dispose();
|
||||
ocrcount++;
|
||||
if (Date.now() - lastCheck >= interval) {
|
||||
loopCount++;
|
||||
await sleep(1);
|
||||
lastCheck = Date.now();
|
||||
log.info(`在第${loopCount}个${interval}毫秒内执行了${ocrcount}次截图`);
|
||||
ocrcount = 0;
|
||||
}
|
||||
} catch (error) {
|
||||
log.error(`运行时发生异常: ${error.message}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (operationMode === "模板匹配") {
|
||||
let GameRegion = captureGameRegion();
|
||||
while (Date.now() - startTime < timeout * 1000) {
|
||||
try {
|
||||
|
||||
let recognitionObject = RecognitionObject.TemplateMatch(template, 0, 0, xRange, yRange);
|
||||
let result = GameRegion.find(recognitionObject);
|
||||
ocrcount++;
|
||||
if (Date.now() - lastCheck >= interval) {
|
||||
loopCount++;
|
||||
await sleep(1);
|
||||
lastCheck = Date.now();
|
||||
log.info(`在第${loopCount}个${interval}毫秒内执行了${ocrcount}次模板匹配`);
|
||||
ocrcount = 0;
|
||||
}
|
||||
} catch (error) {
|
||||
log.error(`运行时发生异常: ${error.message}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (settings.dispose) GameRegion.dispose();
|
||||
}
|
||||
if (operationMode === "ocr") {
|
||||
let GameRegion = captureGameRegion();
|
||||
while (Date.now() - startTime < timeout * 1000) {
|
||||
try {
|
||||
let result = GameRegion.findMulti(RecognitionObject.ocr(
|
||||
0, 0,
|
||||
xRange, yRange
|
||||
));
|
||||
ocrcount++;
|
||||
} catch (error) {
|
||||
log.error(`运行时发生异常: ${error.message}`);
|
||||
break;
|
||||
}
|
||||
if (Date.now() - lastCheck >= interval) {
|
||||
loopCount++;
|
||||
lastCheck = Date.now();
|
||||
await sleep(1);
|
||||
log.info(`在第${loopCount}个${interval}毫秒内执行了${ocrcount}次OCR`);
|
||||
ocrcount = 0;
|
||||
}
|
||||
}
|
||||
if (settings.dispose) GameRegion.dispose();
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 1,
|
||||
"name": "截图性能测试",
|
||||
"version": "0.1",
|
||||
"name": "性能测试",
|
||||
"version": "1.0",
|
||||
"tags": [],
|
||||
"bgi_version": "0.46.0",
|
||||
"description": "测测你的",
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
[
|
||||
{
|
||||
"name": "operationMode",
|
||||
"type": "select",
|
||||
"label": "测试项目",
|
||||
"options": [
|
||||
"截图",
|
||||
"模板匹配",
|
||||
"ocr"
|
||||
],
|
||||
"default": "只截图"
|
||||
},
|
||||
{
|
||||
"name": "dispose",
|
||||
"type": "checkbox",
|
||||
@@ -15,5 +26,17 @@
|
||||
"type": "input-text",
|
||||
"label": "间隔多久输出一次(毫秒)",
|
||||
"default": "1000"
|
||||
},
|
||||
{
|
||||
"name": "xRange",
|
||||
"type": "input-text",
|
||||
"label": "区域大小x",
|
||||
"default": "1920"
|
||||
},
|
||||
{
|
||||
"name": "yRange",
|
||||
"type": "input-text",
|
||||
"label": "区域大小y",
|
||||
"default": "1080"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user