1 #ifndef _NNDEPLOY_DETECT_DETECTER_OCR_OCR_H_
2 #define _NNDEPLOY_DETECT_DETECTER_OCR_OCR_H_
49 int max_side_len_ = 960;
50 bool normalize_ =
true;
51 float scale_[3] = {1.0f / 255.0f, 1.0f / 255.0f, 1.0f / 255.0f};
52 float mean_[3] = {0.485f, 0.456f, 0.406f};
53 float std_[3] = {0.229f, 0.224f, 0.225f};
64 rapidjson::Value &json,
65 rapidjson::Document::AllocatorType &allocator)
override {
67 json.AddMember(
"src_pixel_type_",
68 rapidjson::Value(src_pixel_type_str.c_str(), allocator),
71 json.AddMember(
"dst_pixel_type_",
72 rapidjson::Value(dst_pixel_type_str.c_str(), allocator),
75 json.AddMember(
"interp_type_",
76 rapidjson::Value(interp_type_str.c_str(), allocator),
79 json.AddMember(
"data_type_",
80 rapidjson::Value(data_type_str.c_str(), allocator),
83 json.AddMember(
"data_format_",
84 rapidjson::Value(data_format_str.c_str(), allocator),
86 json.AddMember(
"h_", h_, allocator);
87 json.AddMember(
"w_", w_, allocator);
89 json.AddMember(
"max_side_len_", max_side_len_, allocator);
90 json.AddMember(
"normalize_", normalize_, allocator);
92 rapidjson::Value scale_array(rapidjson::kArrayType);
93 rapidjson::Value mean_array(rapidjson::kArrayType);
94 rapidjson::Value std_array(rapidjson::kArrayType);
95 for (
int i = 0; i < 3; i++) {
96 scale_array.PushBack(scale_[i], allocator);
97 mean_array.PushBack(mean_[i], allocator);
98 std_array.PushBack(std_[i], allocator);
100 json.AddMember(
"scale_", scale_array, allocator);
101 json.AddMember(
"mean_", mean_array, allocator);
102 json.AddMember(
"std_", std_array, allocator);
105 json.AddMember(
"border_type_",
106 rapidjson::Value(border_type_str.c_str(), allocator),
108 json.AddMember(
"top_", top_, allocator);
109 json.AddMember(
"bottom_", bottom_, allocator);
110 json.AddMember(
"left_", left_, allocator);
111 json.AddMember(
"right_", right_, allocator);
113 rapidjson::Value border_val_array(rapidjson::kArrayType);
114 for (
int i = 0; i < 4; i++) {
115 border_val_array.PushBack(border_val_.
val_[i], allocator);
117 json.AddMember(
"border_val_", border_val_array, allocator);
124 if (json.HasMember(
"src_pixel_type_") &&
125 json[
"src_pixel_type_"].IsString()) {
129 if (json.HasMember(
"dst_pixel_type_") &&
130 json[
"dst_pixel_type_"].IsString()) {
134 if (json.HasMember(
"interp_type_") && json[
"interp_type_"].IsString()) {
137 if (json.HasMember(
"data_type_") && json[
"data_type_"].IsString()) {
140 if (json.HasMember(
"data_format_") && json[
"data_format_"].IsString()) {
143 if (json.HasMember(
"h_") && json[
"h_"].IsInt()) {
144 h_ = json[
"h_"].GetInt();
146 if (json.HasMember(
"w_") && json[
"w_"].IsInt()) {
147 w_ = json[
"w_"].GetInt();
150 if (json.HasMember(
"max_side_len_") && json[
"max_side_len_"].IsInt()) {
151 max_side_len_ = json[
"max_side_len_"].GetInt();
153 if (json.HasMember(
"normalize_") && json[
"normalize_"].IsBool()) {
154 normalize_ = json[
"normalize_"].GetBool();
157 if (json.HasMember(
"scale_") && json[
"scale_"].IsArray()) {
158 const rapidjson::Value &scale_array = json[
"scale_"];
159 for (
int i = 0; i < 3 && i < scale_array.Size(); i++) {
160 if (scale_array[i].IsFloat()) {
161 scale_[i] = scale_array[i].GetFloat();
165 if (json.HasMember(
"mean_") && json[
"mean_"].IsArray()) {
166 const rapidjson::Value &mean_array = json[
"mean_"];
167 for (
int i = 0; i < 3 && i < mean_array.Size(); i++) {
168 if (mean_array[i].IsFloat()) {
169 mean_[i] = mean_array[i].GetFloat();
173 if (json.HasMember(
"std_") && json[
"std_"].IsArray()) {
174 const rapidjson::Value &std_array = json[
"std_"];
175 for (
int i = 0; i < 3 && i < std_array.Size(); i++) {
176 if (std_array[i].IsFloat()) {
177 std_[i] = std_array[i].GetFloat();
182 if (json.HasMember(
"border_type_") && json[
"border_type_"].IsString()) {
185 if (json.HasMember(
"top_") && json[
"top_"].IsInt()) {
186 top_ = json[
"top_"].GetInt();
188 if (json.HasMember(
"bottom_") && json[
"bottom_"].IsInt()) {
189 bottom_ = json[
"bottom_"].GetInt();
191 if (json.HasMember(
"left_") && json[
"left_"].IsInt()) {
192 left_ = json[
"left_"].GetInt();
194 if (json.HasMember(
"right_") && json[
"right_"].IsInt()) {
195 right_ = json[
"right_"].GetInt();
198 if (json.HasMember(
"border_val_") && json[
"border_val_"].IsArray()) {
199 const rapidjson::Value &border_val_array = json[
"border_val_"];
200 for (
int i = 0; i < 4 && i < border_val_array.Size(); i++) {
201 if (border_val_array[i].IsFloat()) {
202 border_val_.
val_[i] = border_val_array[i].GetFloat();
214 key_ =
"nndeploy::ocr::DetectorPreProcess";
216 "ocr detectorpreprocess cv::Mat to "
217 "device::Tensor[resize->pad->normalize->transpose]";
218 param_ = std::make_shared<DetectorPreProcessParam>();
219 this->setInputTypeInfo<cv::Mat>();
220 this->setOutputTypeInfo<device::Tensor>();
223 std::vector<dag::Edge *> outputs)
224 : dag::Node(name, inputs, outputs) {
225 key_ =
"nndeploy::ocr::DetectorPreProcess";
227 "ocr detectorpreprocess cv::Mat to "
228 "device::Tensor[resize->pad->normalize->transpose]";
229 param_ = std::make_shared<DetectorPreProcessParam>();
230 this->setInputTypeInfo<cv::Mat>();
231 this->setOutputTypeInfo<device::Tensor>();
241 double det_db_thresh_ = 0.3;
242 double det_db_box_thresh_ = 0.6;
243 double det_db_unclip_ratio_ = 1.5;
244 std::string det_db_score_mode_ =
"slow";
245 bool use_dilation_ =
false;
249 rapidjson::Document::AllocatorType &allocator);
257 key_ =
"nndeploy::ocr::DetectorPostProcess";
258 desc_ =
"PPOcrDetv3/v4/v5 postprocess[device::Tensor->OcrResult]";
259 param_ = std::make_shared<DetectorPostParam>();
260 this->setInputTypeInfo<device::Tensor>();
261 this->setOutputTypeInfo<OCRResult>();
264 std::vector<dag::Edge *> outputs)
265 : dag::Node(name, inputs, outputs) {
266 key_ =
"nndeploy::ocr::DetectorPostProcess";
267 desc_ =
"PPOcrDetv3/v4/v5 postprocess[device::Tensor->OcrResult]";
268 param_ = std::make_shared<DetectorPostParam>();
269 this->setInputTypeInfo<device::Tensor>();
270 this->setOutputTypeInfo<OCRResult>();
303 key_ =
"nndeploy::ocr::DetectorGraph";
306 "graph[cv::Mat->preprocess->infer->postprocess->OcrResult]";
307 this->setInputTypeInfo<cv::Mat>();
308 this->setOutputTypeInfo<OCRResult>();
310 this->createNode<DetectorPreProcess>(
"preprocess"));
312 dynamic_cast<infer::Infer *
>(this->createNode<infer::Infer>(
"infer"));
314 this->createNode<DetectorPostProcess>(
"postprocess"));
318 std::vector<dag::Edge *> outputs)
319 : dag::Graph(name, inputs, outputs) {
320 key_ =
"nndeploy::ocr::DetectorGraph";
323 "graph[cv::Mat->preprocess->infer->postprocess->OcrResult]";
324 this->setInputTypeInfo<cv::Mat>();
325 this->setOutputTypeInfo<OCRResult>();
327 this->createNode<DetectorPreProcess>(
"preprocess"));
329 dynamic_cast<infer::Infer *
>(this->createNode<infer::Infer>(
"infer"));
331 this->createNode<DetectorPostProcess>(
"postprocess"));
340 this->setNodeDesc(pre_, pre_desc);
341 this->setNodeDesc(infer_, infer_desc);
342 this->setNodeDesc(post_, post_desc);
343 this->defaultParam();
344 base::Status status = infer_->setInferenceType(inference_type);
372 base::Status status = infer_->setInferenceType(inference_type);
381 std::vector<std::string> &model_value) {
384 param->model_type_ = model_type;
385 param->is_path_ = is_path;
386 param->model_value_ = model_value;
439 std::vector<dag::Edge *>
forward(std::vector<dag::Edge *> inputs) {
440 std::vector<dag::Edge *> pre_outputs = (*pre_)(inputs);
441 std::vector<dag::Edge *> infer_outputs = (*infer_)(pre_outputs);
442 std::vector<dag::Edge *> post_outputs = (*post_)(infer_outputs);
virtual base::Status deserialize(rapidjson::Value &json)
virtual std::string serialize()
Template class for a 4-element vector. Scalar_ and Scalar can be used just as typical 4-element vecto...
Directed Acyclic Graph Node.
InferenceParam is the base class of all inference param.
base::DeviceType device_type_
base::Status setVersion(int version)
DetectorGraph(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs)
std::vector< dag::Edge * > forward(std::vector< dag::Edge * > inputs)
base::Status setDbUnclipRatio(float ratio)
DetectorGraph(const std::string &name)
base::Status make(const dag::NodeDesc &pre_desc, const dag::NodeDesc &infer_desc, base::InferenceType inference_type, const dag::NodeDesc &post_desc)
base::Status setDbScoreMode(const std::string &mode)
base::Status setDbUseDilation(bool value)
virtual base::Status defaultParam()
Set default parameters.
base::Status setSrcPixelType(base::PixelType pixel_type)
base::Status setInferenceType(base::InferenceType inference_type)
base::Status setDbBoxThresh(float threshold)
base::Status setDbThresh(float threshold)
base::Status setInferParam(base::DeviceType device_type, base::ModelType model_type, bool is_path, std::vector< std::string > &model_value)
double det_db_box_thresh_
virtual base::Status deserialize(rapidjson::Value &json)
double det_db_unclip_ratio_
std::string det_db_score_mode_
virtual base::Status serialize(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator)
virtual base::Status run()
Run node (pure virtual function)
PostProcessor util_post_processor_
virtual ~DetectorPostProcess()
DetectorPostProcess(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs)
DetectorPostProcess(const std::string &name)
virtual base::Status serialize(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) override
virtual base::Status deserialize(rapidjson::Value &json) override
base::InterpType interp_type_
base::PixelType dst_pixel_type_
base::PixelType src_pixel_type_
virtual ~DetectorPreProcess()
DetectorPreProcess(const std::string &name)
virtual base::Status run()
Run node (pure virtual function)
DetectorPreProcess(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs)
#define NNDEPLOY_LOGE(fmt,...)
#define NNDEPLOY_CC_API
api
std::string dataFormatToString(DataFormat data_format)
PixelType stringToPixelType(const std::string &pixel_type_str)
BorderType stringToBorderType(const std::string &border_type_str)
DataType stringToDataType(const std::string &str)
DataFormat stringToDataFormat(const std::string &str)
std::string borderTypeToString(BorderType border_type)
std::string dataTypeToString(DataType data_type)
DataType dataTypeOf< float >()
std::string pixelTypeToString(PixelType pixel_type)
std::string interpTypeToString(InterpType interp_type)
InterpType stringToInterpType(const std::string &interp_type_str)