From 93f5f47344a8348db2baeb9aa7c9a7d7ad1208a9 Mon Sep 17 00:00:00 2001 From: WenmuZhou <572459439@qq.com> Date: Fri, 22 Apr 2022 13:26:15 +0000 Subject: [PATCH 1/2] rename PaddleOCR to PPOCR --- deploy/cpp_infer/include/paddleocr.h | 6 +++--- deploy/cpp_infer/include/utility.h | 2 ++ deploy/cpp_infer/src/main.cpp | 2 +- deploy/cpp_infer/src/paddleocr.cpp | 29 ++++++++++++++-------------- deploy/cpp_infer/src/utility.cpp | 17 ++++++++++++++-- 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/deploy/cpp_infer/include/paddleocr.h b/deploy/cpp_infer/include/paddleocr.h index 499fbee317..6db9d86cb1 100644 --- a/deploy/cpp_infer/include/paddleocr.h +++ b/deploy/cpp_infer/include/paddleocr.h @@ -39,10 +39,10 @@ using namespace paddle_infer; namespace PaddleOCR { -class PaddleOCR { +class PPOCR { public: - explicit PaddleOCR(); - ~PaddleOCR(); + explicit PPOCR(); + ~PPOCR(); std::vector> ocr(std::vector cv_all_img_names, bool det = true, bool rec = true, bool cls = true); diff --git a/deploy/cpp_infer/include/utility.h b/deploy/cpp_infer/include/utility.h index 33e995fd02..eb18c06244 100644 --- a/deploy/cpp_infer/include/utility.h +++ b/deploy/cpp_infer/include/utility.h @@ -65,6 +65,8 @@ public: static bool PathExists(const std::string &path); + static void CreateDir(const std::string &path); + static void print_result(const std::vector &ocr_result); }; diff --git a/deploy/cpp_infer/src/main.cpp b/deploy/cpp_infer/src/main.cpp index 66ac795f59..b6085257e7 100644 --- a/deploy/cpp_infer/src/main.cpp +++ b/deploy/cpp_infer/src/main.cpp @@ -69,7 +69,7 @@ int main(int argc, char **argv) { cv::glob(FLAGS_image_dir, cv_all_img_names); std::cout << "total images num: " << cv_all_img_names.size() << endl; - PaddleOCR::PaddleOCR ocr = PaddleOCR::PaddleOCR(); + PPOCR ocr = PPOCR(); std::vector> ocr_results = ocr.ocr(cv_all_img_names, FLAGS_det, FLAGS_rec, FLAGS_cls); diff --git a/deploy/cpp_infer/src/paddleocr.cpp b/deploy/cpp_infer/src/paddleocr.cpp index 861461a01b..2ed9040c1a 100644 --- a/deploy/cpp_infer/src/paddleocr.cpp +++ b/deploy/cpp_infer/src/paddleocr.cpp @@ -21,7 +21,7 @@ namespace PaddleOCR { -PaddleOCR::PaddleOCR() { +PPOCR::PPOCR() { if (FLAGS_det) { this->detector_ = new DBDetector( FLAGS_det_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, FLAGS_gpu_mem, @@ -45,8 +45,8 @@ PaddleOCR::PaddleOCR() { } }; -void PaddleOCR::det(cv::Mat img, std::vector &ocr_results, - std::vector ×) { +void PPOCR::det(cv::Mat img, std::vector &ocr_results, + std::vector ×) { std::vector>> boxes; std::vector det_times; @@ -63,9 +63,9 @@ void PaddleOCR::det(cv::Mat img, std::vector &ocr_results, times[2] += det_times[2]; } -void PaddleOCR::rec(std::vector img_list, - std::vector &ocr_results, - std::vector ×) { +void PPOCR::rec(std::vector img_list, + std::vector &ocr_results, + std::vector ×) { std::vector rec_texts(img_list.size(), ""); std::vector rec_text_scores(img_list.size(), 0); std::vector rec_times; @@ -80,9 +80,9 @@ void PaddleOCR::rec(std::vector img_list, times[2] += rec_times[2]; } -void PaddleOCR::cls(std::vector img_list, - std::vector &ocr_results, - std::vector ×) { +void PPOCR::cls(std::vector img_list, + std::vector &ocr_results, + std::vector ×) { std::vector cls_labels(img_list.size(), 0); std::vector cls_scores(img_list.size(), 0); std::vector cls_times; @@ -98,8 +98,8 @@ void PaddleOCR::cls(std::vector img_list, } std::vector> -PaddleOCR::ocr(std::vector cv_all_img_names, bool det, bool rec, - bool cls) { +PPOCR::ocr(std::vector cv_all_img_names, bool det, bool rec, + bool cls) { std::vector time_info_det = {0, 0, 0}; std::vector time_info_rec = {0, 0, 0}; std::vector time_info_cls = {0, 0, 0}; @@ -188,9 +188,8 @@ PaddleOCR::ocr(std::vector cv_all_img_names, bool det, bool rec, return ocr_results; } // namespace PaddleOCR -void PaddleOCR::log(std::vector &det_times, - std::vector &rec_times, - std::vector &cls_times, int img_num) { +void PPOCR::log(std::vector &det_times, std::vector &rec_times, + std::vector &cls_times, int img_num) { if (det_times[0] + det_times[1] + det_times[2] > 0) { AutoLogger autolog_det("ocr_det", FLAGS_use_gpu, FLAGS_use_tensorrt, FLAGS_enable_mkldnn, FLAGS_cpu_threads, 1, "dynamic", @@ -212,7 +211,7 @@ void PaddleOCR::log(std::vector &det_times, autolog_cls.report(); } } -PaddleOCR::~PaddleOCR() { +PPOCR::~PPOCR() { if (this->detector_ != nullptr) { delete this->detector_; } diff --git a/deploy/cpp_infer/src/utility.cpp b/deploy/cpp_infer/src/utility.cpp index 339e992daa..45b8104626 100644 --- a/deploy/cpp_infer/src/utility.cpp +++ b/deploy/cpp_infer/src/utility.cpp @@ -16,10 +16,15 @@ #include #include #include -#include -#include + #include +#ifdef _WIN32 +#include +#else +#include +#endif + namespace PaddleOCR { std::vector Utility::ReadDict(const std::string &path) { @@ -206,6 +211,14 @@ bool Utility::PathExists(const std::string &path) { #endif // !_WIN32 } +void Utility::CreateDir(const std::string &path) { +#ifdef _WIN32 + _mkdir(path.c_str()); +#else + mkdir(path.c_str(), 0777); +#endif // !_WIN32 +} + void Utility::print_result(const std::vector &ocr_result) { for (int i = 0; i < ocr_result.size(); i++) { std::cout << i << "\t"; From 8abef5a19074b08f3814e72b5f5342f03004553c Mon Sep 17 00:00:00 2001 From: WenmuZhou <572459439@qq.com> Date: Fri, 22 Apr 2022 13:31:57 +0000 Subject: [PATCH 2/2] fix mkdir error --- deploy/cpp_infer/src/paddleocr.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/deploy/cpp_infer/src/paddleocr.cpp b/deploy/cpp_infer/src/paddleocr.cpp index 2ed9040c1a..e7b3777e78 100644 --- a/deploy/cpp_infer/src/paddleocr.cpp +++ b/deploy/cpp_infer/src/paddleocr.cpp @@ -17,8 +17,6 @@ #include "auto_log/autolog.h" #include -#include - namespace PaddleOCR { PPOCR::PPOCR() { @@ -139,7 +137,7 @@ PPOCR::ocr(std::vector cv_all_img_names, bool det, bool rec, } } else { if (!Utility::PathExists(FLAGS_output) && FLAGS_det) { - mkdir(FLAGS_output.c_str(), 0777); + Utility::CreateDir(FLAGS_output); } for (int i = 0; i < cv_all_img_names.size(); ++i) {