18:26:32.086/E: Wrapped java.lang.IllegalStateException: image has been recycled (/android_asset/modules/paddle.js#10)
Wrapped java.lang.IllegalStateException: image has been recycled
at /android_asset/modules/paddle.js:10:0
at captureAndOcr (/storage/emulated/0/脚本/GetGold-x/OCR/OCR.js:37:0)
at /storage/emulated/0/脚本/GetGold-x/OCR/OCR.js:47:0
at /storage/emulated/0/脚本/GetGold-x/App/com.antisent.compass/ExternalScript.js:39:0
![0_1706869931792_965c9aaff1c0aeb06bceab530745607.png](正在上传 100%)
代码:// 识别结果和截图信息
let result = []
let img = null
let capturing = true
/**
- 截图并识别OCR文本信息
*/
function captureAndOcr() {
capturing = true
img && img.recycle()
img = captureScreen();
if (!img) {
toastLog('截图失败')
}
let start = new Date()
result = paddle.ocr(img);
// log(result);
toastLog('OCR耗时' + (new Date() - start) + 'ms')
capturing = false
// 回收图片
}
OCR.find = function (elementName) {
captureAndOcr()
if (result && result.length > 0) {
for (let i = 0; i < result.length; i++) {
let ocrResult = result[i]
// log(ocrResult.words);
for (let s = 0; s < elementName.length; s++) {
if (ocrResult.words == elementName[s]) {
// draw(ocrResult.words + ' #信心:' + ocrResult.confidence.toFixed(2), ocrResult.bounds);
toastLog(ocrResult.words + " ,坐标:" + ocrResult.bounds.centerX() + ',' + ocrResult.bounds.centerY());
return [ocrResult.bounds.centerX(), ocrResult.bounds.centerY()]
}
}
}
} else {
return null;
}
}