nndeploy C++ API  0.2.0
nndeploy C++ API
ocr.h
Go to the documentation of this file.
1 #ifndef _NNDEPLOY_OCR_OCR_H_
2 #define _NNDEPLOY_OCR_OCR_H_
3 
4 #include "nndeploy/base/any.h"
5 #include "nndeploy/base/common.h"
7 #include "nndeploy/base/log.h"
8 #include "nndeploy/base/macro.h"
9 #include "nndeploy/base/object.h"
11 #include "nndeploy/base/param.h"
12 #include "nndeploy/base/status.h"
13 #include "nndeploy/base/string.h"
14 #include "nndeploy/dag/edge.h"
15 #include "nndeploy/dag/graph.h"
16 #include "nndeploy/dag/node.h"
17 #include "nndeploy/device/buffer.h"
18 #include "nndeploy/device/device.h"
20 #include "nndeploy/device/tensor.h"
21 #include "nndeploy/infer/infer.h"
23 #include "nndeploy/ocr/result.h"
25 
26 namespace nndeploy {
27 namespace ocr {
28 
30  public:
31  RotateCropImage(const std::string &name) : Node(name) {
32  key_ = "nndeploy::ocr::RotateCropImage";
33  desc_ = "RotateCropImage";
34  this->setInputTypeInfo<OCRResult>();
35  this->setInputTypeInfo<cv::Mat>();
36  this->setOutputTypeInfo<OCRResult>();
37  }
38  RotateCropImage(const std::string &name, std::vector<dag::Edge *> inputs,
39  std::vector<dag::Edge *> outputs)
40  : Node(name, inputs, outputs) {
41  key_ = "nndeploy::ocr::RotateCropImage";
42  desc_ = "RotateCropImage";
43  this->setInputTypeInfo<OCRResult>();
44  this->setInputTypeInfo<cv::Mat>();
45  this->setOutputTypeInfo<OCRResult>();
46  }
48  virtual ~RotateCropImage(){};
49 
50  virtual base::Status run();
51 };
52 
54  public:
55  RotateImage180(const std::string &name) : Node(name) {
56  key_ = "nndeploy::ocr::RotateImage180";
57  desc_ = "RotateImage180";
58  this->setInputTypeInfo<OCRResult>();
59  this->setInputTypeInfo<OCRResult>();
60  this->setOutputTypeInfo<OCRResult>();
61  }
62  RotateImage180(const std::string &name, std::vector<dag::Edge *> inputs,
63  std::vector<dag::Edge *> outputs)
64  : Node(name, inputs, outputs) {
65  key_ = "nndeploy::ocr::RotateImage180";
66  desc_ = "RotateImage180";
67  this->setInputTypeInfo<OCRResult>();
68  this->setInputTypeInfo<OCRResult>();
69  this->setOutputTypeInfo<OCRResult>();
70  }
72  virtual ~RotateImage180(){};
73 
74  virtual base::Status run();
75 };
76 
78  public:
79  std::vector<std::string> texts_;
80 
83  rapidjson::Value &json,
84  rapidjson::Document::AllocatorType &allocator) override {
85  rapidjson::Value texts_json(rapidjson::kArrayType);
86  for (const auto &text : texts_) {
87  texts_json.PushBack(rapidjson::Value(text.c_str(), allocator), allocator);
88  }
89  json.AddMember("texts_", texts_json, allocator);
90  return base::kStatusCodeOk;
91  }
92 
94  virtual base::Status deserialize(rapidjson::Value &json) override {
95  if (json.HasMember("texts_") && json["texts_"].IsArray()) {
96  texts_.clear();
97  for (const auto &text : json["texts_"].GetArray()) {
98  texts_.push_back(text.GetString());
99  }
100  }
101  return base::kStatusCodeOk;
102  }
103 };
104 
106  public:
107  std::string path_ = "resources/others/ocr_out.txt";
108 
110  virtual base::Status serialize(rapidjson::Value &json,
111  rapidjson::Document::AllocatorType &allocator);
113  virtual base::Status deserialize(rapidjson::Value &json);
114 };
115 
117  public:
118  PrintOcrNode(const std::string &name, std::vector<dag::Edge *> inputs,
119  std::vector<dag::Edge *> outputs)
120  : Node(name, inputs, outputs) {
121  key_ = "nndeploy::ocr::PrintOcrNode";
122  desc_ = "Print Text";
123  param_ = std::make_shared<PrintOcrNodeParam>();
124  this->setInputTypeInfo<OCRResult>();
125  this->setNodeType(dag::NodeType::kNodeTypeOutput);
126  this->setIoType(dag::IOType::kIOTypeText);
127  }
128 
129  virtual ~PrintOcrNode() {}
130  base::Status setPath(const std::string &path) {
131  if (path.empty()) {
133  }
134  auto param = dynamic_cast<PrintOcrNodeParam *>(getParam());
135  param->path_ = path;
136  return base::kStatusCodeOk;
137  }
138  virtual base::Status run();
139 };
140 
141 } // namespace ocr
142 } // namespace nndeploy
143 
144 #endif
virtual base::Status deserialize(rapidjson::Value &json)
virtual std::string serialize()
Node base class.
Definition: node.h:171
virtual base::Status deserialize(rapidjson::Value &json) override
Definition: ocr.h:94
virtual base::Status serialize(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) override
Definition: ocr.h:82
std::vector< std::string > texts_
Definition: ocr.h:79
virtual base::Status serialize(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator)
virtual base::Status deserialize(rapidjson::Value &json)
base::Status setPath(const std::string &path)
Definition: ocr.h:130
virtual base::Status run()
Run node (pure virtual function)
PrintOcrNode(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs)
Definition: ocr.h:118
virtual ~PrintOcrNode()
Definition: ocr.h:129
virtual base::Status run()
Run node (pure virtual function)
PostProcessor util_post_processor_
Definition: ocr.h:47
RotateCropImage(const std::string &name)
Definition: ocr.h:31
RotateCropImage(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs)
Definition: ocr.h:38
virtual ~RotateCropImage()
Definition: ocr.h:48
virtual base::Status run()
Run node (pure virtual function)
RotateImage180(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs)
Definition: ocr.h:62
RotateImage180(const std::string &name)
Definition: ocr.h:55
virtual ~RotateImage180()
Definition: ocr.h:72
PostProcessor util_post_processor_
Definition: ocr.h:71
#define NNDEPLOY_CC_API
api
Definition: macro.h:29
@ kStatusCodeOk
Definition: status.h:13
@ kStatusCodeErrorInvalidParam
Definition: status.h:21