欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實(shí)現(xiàn)圖片文字識別

 更新時間:2021年07月11日 10:06:49   作者:愛樂寫代碼  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)圖片文字識別,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

導(dǎo)言

OCR,tess-two ,openCV等暈人的東西先分清,OCR,tess-two是圖片文字識別,而openCV是圖像識別比對,對于更復(fù)雜的圖片文字識別需求可以采用百度云人工智能通用文字識別開發(fā)的SDK,準(zhǔn)確性更高

可運(yùn)行的步驟

1、添加依賴

implementation 'com.rmtheis:tess-two:8.0.0'

2、下載字體識別庫(chi_sim.traineddata 中文簡體,chi_tra.traineddata 中文繁體,eng.traineddata 英文庫)

3、為了apk的大小,我們需要將字體識別庫文件拷貝到SD卡目錄中,比如eng.traineddata的copy

private String mDataPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator;
private String mFilePath = mDataPath + File.separator + "tessdata" + File.separator + "eng.traineddata";
private void copyFile() {
        try {
            File mFile = new File(mFilePath);
            if (mFile.exists()) {
                mFile.delete();
            }
            if (!mFile.exists()) {
                File p = new File(mFile.getParent());
                if (!p.exists()) {
                    p.mkdirs();
                }
                try {
                    mFile.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            OutputStream os = new FileOutputStream(mFilePath);
            InputStream is = this.getAssets().open("eng.traineddata");
            byte[] buffer = new byte[1024];
            int len = 0;
            while ((len = is.read(buffer)) != -1) {
                os.write(buffer, 0, len);
            }
            os.flush();
            os.close();
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

4、tess two初始化

TessBaseAPI baseApi;
baseApi = new TessBaseAPI();
baseApi.init(mDataPath, "eng");

5、處理bitmap圖片并識別里面的內(nèi)容

//OCR圖片文字識別
baseApi.setImage(bitmap);
String result = baseApi.getUTF8Text().replace(" ", "").toLowerCase();

6、他要求看需求,本文結(jié)束

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論