import('java.io.File') import('java.lang.*') import('java.util.Arrays') import('android.content.Context') import('android.hardware.Sensor') import('android.hardware.SensorEvent') import('android.hardware.SensorEventListener') import('android.hardware.SensorManager') import('com.nx.assist.lua.LuaEngine') local w,h w,h = getDisplaySize() print(w,h) local loader = LuaEngine.loadApk("111222.apk") local OCR = loader.loadClass("com.tomato.ocr.lr.OCRApi") local tmo_ocr = OCR.init(LuaEngine.getContext()) local license = "TF70TX9SQEDJXUISSRNOPT3RPZJRDQKZ|K55DSIM3E82ZRKEKMDEGLF"; local flag = tmo_ocr.setLicense(license); print(flag) tmo_ocr.setRecType("ch-3.0") tmo_ocr.setDetBoxType("rect") tmo_ocr.setDetUnclipRatio(1.9) tmo_ocr.setRecScoreThreshold(0.3) tmo_ocr.setReturnType("json") tmo_ocr.setBinaryThresh(0) local w,h w,h = getDisplaySize() if w~=540 or h~=960 then print('解析度540*960 才可以執行') stop() end function click_node() local sel = index(0):text(""):desc("資料夾:系統應用"):visibleToUser(true) local node = sel:findOne(10000) if node ~= nil then print(node:click()) end end function find_text_click(x1, y1, x2, y2, wz,count) count = count or 0 -- 如果count未傳入,則設定為0 local type = 3; local bitmap = LuaEngine.snapShot(x1, y1, x2, y2) local result = tmo_ocr.ocrBitmap(bitmap, type) bitmap.recycle() local point = tmo_ocr.findTapPoint(wz) if point ~= "" then local json_point = jsonLib.decode(point) local center_x = json_point[1] + x1 local center_y = json_point[2] + y1 printEx('找到了' .. wz .. ': 座標' .. center_x .. ' ' .. center_y .. ' 開始點選'); tap(center_x, center_y) else printEx('未找到文字' .. wz) count = count + 1; sleep(2000) print('延遲2秒後繼續找' .. count) find_text_click(x1, y1, x2, y2, wz,count) end end function recognize_text(x1, y1, x2, y2) local type = 3; local bitmap = LuaEngine.snapShot(x1, y1, x2, y2) local result = tmo_ocr.ocrBitmap(bitmap, type) bitmap.recycle() if result ~= "" then local json_result = jsonLib.decode(result) -- setReturnType為“json”時,返回的是json字串,用jsonLib.decode解析 for i, data in ipairs(json_result) do local location = data.location local score = data.score local words = data.words printEx('找到文字' .. words); return words; end else printEx('識別不了文字'); return 0; end end function stop() exitScript() end function begintouch() print('開始滑動'); touchDown(1, 297, 327) sleep(50) touchMoveEx(1, 297, 127, 2000) touchUp(1) end -- local ret, code = httpPost("https://wxserver.zhihuxuetang.cn/home/moban/testajax", "arg=123") -- print(ret) local function start() find_text_click(0, 0, 208, 397, '系統應用') text = recognize_text(79, 341, 209, 375) print(text); end return { start = start }