中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

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

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

目的

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

準(zhǔn)備工作

1、android studio最新版本即可

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

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

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

3、導(dǎo)入Android studio并成功運(yùn)行

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

插件開發(fā)

1、項(xiàng)目結(jié)構(gòu)對(duì)比

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

?2、插件SDK集成

在項(xiàng)目的build.gradle文件中添加:

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

在app的build.gradle文件中添加

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

3、刪除無(wú)用的Activity文件

?4、修改AndroidManifest.xml

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

<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;// 檢測(cè)protected int run_det = 1;// 分類protected int run_cls = 1;// 識(shí)別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) {// 只檢測(cè)return this.ocrFile(imagePath, 1, 0, 0).toJSONString();} else if (type == 1) {// 方向分類 + 識(shí)別return this.ocrFile(imagePath, 0, 1, 1).toJSONString();} else if (type == 2) {// 只識(shí)別return this.ocrFile(imagePath, 0, 0, 1).toJSONString();} else if (type == 3) {// 檢測(cè) + 識(shí)別return this.ocrFile(imagePath, 1, 0, 1).toJSONString();}// 默認(rèn) 檢測(cè) + 方向分類 + 識(shí)別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("****************", "無(wú)法運(yùn)行!");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) {// 只檢測(cè)return this.ocrBitmap(bitmap, 1, 0, 0).toJSONString();} else if (type == 1) {// 方向分類 + 識(shí)別return this.ocrBitmap(bitmap, 0, 1, 1).toJSONString();} else if (type == 2) {// 只識(shí)別return this.ocrBitmap(bitmap, 0, 0, 1).toJSONString();} else if (type == 3) {// 檢測(cè) + 識(shí)別return this.ocrBitmap(bitmap, 1, 0, 1).toJSONString();}// 默認(rèn) 檢測(cè) + 方向分類 + 識(shí)別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("****************", "無(wú)法運(yùn)行!");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)

?一個(gè)10M以下的插件就完成了。

9、在懶人精靈應(yīng)用中編寫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 : 只檢測(cè)
-- type=1 : 方向分類 + 識(shí)別
-- type=2 : 只識(shí)別
-- type=3 : 檢測(cè) + 識(shí)別-- 只檢測(cè)文字位置:type=0
-- 全屏識(shí)別: type=3或者不傳type
-- 截取單行文字識(shí)別: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對(duì)象", type)
-- local result2 = ocr.ocrBitmaps(["bitmap對(duì)象","bitmap對(duì)象",...],type)
printEx(result2);-- 例子三
local result3 = ocr.ocrBase64("圖片base64字符串", type)
-- local result3 = ocr.ocrBase64s(["圖片base64字符串","圖片base64字符串",...],type)
printEx(result3);-- 釋放
ocr.release()

完畢!!!

總結(jié)

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

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

http://www.risenshineclean.com/news/40872.html

相關(guān)文章:

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