|
|
#include "vp_ba_report_detect_node.h"
|
|
namespace vp_nodes
|
{
|
|
vp_ba_report_detect_node::vp_ba_report_detect_node(std::string node_name,
|
std::string detect_type_name,
|
std::vector<int> class_ids,
|
bool need_record_image,
|
bool need_record_video) : vp_node(node_name), detect_type_name(detect_type_name),class_ids(class_ids), need_record_image(need_record_image), need_record_video(need_record_video)
|
{
|
VP_INFO(vp_utils::string_format("[%s] %s", node_name.c_str(), to_string().c_str()));
|
this->initialized();
|
}
|
|
vp_ba_report_detect_node::~vp_ba_report_detect_node()
|
{
|
deinitialized();
|
}
|
|
std::string vp_ba_report_detect_node::to_string()
|
{
|
/*
|
* return vertexs of all jam regions
|
* [channel0: x1,y1 x2,y2 ...][channel1: x1,y1 x2,y2 ...]...
|
*/
|
|
return "vp_ba_report_detect_node";
|
}
|
|
std::shared_ptr<vp_objects::vp_meta> vp_ba_report_detect_node::handle_frame_meta(std::shared_ptr<vp_objects::vp_frame_meta> meta)
|
{
|
// for current channel
|
auto &detect_result_count = all_detect_result_counts[meta->channel_index];
|
auto &last_notify = all_last_notifys[meta->channel_index];
|
|
// for vp_frame_target only
|
bool has_detected = false;
|
for (auto &target : meta->targets)
|
{
|
if (std::find(class_ids.begin(), class_ids.end(), target->primary_class_id) != class_ids.end())
|
{
|
has_detected = true;
|
|
}
|
}
|
if (has_detected)
|
{
|
detect_result_count++;
|
|
}
|
|
if (detect_result_count >= check_min_hit_frames && (meta->frame_index - last_notify) > (check_notify_interval * meta->fps))
|
{
|
detect_result_count = 0;
|
last_notify = meta->frame_index;
|
// send record image and record video signal, recording actions would occur if record nodes exist in pipeline
|
std::string image_file_name_without_ext = ""; // empty means no recording image
|
std::string video_file_name_without_ext = ""; // empty means no recording video
|
|
// send image record control meta
|
if (need_record_image)
|
{
|
image_file_name_without_ext = vp_utils::time_format(NOW, "detect_result_image__<year><mon><day><hour><min><sec><mili>");
|
auto image_record_control_meta = std::make_shared<vp_objects::vp_image_record_control_meta>(meta->channel_index, image_file_name_without_ext, true);
|
pendding_meta(image_record_control_meta);
|
}
|
// send video record control meta
|
if (need_record_video)
|
{
|
video_file_name_without_ext = vp_utils::time_format(NOW, "detect_result_video__<year><mon><day><hour><min><sec><mili>");
|
auto video_record_control_meta = std::make_shared<vp_objects::vp_video_record_control_meta>(meta->channel_index, video_file_name_without_ext);
|
pendding_meta(video_record_control_meta);
|
}
|
|
std::vector<int> involve_targets;
|
std::vector<vp_objects::vp_point> involve_region;
|
auto ba_result = std::make_shared<vp_objects::vp_ba_result>(vp_objects::vp_ba_type::DETECTREPORT,
|
meta->channel_index,
|
meta->frame_index,
|
involve_targets,
|
involve_region,
|
detect_type_name, // meaningful label
|
image_file_name_without_ext,
|
video_file_name_without_ext);
|
// fill back to frame meta
|
meta->ba_results.push_back(ba_result);
|
// info log
|
VP_INFO(vp_utils::string_format("[%s] [channel %d] has found target .", node_name.c_str(), meta->channel_index));
|
if (need_record_image || need_record_video)
|
{
|
VP_INFO(vp_utils::string_format("[%s] [channel %d] image & video record file names are: [%s & %s]", node_name.c_str(), meta->channel_index, image_file_name_without_ext.c_str(), video_file_name_without_ext.c_str()));
|
}
|
}
|
return meta;
|
}
|
}
|