Android uses Baidu Flying Paddle for local recognition of OCR

During the project process, due to the time-consuming call interface recognition, the open source model of Flying Paddle was used to do local OCR recognition. Its SDK is completely free to use and has no validity period limit.

We are using the OCRV3 package here, but only use the OCR recognition during the scanning process

Import package file by demo

Call method:

    private void uploadOcr(Bitmap bitmap, Handler handler) {
        try {
            mInferConfig = new InferConfig(activity.getAssets(), "infer");
            mInferConfig.setThread(Util.getInferCores());


            mOcrManager = new InferManager(activity, mInferConfig, "XXXX-XXXX-XXXX-XXXX");
            StringBuffer stringBuffer = new StringBuffer();
            List<com.baidu.ai.edge.core.ocr.OcrResultModel> modelList;
            modelList = mOcrManager.ocr(bitmap, 0.1f);
            List<BasePolygonResultModel> results = new ArrayList<>();
            for (int i = 0; i < modelList.size(); i++) {
                com.baidu.ai.edge.core.ocr.OcrResultModel mOcrResultModel = modelList.get(i);
                OcrViewResultModel mOcrViewResultModel = new OcrViewResultModel();
                mOcrViewResultModel.setColorId(mOcrResultModel.getLabelIndex());
                mOcrViewResultModel.setIndex(i + 1);
                mOcrViewResultModel.setConfidence(mOcrResultModel.getConfidence());
                mOcrViewResultModel.setName(mOcrResultModel.getLabel());
                mOcrViewResultModel.setBounds(mOcrResultModel.getPoints());
                mOcrViewResultModel.setTextOverlay(true);
                results.add(mOcrViewResultModel);
            }
            mOcrManager.destroy();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

The results returned here are identified by rectangles one by one, so the final result needs to be judged by the x and y values ​​of the rectangles to calculate and splicing.

Guess you like

Origin blog.csdn.net/QhappyfishQ/article/details/126458900