未验证 提交 95ac9c0e 编写于 作者: Z zhoujun 提交者: GitHub

Merge pull request #6044 from WenmuZhou/cpp_infer1

rename PaddleOCR to PPOCR
...@@ -39,10 +39,10 @@ using namespace paddle_infer; ...@@ -39,10 +39,10 @@ using namespace paddle_infer;
namespace PaddleOCR { namespace PaddleOCR {
class PaddleOCR { class PPOCR {
public: public:
explicit PaddleOCR(); explicit PPOCR();
~PaddleOCR(); ~PPOCR();
std::vector<std::vector<OCRPredictResult>> std::vector<std::vector<OCRPredictResult>>
ocr(std::vector<cv::String> cv_all_img_names, bool det = true, ocr(std::vector<cv::String> cv_all_img_names, bool det = true,
bool rec = true, bool cls = true); bool rec = true, bool cls = true);
......
...@@ -65,6 +65,8 @@ public: ...@@ -65,6 +65,8 @@ public:
static bool PathExists(const std::string &path); static bool PathExists(const std::string &path);
static void CreateDir(const std::string &path);
static void print_result(const std::vector<OCRPredictResult> &ocr_result); static void print_result(const std::vector<OCRPredictResult> &ocr_result);
}; };
......
...@@ -69,7 +69,7 @@ int main(int argc, char **argv) { ...@@ -69,7 +69,7 @@ int main(int argc, char **argv) {
cv::glob(FLAGS_image_dir, cv_all_img_names); cv::glob(FLAGS_image_dir, cv_all_img_names);
std::cout << "total images num: " << cv_all_img_names.size() << endl; std::cout << "total images num: " << cv_all_img_names.size() << endl;
PaddleOCR::PaddleOCR ocr = PaddleOCR::PaddleOCR(); PPOCR ocr = PPOCR();
std::vector<std::vector<OCRPredictResult>> ocr_results = std::vector<std::vector<OCRPredictResult>> ocr_results =
ocr.ocr(cv_all_img_names, FLAGS_det, FLAGS_rec, FLAGS_cls); ocr.ocr(cv_all_img_names, FLAGS_det, FLAGS_rec, FLAGS_cls);
......
...@@ -17,11 +17,9 @@ ...@@ -17,11 +17,9 @@
#include "auto_log/autolog.h" #include "auto_log/autolog.h"
#include <numeric> #include <numeric>
#include <sys/stat.h>
namespace PaddleOCR { namespace PaddleOCR {
PaddleOCR::PaddleOCR() { PPOCR::PPOCR() {
if (FLAGS_det) { if (FLAGS_det) {
this->detector_ = new DBDetector( this->detector_ = new DBDetector(
FLAGS_det_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, FLAGS_gpu_mem, FLAGS_det_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, FLAGS_gpu_mem,
...@@ -45,8 +43,8 @@ PaddleOCR::PaddleOCR() { ...@@ -45,8 +43,8 @@ PaddleOCR::PaddleOCR() {
} }
}; };
void PaddleOCR::det(cv::Mat img, std::vector<OCRPredictResult> &ocr_results, void PPOCR::det(cv::Mat img, std::vector<OCRPredictResult> &ocr_results,
std::vector<double> &times) { std::vector<double> &times) {
std::vector<std::vector<std::vector<int>>> boxes; std::vector<std::vector<std::vector<int>>> boxes;
std::vector<double> det_times; std::vector<double> det_times;
...@@ -63,9 +61,9 @@ void PaddleOCR::det(cv::Mat img, std::vector<OCRPredictResult> &ocr_results, ...@@ -63,9 +61,9 @@ void PaddleOCR::det(cv::Mat img, std::vector<OCRPredictResult> &ocr_results,
times[2] += det_times[2]; times[2] += det_times[2];
} }
void PaddleOCR::rec(std::vector<cv::Mat> img_list, void PPOCR::rec(std::vector<cv::Mat> img_list,
std::vector<OCRPredictResult> &ocr_results, std::vector<OCRPredictResult> &ocr_results,
std::vector<double> &times) { std::vector<double> &times) {
std::vector<std::string> rec_texts(img_list.size(), ""); std::vector<std::string> rec_texts(img_list.size(), "");
std::vector<float> rec_text_scores(img_list.size(), 0); std::vector<float> rec_text_scores(img_list.size(), 0);
std::vector<double> rec_times; std::vector<double> rec_times;
...@@ -80,9 +78,9 @@ void PaddleOCR::rec(std::vector<cv::Mat> img_list, ...@@ -80,9 +78,9 @@ void PaddleOCR::rec(std::vector<cv::Mat> img_list,
times[2] += rec_times[2]; times[2] += rec_times[2];
} }
void PaddleOCR::cls(std::vector<cv::Mat> img_list, void PPOCR::cls(std::vector<cv::Mat> img_list,
std::vector<OCRPredictResult> &ocr_results, std::vector<OCRPredictResult> &ocr_results,
std::vector<double> &times) { std::vector<double> &times) {
std::vector<int> cls_labels(img_list.size(), 0); std::vector<int> cls_labels(img_list.size(), 0);
std::vector<float> cls_scores(img_list.size(), 0); std::vector<float> cls_scores(img_list.size(), 0);
std::vector<double> cls_times; std::vector<double> cls_times;
...@@ -98,8 +96,8 @@ void PaddleOCR::cls(std::vector<cv::Mat> img_list, ...@@ -98,8 +96,8 @@ void PaddleOCR::cls(std::vector<cv::Mat> img_list,
} }
std::vector<std::vector<OCRPredictResult>> std::vector<std::vector<OCRPredictResult>>
PaddleOCR::ocr(std::vector<cv::String> cv_all_img_names, bool det, bool rec, PPOCR::ocr(std::vector<cv::String> cv_all_img_names, bool det, bool rec,
bool cls) { bool cls) {
std::vector<double> time_info_det = {0, 0, 0}; std::vector<double> time_info_det = {0, 0, 0};
std::vector<double> time_info_rec = {0, 0, 0}; std::vector<double> time_info_rec = {0, 0, 0};
std::vector<double> time_info_cls = {0, 0, 0}; std::vector<double> time_info_cls = {0, 0, 0};
...@@ -139,7 +137,7 @@ PaddleOCR::ocr(std::vector<cv::String> cv_all_img_names, bool det, bool rec, ...@@ -139,7 +137,7 @@ PaddleOCR::ocr(std::vector<cv::String> cv_all_img_names, bool det, bool rec,
} }
} else { } else {
if (!Utility::PathExists(FLAGS_output) && FLAGS_det) { 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) { for (int i = 0; i < cv_all_img_names.size(); ++i) {
...@@ -188,9 +186,8 @@ PaddleOCR::ocr(std::vector<cv::String> cv_all_img_names, bool det, bool rec, ...@@ -188,9 +186,8 @@ PaddleOCR::ocr(std::vector<cv::String> cv_all_img_names, bool det, bool rec,
return ocr_results; return ocr_results;
} // namespace PaddleOCR } // namespace PaddleOCR
void PaddleOCR::log(std::vector<double> &det_times, void PPOCR::log(std::vector<double> &det_times, std::vector<double> &rec_times,
std::vector<double> &rec_times, std::vector<double> &cls_times, int img_num) {
std::vector<double> &cls_times, int img_num) {
if (det_times[0] + det_times[1] + det_times[2] > 0) { if (det_times[0] + det_times[1] + det_times[2] > 0) {
AutoLogger autolog_det("ocr_det", FLAGS_use_gpu, FLAGS_use_tensorrt, AutoLogger autolog_det("ocr_det", FLAGS_use_gpu, FLAGS_use_tensorrt,
FLAGS_enable_mkldnn, FLAGS_cpu_threads, 1, "dynamic", FLAGS_enable_mkldnn, FLAGS_cpu_threads, 1, "dynamic",
...@@ -212,7 +209,7 @@ void PaddleOCR::log(std::vector<double> &det_times, ...@@ -212,7 +209,7 @@ void PaddleOCR::log(std::vector<double> &det_times,
autolog_cls.report(); autolog_cls.report();
} }
} }
PaddleOCR::~PaddleOCR() { PPOCR::~PPOCR() {
if (this->detector_ != nullptr) { if (this->detector_ != nullptr) {
delete this->detector_; delete this->detector_;
} }
......
...@@ -16,10 +16,15 @@ ...@@ -16,10 +16,15 @@
#include <include/utility.h> #include <include/utility.h>
#include <iostream> #include <iostream>
#include <ostream> #include <ostream>
#include <sys/stat.h>
#include <sys/types.h>
#include <vector> #include <vector>
#ifdef _WIN32
#include <direct.h>
#else
#include <sys/stat.h>
#endif
namespace PaddleOCR { namespace PaddleOCR {
std::vector<std::string> Utility::ReadDict(const std::string &path) { std::vector<std::string> Utility::ReadDict(const std::string &path) {
...@@ -206,6 +211,14 @@ bool Utility::PathExists(const std::string &path) { ...@@ -206,6 +211,14 @@ bool Utility::PathExists(const std::string &path) {
#endif // !_WIN32 #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<OCRPredictResult> &ocr_result) { void Utility::print_result(const std::vector<OCRPredictResult> &ocr_result) {
for (int i = 0; i < ocr_result.size(); i++) { for (int i = 0; i < ocr_result.size(); i++) {
std::cout << i << "\t"; std::cout << i << "\t";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册