|
@@ -59,57 +59,34 @@ static std::tuple<uint8_t, uint8_t, uint8_t> random_color(int id)
|
|
return hsv2bgr(h_plane, s_plane, 1);
|
|
return hsv2bgr(h_plane, s_plane, 1);
|
|
}
|
|
}
|
|
|
|
|
|
-void DrawNode::work()
|
|
|
|
|
|
+void DrawNode::handle_data(std::shared_ptr<meta::MetaData>& meta_data)
|
|
{
|
|
{
|
|
- PLOGI.printf("DrawNode : [%s] start", name_.c_str());
|
|
|
|
- while (running_)
|
|
|
|
|
|
+ cv::Mat image = meta_data->image.clone();
|
|
|
|
+ int image_width = image.cols;
|
|
|
|
+ int image_height = image.rows;
|
|
|
|
+ PositionManager<float> pm(getFontSize);
|
|
|
|
+ for (auto& box : meta_data->boxes)
|
|
{
|
|
{
|
|
- bool has_data = false;
|
|
|
|
- for (auto& input_buffer : input_buffers_)
|
|
|
|
- {
|
|
|
|
- std::shared_ptr<meta::MetaData> metaData;
|
|
|
|
- if (!input_buffer.second->try_pop(metaData))
|
|
|
|
- {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- has_data = true;
|
|
|
|
- // printf("Node %s get data from %s\n", name_.c_str(), input_buffer.first.c_str());
|
|
|
|
- cv::Mat image = metaData->image.clone();
|
|
|
|
- int image_width = image.cols;
|
|
|
|
- int image_height = image.rows;
|
|
|
|
- PositionManager<float> pm(getFontSize);
|
|
|
|
- for (auto& box : metaData->boxes)
|
|
|
|
- {
|
|
|
|
- uint8_t b, g, r;
|
|
|
|
- std::tie(b, g, r) = random_color(box.class_id);
|
|
|
|
- cv::rectangle(image, cv::Point(box.left, box.top), cv::Point(box.right, box.bottom), cv::Scalar(b, g, r), 2);
|
|
|
|
|
|
+ uint8_t b, g, r;
|
|
|
|
+ std::tie(b, g, r) = random_color(box.class_id);
|
|
|
|
+ cv::rectangle(image, cv::Point(box.left, box.top), cv::Point(box.right, box.bottom), cv::Scalar(b, g, r), 2);
|
|
|
|
|
|
- std::tuple<int, int, int, int> pbox = std::make_tuple(box.left, box.top, box.right, box.bottom);
|
|
|
|
- int x, y;
|
|
|
|
- std::string text;
|
|
|
|
- if (box.class_id != -1)
|
|
|
|
- {
|
|
|
|
- text = str_format("%s %.2f id=%d", box.label.c_str(), box.score, box.class_id);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- text = str_format("%s %.2f", box.label.c_str(), box.score);
|
|
|
|
- }
|
|
|
|
- std::tie(x, y) = pm.selectOptimalPosition(pbox, image_width, image_height, text);
|
|
|
|
-
|
|
|
|
- cv::putText(image, text, cv::Point(x, y), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(b, g, r), 2);
|
|
|
|
- }
|
|
|
|
- metaData->draw_image = image;
|
|
|
|
- send_output_data(metaData);
|
|
|
|
|
|
+ std::tuple<int, int, int, int> pbox = std::make_tuple(box.left, box.top, box.right, box.bottom);
|
|
|
|
+ int x, y;
|
|
|
|
+ std::string text;
|
|
|
|
+ if (box.class_id != -1)
|
|
|
|
+ {
|
|
|
|
+ text = str_format("%s %.2f id=%d", box.label.c_str(), box.score, box.class_id);
|
|
}
|
|
}
|
|
- if (!has_data) {
|
|
|
|
- // printf("draw wait data\n");
|
|
|
|
- std::unique_lock<std::mutex> lock(mutex_);
|
|
|
|
- cond_var_->wait_for(lock, std::chrono::milliseconds(100), [this] {
|
|
|
|
- return !running_; // 等待时检查退出条件
|
|
|
|
- });
|
|
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ text = str_format("%s %.2f", box.label.c_str(), box.score);
|
|
}
|
|
}
|
|
|
|
+ std::tie(x, y) = pm.selectOptimalPosition(pbox, image_width, image_height, text);
|
|
|
|
+
|
|
|
|
+ cv::putText(image, text, cv::Point(x, y), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(b, g, r), 2);
|
|
}
|
|
}
|
|
|
|
+ meta_data->draw_image = image;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|