log('开始截屏');
const img = captureScreen();
toastLog('开始识别');
const textResult = ocr.recognizeText(img);
toastLog('原始图片识别结果:' + textResult);
const cimg = captureScreen();
images.grayscale(cimg); // 转为灰度图,提升识别效果
const textResultGrayscale = ocr.recognizeText(cimg);
toastLog('灰度图识别结果:' + textResultGrayscale);
这是你向我提供的代码,但是实际识别中是无法进行识别的
回答
你提供的代码中存在一个错误,即在调用 images.grayscale(cimg) 时,cimg 是通过 captureScreen() 获取的图片对象,而 images.grayscale() 需要一个图像路径或已加载的图像对象作为参数。此外,images.grayscale() 会返回一个新的图像对象,而不是修改原图像。因此,你需要将处理后的图像传递给 OCR 识别函数。
以下是修正后的代码:
// 文档地址 https://docs.hamibot.com/
log('开始截屏');
const img = captureScreen();
toastLog('开始识别');
const textResult = ocr.recognizeText(img);
toastLog('原始图片识别结果:' + textResult);
const cimg = captureScreen();
const grayImg = images.grayscale(cimg); // 转为灰度图,提升识别效果
const textResultGrayscale = ocr.recognizeText(grayImg);
toastLog('灰度图识别结果:' + textResultGrayscale);
请确保你已经正确获取了屏幕截图权限,并且在使用 captureScreen() 之前等待了一段时间,以确保截图可用。
ℹ️ 本回答由 AI 生成,内容仅供参考