Image text recognition on Android

foreword

insert image description here

OCR is the abbreviation of Optical Character Recognition, translated as Optical Character Recognition, which refers to the use of optical methods to convert the text in paper documents into black and white dot matrix image files for printed characters, and recognize the text in the image through recognition software The technology of converting into text format for further editing and processing by word processing software (well, this is what I checked). To put it simply, OCR technology can recognize the text on the picture and extract it in text format.

This technology has a wide range of applications. For example, converting the contents of paper books into e-books used to be manually typed, but now it only needs to be scanned, and the scanned pictures are converted into text format through OCR technology. The efficiency and cost are unknown. How many times has it been improved.

runnable steps

1. Add dependencies

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

2. Download the font recognition library (chi_sim.traineddata Chinese Simplified, chi_tra.traineddata Chinese Traditional, eng.traineddata English library)

3. For the size of the apk, we need to copy the font recognition library file to the SD card directory, such as the copy of eng.traineddata

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 initialization

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

5. Process the bitmap image and identify the content inside

//OCR图片文字识别
baseApi.setImage(bitmap);
String result = baseApi.getUTF8Text().replace(" ", "").toLowerCase();

At this point, the study on "How Android realizes image text recognition" is over, and I hope to solve your doubts. Students who need more learning materials can scan the QR code below to get them!

[Tencent technical team produced] Android zero-based entry to proficiency, Android Studio installation tutorial + a full set of Android basic tutorials

Android is developed using the Java language, so if you want to learn Android, you must have a certain Java foundation, otherwise you will not be able to proceed at all. Of course, it doesn't matter if you don't have one. Here is an introductory tutorial on Android programming for you. I believe you can learn it quickly.

Information acquisition method:

Android programming tutorial

Java language basics from entry to familiarity

img

Kotlin language basics from entry to familiarity

img

Android technology stack from entry to familiarity

img

Android Jetpack family bucket comprehensive learning

img

Eclipse is generally used during learning Java.

But for Android it is recommended to use Android Studio instead of Eclipse ADT.

For novices, it may be difficult to install Android Studio. You can watch the following video and learn to install and run step by step.

Android Studio installation tutorial

img

With the learning of the Java stage, it is recommended to focus on video learning at this stage and supplement it with books to check for omissions. If you focus on books, you can type codes based on book explanations, supplemented by teaching videos to check for omissions. If you encounter problems, you can go to Baidu. Generally, many people will encounter problems when getting started, and they will give better answers.

It is necessary to master basic knowledge points, such as how to use the four major components, how to create a Service, how to layout, simple custom View, animation, network communication and other common technologies.

A full set of zero-based tutorials has been prepared for you, if you need it, you can add the QR code below to get it for free

A full set of Android basic tutorials

img

img

img

imgimg

img

img

imgInformation acquisition method:

Guess you like

Origin blog.csdn.net/Android_XG/article/details/129492753