1 #ifndef _NNDEPLOY_CLASSIFICATION_DRAWLABEL_H_
2 #define _NNDEPLOY_CLASSIFICATION_DRAWLABEL_H_
12 namespace classification {
17 key_ =
"nndeploy::classification::DrawLable";
18 desc_ =
"Draw classification labels on input cv::Mat image based on classification results[cv::Mat->cv::Mat]";
19 this->setInputTypeInfo<cv::Mat>();
20 this->setInputTypeInfo<ClassificationResult>();
21 this->setOutputTypeInfo<cv::Mat>();
23 DrawLable(
const std::string &name, std::vector<dag::Edge *> inputs,
24 std::vector<dag::Edge *> outputs)
25 :
Node(name, inputs, outputs) {
26 key_ =
"nndeploy::classification::DrawLable";
27 desc_ =
"Draw classification labels on input cv::Mat image based on classification results[cv::Mat->cv::Mat]";
28 this->setInputTypeInfo<cv::Mat>();
29 this->setInputTypeInfo<ClassificationResult>();
30 this->setOutputTypeInfo<cv::Mat>();
35 cv::Mat *input_mat =
inputs_[0]->getCvMat(
this);
39 cv::Mat *output_mat =
new cv::Mat();
40 input_mat->copyTo(*output_mat);
41 for (
int i = 0; i < result->
labels_.size(); i++) {
42 auto label = result->
labels_[i];
45 std::string text =
"class: " + std::to_string(label.label_ids_) +
46 " score: " + std::to_string(label.scores_);
51 cv::Size text_size = cv::getTextSize(text, cv::FONT_HERSHEY_SIMPLEX, 2.0, 4, &baseline);
54 int y_position = std::max(text_size.height + 10, 50 + i * (text_size.height + 10));
57 cv::Point text_origin(30, y_position);
58 cv::Rect background_rect(text_origin.x - 5, text_origin.y - text_size.height - 5,
59 text_size.width + 10, text_size.height + baseline + 10);
60 cv::rectangle(*output_mat, background_rect, cv::Scalar(0, 0, 0), -1);
63 cv::putText(*output_mat, text, text_origin,
64 cv::FONT_HERSHEY_SIMPLEX, 2.0, cv::Scalar(0, 255, 0), 4);
std::vector< ClassificationLableResult > labels_
DrawLable(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs)
virtual base::Status run()
Run node (pure virtual function)
DrawLable(const std::string &name)
std::string desc_
Node description.
virtual base::Param * getParam()
Get parameter.
std::vector< Edge * > outputs_
Output edge list.
Node(const std::string &name)
Constructor.
std::string key_
Node key.
std::vector< Edge * > inputs_
Input edge list.