From 1ab2345d01860b134b622d27cb3f8b7a9a14bbee Mon Sep 17 00:00:00 2001 From: wilinz Date: Mon, 22 Aug 2022 19:14:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0TessOCR=E5=8F=8A=E4=BE=8B?= =?UTF-8?q?=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/sample/TessOCR/main.js | 32 +++++++++++ .../main/assets/sample/TessOCR/project.json | 53 +++++++++++++++++++ autojs/build.gradle | 3 +- project-versions.json | 8 +-- 4 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 app/src/main/assets/sample/TessOCR/main.js create mode 100644 app/src/main/assets/sample/TessOCR/project.json diff --git a/app/src/main/assets/sample/TessOCR/main.js b/app/src/main/assets/sample/TessOCR/main.js new file mode 100644 index 000000000..6e35c6dd3 --- /dev/null +++ b/app/src/main/assets/sample/TessOCR/main.js @@ -0,0 +1,32 @@ +//此例子仅作为演示,无法运行,因为tessdata目录下没有训练数据, +//如需运行,可前往github下载完整例子:https://github.com/wilinz/autoxjs-tessocr +//导包 +importClass(com.googlecode.tesseract.android.TessBaseAPI) +//新建OCR实例 +var tessocr = new TessBaseAPI() +//请求截图权限 +requestScreenCapture(false); +//3秒后开始 +toastLog("3秒后截图") +sleep(3000) +toastLog("开始截图") +//截图 +var img = captureScreen(); +//tessdata目录所在的文件夹,目录下放置训练数据 +//训练数据下载地址:https://github.com/tesseract-ocr/tessdata/tree/4.0.0 +var dataPath = files.path("./") +//初始化tessocr +//第二个参数是初始化的语言,是数据文件去掉扩展名后的文件名,多个语言用+连接 +//训练数据文件夹必须命名为tessdata +//训练数据下载时是什么名字就是什么名字,不能改 +var ok = tessocr.init(dataPath, "eng+chi_sim") +if (ok) { + toastLog("初始化成功: " + tessocr.getInitLanguagesAsString()) +} else { + toastLog("初始化失败") +} +//设置图片 +tessocr.setImage(img.getBitmap()) +//打印文本结果 +toastLog(tessocr.getUTF8Text()) +//如需获取位置等其他结果请看文档 \ No newline at end of file diff --git a/app/src/main/assets/sample/TessOCR/project.json b/app/src/main/assets/sample/TessOCR/project.json new file mode 100644 index 000000000..cba14159a --- /dev/null +++ b/app/src/main/assets/sample/TessOCR/project.json @@ -0,0 +1,53 @@ +{ + "abis": [ + "arm64-v8a", + "armeabi-v7a", + "x86", + "x86_64" + ], + "assets": [ + ], + "buildDir": "build", + "build": { + "build_id": null, + "build_number": 0, + "build_time": 0 + }, + "useFeatures": [], + "icon": null, + "ignoredDirs": [ + "build" + ], + "launchConfig": { + "displaySplash": false, + "hideLauncher": false, + "hideLogs": false, + "stableMode": false, + "volumeUpcontrol": false, + "permissions": [], + "serviceDesc": "使脚本自动操作(点击、长按、滑动等)所需,若关闭则只能执行不涉及自动操作的脚本。", + "splashIcon": null, + "splashText": "Powered by TessOCR" + }, + "libs": [ + "libtesseract.so", + "libpng.so", + "libleptonica.so", + "libjpeg.so", + "libjackpal-androidterm5.so", + "libjackpal-termexec2.so" + ], + "main": "main.js", + "name": "TessOCR", + "outputPath": null, + "packageName": "com.script.tessocr", + "projectDirectory": null, + "scripts": {}, + "signingConfig": { + "alias": null, + "keystore": null + }, + "sourcePath": null, + "versionCode": 1, + "versionName": "1.0.0" +} \ No newline at end of file diff --git a/autojs/build.gradle b/autojs/build.gradle index 5bec54c45..6331ef7b3 100644 --- a/autojs/build.gradle +++ b/autojs/build.gradle @@ -50,7 +50,7 @@ dependencies { api('com.afollestad.material-dialogs:core:0.9.2.3', { exclude group: 'com.android.support' }) - api 'com.google.android.material:material:1.7.0-alpha03' + api 'com.google.android.material:material:1.7.0-beta01' api 'com.github.hyb1996:EnhancedFloaty:0.31' api 'com.makeramen:roundedimageview:2.3.0' // OkHttp @@ -74,5 +74,6 @@ dependencies { api project(":paddleocr") // libs api fileTree(dir: '../app/libs', include: ['dx.jar', 'rhino-1.7.14-jdk7.jar']) + api 'cz.adaptech:tesseract4android:4.1.1' } diff --git a/project-versions.json b/project-versions.json index 3ca390ac7..8dbf1cf96 100644 --- a/project-versions.json +++ b/project-versions.json @@ -1,8 +1,8 @@ { - "appVersionCode": 628, - "appVersionName": "6.2.8", - "devVersionCode": 628, - "devVersionName": "6.2.8", + "appVersionCode": 629, + "appVersionName": "6.2.9", + "devVersionCode": 629, + "devVersionName": "6.2.9", "target": 26, "mini": 21, "compile": 32,