食品加工脚本:图像识别失败时fallback到OCR识别,以支持追加正在被加工的食材 (#1432)
This commit is contained in:
@@ -415,6 +415,30 @@ async function AutoPath() {
|
|||||||
await sleep(1000); // 等待1秒以确保点击生效
|
await sleep(1000); // 等待1秒以确保点击生效
|
||||||
foundIngredient = true;
|
foundIngredient = true;
|
||||||
|
|
||||||
|
break; // 找到食材后跳出循环
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!foundIngredient) {
|
||||||
|
// 图像识别未成功,可能是因为该食材正在被加工,通过OCR识别
|
||||||
|
const ocrResult = captureGameRegion().findMulti(RecognitionObject.ocr(112, 118, 1161, 345));
|
||||||
|
for (var i = 0; i < ocrResult.count; ++i) {
|
||||||
|
if (ocrResult[i].text.endsWith("分钟") || ocrResult[i].text.endsWith("秒")) {
|
||||||
|
// 选中该食材
|
||||||
|
click(ocrResult[i].x, ocrResult[i].y);
|
||||||
|
await sleep(500);
|
||||||
|
// OCR食材名称
|
||||||
|
const ocrResult2 = captureGameRegion().findMulti(RecognitionObject.ocr(1308, 122, 492, 52));
|
||||||
|
const ingredientName = ocrResult2.count > 0 ? ocrResult2[0].text : null;
|
||||||
|
if (ingredientName === chineseDescription) {
|
||||||
|
log.info(`通过OCR识别找到食材: ${chineseDescription}`);
|
||||||
|
foundIngredient = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foundIngredient) {
|
||||||
// 执行额外的点击操作(如果需要)
|
// 执行额外的点击操作(如果需要)
|
||||||
await performExtraClicks(processingKey);
|
await performExtraClicks(processingKey);
|
||||||
|
|
||||||
@@ -426,12 +450,7 @@ async function AutoPath() {
|
|||||||
if (PrepCount > 0) {
|
if (PrepCount > 0) {
|
||||||
await performPrepCountActions(PrepCount);
|
await performPrepCountActions(PrepCount);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
break; // 找到食材后跳出循环
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!foundIngredient) {
|
|
||||||
log.error(`未能识别到食材: ${chineseDescription}`);
|
log.error(`未能识别到食材: ${chineseDescription}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 1,
|
"manifest_version": 1,
|
||||||
"name": "选择加工食材",
|
"name": "选择加工食材",
|
||||||
"version": "2.1",
|
"version": "2.2",
|
||||||
"description": "食材加工 识图 复选框。",
|
"description": "食材加工 识图 复选框。",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user