国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

動態(tài)網(wǎng)站建設的一般步驟免費的h5制作網(wǎng)站

動態(tài)網(wǎng)站建設的一般步驟,免費的h5制作網(wǎng)站,三亞的私人電影院,php做網(wǎng)站有哪些好處目的 懶人精靈是 Android 平臺上的一款自動化工具,它通過編寫 lua 腳本,結(jié)合系統(tǒng)的「 無障礙服務 」對 App 進行自動化操作。在文字識別方面它提供的有一款OCR識別插件,但是其中有識別速度慢,插件大的缺點,所以這里將講…

目的

? ? ? ?懶人精靈是 Android 平臺上的一款自動化工具,它通過編寫 lua 腳本,結(jié)合系統(tǒng)的「 無障礙服務 」對 App 進行自動化操作。在文字識別方面它提供的有一款OCR識別插件,但是其中有識別速度慢,插件大的缺點,所以這里將講解一下如何集成基于PaddleOCR文字識別開發(fā)的插件,閱讀本篇文字需要對PaddleOCR有個基本的了解,還需要有一點Android開發(fā)基礎,文章最后有相關(guān)插件下載地址。

準備工作

1、android studio最新版本即可

下載地址:Download Android Studio & App Tools - Android Developers???????

2、下載PaddleOCR提供的安卓版文字識別demo

下載地址:???????PaddleOCR/deploy/android_demo at release/2.5 · PaddlePaddle/PaddleOCR · GitHub

3、導入Android studio并成功運行

以上三步工作完成后,將開始我們的懶人精靈文字識別插件開發(fā)。

插件開發(fā)

1、項目結(jié)構(gòu)對比

修改前 VS 修改后,調(diào)整了一些文件,去除了Activity入口。

?2、插件SDK集成

在項目的build.gradle文件中添加:

allprojects {repositories {// ...maven { url 'https://jitpack.io' }}
}

在app的build.gradle文件中添加

dependencies {// ... implementation 'com.alibaba:fastjson:1.1.46.android'
}

3、刪除無用的Activity文件

?4、修改AndroidManifest.xml

兩處包名替換成自己的包名,其他地方如下代碼不動。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"package="com.tomato.ocr"><applicationandroid:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:debuggable="true"android:theme="@style/AppTheme"tools:ignore="HardcodedDebugMode"></application>
</manifest>

5、修改Predictor文件

添加這兩行文件:

?

?調(diào)整loadLabel代碼如下:

6、修改cpp包名?

修改native.cpp文件,將官方的_com_baidu_paddle_lite_demo_ocr_替換成我們自己的包名,如_com_tomato_ocr_,如下截圖:

7、新建OCRApi接口類

package com.tomato.ocr.ec;import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.media.ExifInterface;
import android.util.Log;import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.tomato.ocr.OCRResultModel;
import com.tomato.ocr.Predictor;
import com.tomato.ocr.Utils;import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;public class OCRApi {private final int useOpencl = 0;private final int cpuThreadNum = 1;private final String cpuPowerMode = "LITE_POWER_HIGH";private final int detLongSize = 960;private final float scoreThreshold = 0.1f;// 檢測protected int run_det = 1;// 分類protected int run_cls = 1;// 識別protected int run_rec = 1;private final String assetModelDirPath = "models/ch_PP-OCRv2";private String assetlabelFilePath = "labels/ppocr_keys_v1.txt";private Context mContext;private Predictor mPredictor;private static OCRApi ocrApi;public static OCRApi init(Context mContext) {if (ocrApi == null) {ocrApi = new OCRApi(mContext);}return ocrApi;}public OCRApi(Context mContext) {this.mContext = mContext;try {String path = Utils.setPathForDefaultDataForLr(mContext, this.getClass());Log.d("OCR加載路徑", path);} catch (IOException e) {e.printStackTrace();}this.mPredictor = new Predictor();boolean flag = this.mPredictor.init(this.mContext, assetModelDirPath, assetlabelFilePath, useOpencl, cpuThreadNum,cpuPowerMode,detLongSize, scoreThreshold);if (!flag) {Log.d("*************", "初始化失敗");} else {Log.d("*************", "初始化成功");}}public void release() {if (mPredictor != null) {mPredictor.releaseModel();}if (ocrApi != null) {ocrApi = null;}}public String ocrFile(final String imagePath) {return this.ocrFile(imagePath, -1);}public String ocrFile(final String imagePath, int type) {if (type == 0) {// 只檢測return this.ocrFile(imagePath, 1, 0, 0).toJSONString();} else if (type == 1) {// 方向分類 + 識別return this.ocrFile(imagePath, 0, 1, 1).toJSONString();} else if (type == 2) {// 只識別return this.ocrFile(imagePath, 0, 0, 1).toJSONString();} else if (type == 3) {// 檢測 + 識別return this.ocrFile(imagePath, 1, 0, 1).toJSONString();}// 默認 檢測 + 方向分類 + 識別return this.ocrFile(imagePath, 1, 1, 1).toJSONString();}private JSONArray ocrFile(final String imagePath, int run_det, int run_cls, int run_rec) {try {Bitmap image;if (imagePath.contains(".jpg") || imagePath.contains(".JPG") || imagePath.contains(".jpeg") || imagePath.contains(".JPEG")) {ExifInterface exif = null;exif = new ExifInterface(imagePath);int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_UNDEFINED);image = BitmapFactory.decodeFile(imagePath);image = Utils.rotateBitmap(image, orientation);} else {image = BitmapFactory.decodeFile(imagePath);}this.mPredictor.setInputImage(image);boolean flag = runModel(run_det, run_cls, run_rec);if (!flag) {Log.d("****************", "無法運行!");return new JSONArray();}return transformOCRResult(this.mPredictor.outputResultList);} catch (IOException e) {e.printStackTrace();}return new JSONArray();}public String ocrBitmap(final Bitmap bitmap) {return this.ocrBitmap(bitmap, -1);}public String ocrBitmap(final Bitmap bitmap, int type) {if (type == 0) {// 只檢測return this.ocrBitmap(bitmap, 1, 0, 0).toJSONString();} else if (type == 1) {// 方向分類 + 識別return this.ocrBitmap(bitmap, 0, 1, 1).toJSONString();} else if (type == 2) {// 只識別return this.ocrBitmap(bitmap, 0, 0, 1).toJSONString();} else if (type == 3) {// 檢測 + 識別return this.ocrBitmap(bitmap, 1, 0, 1).toJSONString();}// 默認 檢測 + 方向分類 + 識別return this.ocrBitmap(bitmap, 1, 1, 1).toJSONString();}private JSONArray ocrBitmap(Bitmap bitmap, int run_det, int run_cls, int run_rec) {this.mPredictor.setInputImage(bitmap);boolean flag = runModel(run_det, run_cls, run_rec);if (!flag) {Log.d("****************", "無法運行!");return new JSONArray();}return transformOCRResult(this.mPredictor.outputResultList);}private boolean runModel(int run_det, int run_cls, int run_rec) {return this.mPredictor.runModel(run_det, run_cls, run_rec);}private JSONArray transformOCRResult(List<OCRResultModel> ocrResultModelList) {JSONArray jsonArray = new JSONArray();for (OCRResultModel ocrResultModel : ocrResultModelList) {JSONObject jsonObject = new JSONObject();jsonObject.put("words", ocrResultModel.getLabel());JSONArray objects = new JSONArray();for (Point point : ocrResultModel.getPoints()) {JSONArray points = new JSONArray();points.add(point.x);points.add(point.y);objects.add(points);}jsonObject.put("location", objects);jsonObject.put("score", ocrResultModel.getConfidence());jsonArray.add(jsonObject);}Log.d("OCR", jsonArray.toJSONString());return jsonArray;}}

8、打包插件

執(zhí)行:Build->Build Bundle(s)/APKS->Build APK(S)

?一個10M以下的插件就完成了。

9、在懶人精靈應用中編寫lua代碼

首先將apk文件放到資源目錄下,然后用loadApk()加載該插件

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 loader = LuaEngine.loadApk("TomatoOCR.apk")local OCR = loader.loadClass("com.tomato.ocr.lr.OCRApi")local ocr = OCR.init(LuaEngine.getContext())local type = -1;
-- type 可傳可不傳
-- type=0 : 只檢測
-- type=1 : 方向分類 + 識別
-- type=2 : 只識別
-- type=3 : 檢測 + 識別-- 只檢測文字位置:type=0
-- 全屏識別: type=3或者不傳type
-- 截取單行文字識別:type=1或者type=2-- 例子一
local result1 = ocr.ocrFile("/storage/emulated/0/0.jpg", type)
-- local result1 = ocr.ocrFiles(["/storage/emulated/0/0.jpg","/storage/emulated/0/0.jpg",...],type)
printEx(result1);-- 例子二
local result2 = ocr.ocrBitmap("bitmap對象", type)
-- local result2 = ocr.ocrBitmaps(["bitmap對象","bitmap對象",...],type)
printEx(result2);-- 例子三
local result3 = ocr.ocrBase64("圖片base64字符串", type)
-- local result3 = ocr.ocrBase64s(["圖片base64字符串","圖片base64字符串",...],type)
printEx(result3);-- 釋放
ocr.release()

完畢!!!

總結(jié)

????????相對來說,在熟悉PaddleOCR和Android開發(fā)的情況下,進行懶人精靈插件開發(fā)還是比較容易的,而且通過自己開發(fā)插件的形式可以集成更多的功能,比如只進行文本檢測、其他語言識別模型、身份識別模型等等,相對來說比較自由,這是官方提供不了的。今天就分享到這里,感謝支持!

插件下載地址:???????地址???????

http://aloenet.com.cn/news/40872.html

相關(guān)文章:

  • wordpress恢復源代碼willfast優(yōu)化工具下載
  • 電子商務網(wǎng)站設計畢業(yè)設計論文競價推廣員月掙多少
  • 網(wǎng)站怎么做優(yōu)化排名推廣下載
  • 福州外包加工網(wǎng)廈門seo優(yōu)化推廣
  • 保定設計網(wǎng)站建設寧波做網(wǎng)站的公司
  • 網(wǎng)站建設公司公司哪家好北京seo排名優(yōu)化網(wǎng)站
  • 汽車之家app下載最新版舟山百度seo
  • 做網(wǎng)站一屏一屏的網(wǎng)站推廣優(yōu)化教程
  • 互聯(lián)網(wǎng)網(wǎng)站建設計劃書搜索軟件使用排名
  • 電商網(wǎng)購網(wǎng)站怎么做做網(wǎng)站一般需要多少錢
  • 工具類網(wǎng)站怎么優(yōu)化seoseo綜合優(yōu)化公司
  • 建網(wǎng)站需要哪些費用東莞做網(wǎng)站推廣公司
  • 網(wǎng)站規(guī)劃建設方案手機怎么搭建網(wǎng)站
  • 大連企業(yè)網(wǎng)站設計欣賞如何讓百度收錄網(wǎng)站
  • 教育培訓網(wǎng)站建設網(wǎng)頁推廣鏈接怎么做
  • 做網(wǎng)站的費屬于什么費用搜索引擎優(yōu)化的五個方面
  • wordpress站內(nèi)短信谷歌商店paypal下載官網(wǎng)
  • 網(wǎng)站結(jié)構(gòu)設計淘寶直通車推廣怎么做
  • 微信瀏覽為網(wǎng)站的緩存怎么清理seo 推廣教程
  • 0基礎學做網(wǎng)站百度網(wǎng)址提交
  • 長沙旅游景點廊坊首頁霸屏優(yōu)化
  • 中國機械加工網(wǎng)加熱爐節(jié)能常用的seo網(wǎng)站優(yōu)化排名
  • 響應式網(wǎng)站建站seo初學教程
  • 煙臺微信網(wǎng)站建設網(wǎng)站搜索優(yōu)化
  • 懷化市建設局門戶網(wǎng)站網(wǎng)絡營銷推廣平臺
  • 定制型網(wǎng)站開發(fā)2345網(wǎng)址導航智能主板
  • 商丘哪里做網(wǎng)站百度收錄提交入口網(wǎng)址
  • dede網(wǎng)站打開速度慢如何優(yōu)化seo關(guān)鍵詞
  • 百度如何搜索到自己的網(wǎng)站網(wǎng)站綜合查詢工具
  • 鄭州電商網(wǎng)站開發(fā)港港網(wǎng)app下載最新版