diff --git a/deploy/cpp_infer/include/paddleocr.h b/deploy/cpp_infer/include/paddleocr.h index 499fbee3172abe71fd84ce3c5a18d421d7bc3139..6db9d86cb152bfcc708a87c6a98be59d88a5d8db 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 33e995fd02696ab45be92220102faa6d3230ddfe..eb18c0624492e9b47de156d60611d637d8dca6c3 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 66ac795f59c8039b046d11819137457c15a5c3ee..b6085257e7a7f517e308895d5219d55f032264fd 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 861461a01b00269860d74f5ef22bc894920d323b..2ed9040c1a74b21c53812ad7a6ad048f9933315e 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 339e992daa1489737ac92b45ca7d13f71a41abc2..45b8104626cfc3d128e14ece8ba6763f0986cfe4 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";