From c3785440a12f8a656015a2d271ad61c6c83e71a5 Mon Sep 17 00:00:00 2001 From: authorfu Date: Mon, 3 Aug 2020 17:17:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=94=B9=E4=B8=BA=E8=8B=B1?= =?UTF-8?q?=E8=AF=AD=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../android_demo/app/src/main/cpp/native.cpp | 2 +- .../app/src/main/cpp/ocr_ppredictor.cpp | 2 +- .../app/src/main/cpp/ocr_ppredictor.h | 24 +++++++++---------- .../app/src/main/cpp/ppredictor.h | 8 +++---- .../app/src/main/cpp/predictor_output.h | 8 +++---- .../paddle/lite/demo/ocr/MiniActivity.java | 13 +++++----- .../baidu/paddle/lite/demo/ocr/Predictor.java | 4 ++-- 7 files changed, 31 insertions(+), 30 deletions(-) diff --git a/deploy/android_demo/app/src/main/cpp/native.cpp b/deploy/android_demo/app/src/main/cpp/native.cpp index 33233e53..390c594d 100644 --- a/deploy/android_demo/app/src/main/cpp/native.cpp +++ b/deploy/android_demo/app/src/main/cpp/native.cpp @@ -30,7 +30,7 @@ Java_com_baidu_paddle_lite_demo_ocr_OCRPredictorNative_init(JNIEnv *env, jobject } /** - * "LITE_POWER_HIGH" 转为 paddle::lite_api::LITE_POWER_HIGH + * "LITE_POWER_HIGH" convert to paddle::lite_api::LITE_POWER_HIGH * @param cpu_mode * @return */ diff --git a/deploy/android_demo/app/src/main/cpp/ocr_ppredictor.cpp b/deploy/android_demo/app/src/main/cpp/ocr_ppredictor.cpp index 6548157b..3d014771 100644 --- a/deploy/android_demo/app/src/main/cpp/ocr_ppredictor.cpp +++ b/deploy/android_demo/app/src/main/cpp/ocr_ppredictor.cpp @@ -37,7 +37,7 @@ int OCR_PPredictor::init_from_file(const std::string &det_model_path, const std: return RETURN_OK; } /** - * 调试用,保存第一步的框选结果 + * for debug use, show result of First Step * @param filter_boxes * @param boxes * @param srcimg diff --git a/deploy/android_demo/app/src/main/cpp/ocr_ppredictor.h b/deploy/android_demo/app/src/main/cpp/ocr_ppredictor.h index 9adbf1e3..eb2bc3bc 100644 --- a/deploy/android_demo/app/src/main/cpp/ocr_ppredictor.h +++ b/deploy/android_demo/app/src/main/cpp/ocr_ppredictor.h @@ -12,26 +12,26 @@ namespace ppredictor { /** - * 配置 + * Config */ struct OCR_Config { - int thread_num = 4; // 线程数 + int thread_num = 4; // Thread num paddle::lite_api::PowerMode mode = paddle::lite_api::LITE_POWER_HIGH; // PaddleLite Mode }; /** - * 一个四边形内图片的推理结果, + * PolyGone Result */ struct OCRPredictResult { - std::vector word_index; // + std::vector word_index; std::vector> points; float score; }; /** - * OCR 一共有2个模型进行推理, - * 1. 使用第一个模型(det),框选出多个四边形 - * 2. 从原图从抠出这些多边形,使用第二个模型(rec),获取文本 + * OCR there are 2 models + * 1. First model(det),select polygones to show where are the texts + * 2. crop from the origin images, use these polygones to infer */ class OCR_PPredictor : public PPredictor_Interface { public: @@ -50,7 +50,7 @@ public: int init(const std::string &det_model_content, const std::string &rec_model_content); int init_from_file(const std::string &det_model_path, const std::string &rec_model_path); /** - * 返回OCR结果 + * Return OCR result * @param dims * @param input_data * @param input_len @@ -69,7 +69,7 @@ public: private: /** - * 从第一个模型的结果中计算有文字的四边形 + * calcul Polygone from the result image of first model * @param pred * @param output_height * @param output_width @@ -81,7 +81,7 @@ private: const cv::Mat &origin); /** - * 第二个模型的推理 + * infer for second model * * @param boxes * @param origin @@ -91,14 +91,14 @@ private: infer_rec(const std::vector>> &boxes, const cv::Mat &origin); /** - * 第二个模型提取文字的后处理 + * Postprocess or sencod model to extract text * @param res * @return */ std::vector postprocess_rec_word_index(const PredictorOutput &res); /** - * 计算第二个模型的文字的置信度 + * calculate confidence of second model text result * @param res * @return */ diff --git a/deploy/android_demo/app/src/main/cpp/ppredictor.h b/deploy/android_demo/app/src/main/cpp/ppredictor.h index 9cdf3a88..1391109f 100644 --- a/deploy/android_demo/app/src/main/cpp/ppredictor.h +++ b/deploy/android_demo/app/src/main/cpp/ppredictor.h @@ -7,7 +7,7 @@ namespace ppredictor { /** - * PaddleLite Preditor 通用接口 + * PaddleLite Preditor Common Interface */ class PPredictor_Interface { public: @@ -21,7 +21,7 @@ public: }; /** - * 通用推理 + * Common Predictor */ class PPredictor : public PPredictor_Interface { public: @@ -33,9 +33,9 @@ public: } /** - * 初始化paddlitelite的opt模型,nb格式,与init_paddle二选一 + * init paddlitelite opt model,nb format ,or use ini_paddle * @param model_content - * @return 0 目前是固定值0, 之后其他值表示失败 + * @return 0 */ virtual int init_nb(const std::string &model_content); diff --git a/deploy/android_demo/app/src/main/cpp/predictor_output.h b/deploy/android_demo/app/src/main/cpp/predictor_output.h index c56e2d9a..ec7086c6 100644 --- a/deploy/android_demo/app/src/main/cpp/predictor_output.h +++ b/deploy/android_demo/app/src/main/cpp/predictor_output.h @@ -21,10 +21,10 @@ public: const std::vector> get_lod() const; const std::vector get_shape() const; - std::vector data; // 通常是float返回,与下面的data_int二选一 - std::vector data_int; // 少数层是int返回,与 data二选一 - std::vector shape; // PaddleLite输出层的shape - std::vector> lod; // PaddleLite输出层的lod + std::vector data; // return float, or use data_int + std::vector data_int; // several layers return int ,or use data + std::vector shape; // PaddleLite output shape + std::vector> lod; // PaddleLite output lod private: std::unique_ptr _tensor; diff --git a/deploy/android_demo/app/src/main/java/com/baidu/paddle/lite/demo/ocr/MiniActivity.java b/deploy/android_demo/app/src/main/java/com/baidu/paddle/lite/demo/ocr/MiniActivity.java index b40cd5f0..d5608911 100644 --- a/deploy/android_demo/app/src/main/java/com/baidu/paddle/lite/demo/ocr/MiniActivity.java +++ b/deploy/android_demo/app/src/main/java/com/baidu/paddle/lite/demo/ocr/MiniActivity.java @@ -41,8 +41,8 @@ public class MiniActivity extends AppCompatActivity { private String assetlabelFilePath = "labels/ppocr_keys_v1.txt"; private Button button; - private ImageView imageView; // 显示图像 - private TextView textView; // 显示结果 + private ImageView imageView; // image result + private TextView textView; // text result @Override protected void onCreate(Bundle savedInstanceState) { @@ -85,7 +85,7 @@ public class MiniActivity extends AppCompatActivity { } } }; - sender.sendEmptyMessage(REQUEST_LOAD_MODEL); // 对应上面的REQUEST_LOAD_MODEL, 调用onLoadModel() + sender.sendEmptyMessage(REQUEST_LOAD_MODEL); // corresponding to REQUEST_LOAD_MODEL, to call onLoadModel() imageView = findViewById(R.id.imageView); textView = findViewById(R.id.sample_text); @@ -112,7 +112,7 @@ public class MiniActivity extends AppCompatActivity { } /** - * onCreate的时候调用, 模型初始化 + * call in onCreate, model init * * @return */ @@ -124,7 +124,8 @@ public class MiniActivity extends AppCompatActivity { } /** - * on + * init engine + * call in onCreate * * @return */ @@ -133,7 +134,7 @@ public class MiniActivity extends AppCompatActivity { String assetImagePath = "images/5.jpg"; InputStream imageStream = getAssets().open(assetImagePath); Bitmap image = BitmapFactory.decodeStream(imageStream); - // 这里输入是Bitmap + // Input is Bitmap predictor.setInputImage(image); return predictor.isLoaded() && predictor.runModel(); } catch (IOException e) { diff --git a/deploy/android_demo/app/src/main/java/com/baidu/paddle/lite/demo/ocr/Predictor.java b/deploy/android_demo/app/src/main/java/com/baidu/paddle/lite/demo/ocr/Predictor.java index 0eedf3dc..078bba28 100644 --- a/deploy/android_demo/app/src/main/java/com/baidu/paddle/lite/demo/ocr/Predictor.java +++ b/deploy/android_demo/app/src/main/java/com/baidu/paddle/lite/demo/ocr/Predictor.java @@ -228,7 +228,7 @@ public class Predictor { for (int i = 0; i < warmupIterNum; i++) { paddlePredictor.runImage(inputData, width, height, channels, inputImage); } - warmupIterNum = 0; // 之后不要再warm了 + warmupIterNum = 0; // do not need warm // Run inference start = new Date(); ArrayList results = paddlePredictor.runImage(inputData, width, height, channels, inputImage); @@ -323,7 +323,7 @@ public class Predictor { for (Point p : result.getPoints()) { sb.append("(").append(p.x).append(",").append(p.y).append(") "); } - Log.i(TAG, sb.toString()); // 这里在logcat里打印结果 + Log.i(TAG, sb.toString()); // show LOG in Logcat panel outputResultSb.append(i + 1).append(": ").append(result.getLabel()).append("\n"); } outputResult = outputResultSb.toString(); -- GitLab