1 #ifndef _NNDEPLOY_DETECT_DRAWBOX_H_
2 #define _NNDEPLOY_DETECT_DRAWBOX_H_
36 DrawBox(
const std::string &name) : Node(name) {
37 key_ =
"nndeploy::detect::DrawBox";
39 "Draw detection boxes on input cv::Mat image based on detection "
40 "results[cv::Mat->cv::Mat]";
41 this->setInputTypeInfo<cv::Mat>();
42 this->setInputTypeInfo<DetectResult>();
43 this->setOutputTypeInfo<cv::Mat>();
45 DrawBox(
const std::string &name, std::vector<dag::Edge *> inputs,
46 std::vector<dag::Edge *> outputs)
47 : Node(name, inputs, outputs) {
48 key_ =
"nndeploy::detect::DrawBox";
50 "Draw detection boxes on input cv::Mat image based on detection "
51 "results[cv::Mat->cv::Mat]";
52 this->setInputTypeInfo<cv::Mat>();
53 this->setInputTypeInfo<DetectResult>();
54 this->setOutputTypeInfo<cv::Mat>();
59 cv::Mat *input_mat = inputs_[0]->get<cv::Mat>(
this);
60 if (input_mat ==
nullptr) {
67 if (result ==
nullptr) {
72 float w_ratio = float(input_mat->cols);
73 float h_ratio = float(input_mat->rows);
75 cv::RNG rng(0xFFFFFFFF);
76 cv::Scalar_<int> randColor[CNUM];
77 cv::Mat *output_mat =
new cv::Mat();
78 input_mat->copyTo(*output_mat);
79 for (
int i = 0; i < CNUM; i++)
80 rng.fill(randColor[i], cv::RNG::UNIFORM, 0, 256);
82 for (
auto bbox : result->
bboxs_) {
83 std::array<float, 4> box;
84 box[0] = bbox.bbox_[0];
85 box[2] = bbox.bbox_[2];
86 box[1] = bbox.bbox_[1];
87 box[3] = bbox.bbox_[3];
92 int width = box[2] - box[0];
93 int height = box[3] - box[1];
94 int id = bbox.label_id_;
97 cv::Point p = cv::Point(box[0], box[1]);
98 cv::Rect rect = cv::Rect(box[0], box[1], width, height);
99 cv::rectangle(*output_mat, rect, randColor[
id], 2);
101 " ID:" + std::to_string(
id) +
" score:" + std::to_string(bbox.score_);
102 cv::putText(*output_mat, text, p, cv::FONT_HERSHEY_PLAIN, 1,
105 outputs_[0]->set(output_mat,
false);
113 key_ =
"nndeploy::detect::YoloMultiConvDrawBox";
115 "Draw detection boxes on input cv::Mat image based on detection "
116 "results[cv::Mat->cv::Mat]";
117 this->setInputTypeInfo<cv::Mat>();
118 this->setInputTypeInfo<DetectResult>();
119 this->setOutputTypeInfo<cv::Mat>();
122 std::vector<dag::Edge *> outputs)
123 : Node(name, inputs, outputs) {
124 key_ =
"nndeploy::detect::YoloMultiConvDrawBox";
126 "Draw detection boxes on input cv::Mat image based on detection "
127 "results[cv::Mat->cv::Mat]";
128 this->setInputTypeInfo<cv::Mat>();
129 this->setInputTypeInfo<DetectResult>();
130 this->setOutputTypeInfo<cv::Mat>();
135 cv::Mat *input_mat = inputs_[0]->getCvMat(
this);
138 float w_ratio = float(input_mat->cols);
139 float h_ratio = float(input_mat->rows);
141 cv::RNG rng(0xFFFFFFFF);
142 cv::Scalar_<int> randColor[CNUM];
143 for (
int i = 0; i < CNUM; i++)
144 rng.fill(randColor[i], cv::RNG::UNIFORM, 0, 256);
146 for (
auto bbox : result->
bboxs_) {
147 std::array<float, 4> box;
148 box[0] = bbox.bbox_[0];
149 box[2] = bbox.bbox_[2];
150 box[1] = bbox.bbox_[1];
151 box[3] = bbox.bbox_[3];
152 int width = box[2] - box[0];
153 int height = box[3] - box[1];
154 int id = bbox.label_id_;
155 NNDEPLOY_LOGE(
"box[0]:%f, box[1]:%f, width :%d, height :%d\n", box[0],
156 box[1], width, height);
157 cv::Point p = cv::Point(box[0], box[1]);
158 cv::Rect rect = cv::Rect(box[0], box[1], width, height);
159 cv::rectangle(*input_mat, rect, randColor[
id], 10);
160 std::string text =
" ID:" + std::to_string(
id);
161 cv::putText(*input_mat, text, p, cv::FONT_HERSHEY_SIMPLEX, 1.0,
165 cv::Mat *output_mat =
new cv::Mat();
166 input_mat->copyTo(*output_mat);
167 outputs_[0]->set(output_mat,
false);
std::vector< DetectBBoxResult > bboxs_
DrawBox(const std::string &name)
virtual base::Status run()
Run node (pure virtual function)
DrawBox(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs)
virtual base::Status run()
Run node (pure virtual function)
YoloMultiConvDrawBox(const std::string &name)
virtual ~YoloMultiConvDrawBox()
YoloMultiConvDrawBox(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs)
#define NNDEPLOY_LOGE(fmt,...)
#define NNDEPLOY_CC_API
api
@ kStatusCodeErrorInvalidParam