if (!requestScreenCapture()) {
toastLog('没有授予 Hamibot 屏幕截图权限');
hamibot.exit();
}
sleep(1000);
log('开始截屏');
const img = captureScreen();
toastLog('开始识别');
const res = ocr.recognize(img);
log(res);
hamibot.exit();这段如果不截屏,通过识别指定屏幕区域的图片可以吗
回答
可以,通过识别指定屏幕区域的图片是可行的。你可以使用 images.clip()
函数来截取屏幕的特定区域,然后对这个区域进行 OCR 识别。
下面是一个示例代码,展示如何截取屏幕的特定区域并进行 OCR 识别:
// 请求截图权限
auto.waitFor();
if (!requestScreenCapture()) {
toastLog('没有授予 Hamibot 屏幕截图权限');
hamibot.exit();
}
sleep(1000);
// 截取整个屏幕
const fullImg = captureScreen();
// 定义要截取的区域 [左, 上, 右, 下]
const region = [100, 200, 500, 400];
// 截取指定区域的图片
const regionImg = images.clip(fullImg, region[0], region[1], region[2], region[3]);
// 开始识别
toastLog('开始识别');
const res = ocr.recognize(regionImg);
log(res);
hamibot.exit();
这段代码首先请求屏幕截图权限,然后截取整个屏幕,接着使用 images.clip()
函数截取指定区域的图片,最后对这个区域的图片进行 OCR 识别。
ℹ️ 本回答由 AI 生成,内容仅供参考