| | |
| | |
|
| | | // for vp_frame_target only
|
| | | std::vector<int> hit_traget_ids;
|
| | | for (auto& target : meta->targets) {
|
| | | auto len = target->tracks.size();
|
| | | auto loc = target->get_rect().track_point();
|
| | |
|
| | | // target has been tracked AND tracked enough frames
|
| | | if (len < check_interval_frames || target->track_id < 0) {
|
| | | continue;
|
| | | }
|
| | | // if target inside of stop region or not
|
| | | if (!point_in_poly(loc, jam_region)) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | auto pre_loc = target->tracks[len - check_interval_frames].track_point();
|
| | | if (pre_loc.distance_with(loc) <= check_max_distance) {
|
| | | stop_checking_status[target->track_id]++;
|
| | | hit_traget_ids.push_back(target->track_id);
|
| | | for (auto &target : meta->targets) {
|
| | | if (target->primary_label != target->class_label_of_person) {
|
| | | auto len = target->tracks.size();
|
| | | auto loc = target->get_rect().track_point();
|
| | | // target has been tracked AND tracked enough frames
|
| | | if (len < check_interval_frames || target->track_id < 0) {
|
| | | continue;
|
| | | }
|
| | | // if target inside of stop region or not
|
| | | if (!point_in_poly(loc, jam_region)) {
|
| | | continue;
|
| | | }
|
| | | auto pre_loc = target->tracks[len - check_interval_frames].track_point();
|
| | | if (pre_loc.distance_with(loc) <= check_max_distance) {
|
| | | stop_checking_status[target->track_id]++;
|
| | | hit_traget_ids.push_back(target->track_id);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | // jam checking logic parameters which may be configed by constructor passed in by user
|
| | | const int check_interval_frames = 20;
|
| | | const int check_min_hit_frames = 25 * 2; // 25 fps * 2 seconds
|
| | | const int check_max_distance = 8;
|
| | | const int check_min_stops = 8;
|
| | | const int check_notify_interval = 10; // interval time (seconds) to notify (ensure not frequently)
|
| | | const int check_max_distance = 3;
|
| | | const int check_min_stops = 1;
|
| | | const int check_notify_interval = 15; // interval time (seconds) to notify (ensure not frequently)
|
| | | protected:
|
| | | virtual std::shared_ptr<vp_objects::vp_meta> handle_frame_meta(std::shared_ptr<vp_objects::vp_frame_meta> meta) override;
|
| | | public:
|
| New file |
| | |
| | |
|
| | |
|
| | | #include "vp_ba_person_falldown_node.h"
|
| | |
|
| | | namespace vp_nodes
|
| | | {
|
| | |
|
| | | vp_ba_person_falldown_node::vp_ba_person_falldown_node(std::string node_name,
|
| | | bool need_record_image,
|
| | | bool need_record_video) : vp_node(node_name), 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_person_falldown_node::~vp_ba_person_falldown_node()
|
| | | {
|
| | | deinitialized();
|
| | | }
|
| | |
|
| | | std::string vp_ba_person_falldown_node::to_string()
|
| | | {
|
| | | /*
|
| | | * return vertexs of all jam regions
|
| | | * [channel0: x1,y1 x2,y2 ...][channel1: x1,y1 x2,y2 ...]...
|
| | | */
|
| | | |
| | | return "vp_ba_person_falldown_node";
|
| | | }
|
| | |
|
| | | bool vp_ba_person_falldown_node::isPersonFallen(int person_width, int person_height, float fallThreshold)
|
| | | {
|
| | | return (person_height / person_width) < fallThreshold; // 跌倒判断条件
|
| | | }
|
| | | |
| | |
|
| | | std::shared_ptr<vp_objects::vp_meta> vp_ba_person_falldown_node::handle_frame_meta(std::shared_ptr<vp_objects::vp_frame_meta> meta)
|
| | | {
|
| | | // for current channel
|
| | | auto &person_falldown_checking_status = all_person_falldown_checking_status[meta->channel_index];
|
| | | auto &person_falldown_result = all_person_falldown_results[meta->channel_index];
|
| | | auto &last_notify = all_last_notifys[meta->channel_index];
|
| | |
|
| | | // for vp_frame_target only
|
| | | // for vp_frame_target only
|
| | | std::vector<int> hit_traget_ids;
|
| | | for (auto &target : meta->targets)
|
| | | {
|
| | | if (target->primary_label == target->class_label_of_person)
|
| | | {
|
| | | auto len = target->tracks.size();
|
| | |
|
| | | // target has been tracked AND tracked enough frames
|
| | | if (len < check_interval_frames || target->track_id < 0)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | // if target inside of stop region or not
|
| | | // if (!point_in_poly(loc, jam_region))
|
| | | //{
|
| | | // continue;
|
| | | //}
|
| | | if (isPersonFallen(target->width,target->height,person_fall_down_threshold))
|
| | | {
|
| | | person_falldown_checking_status[target->track_id]++;
|
| | | hit_traget_ids.push_back(target->track_id);
|
| | | }
|
| | | }
|
| | | }
|
| | | std::vector<int> involve_targets;
|
| | | for (auto i = person_falldown_checking_status.begin(); i != person_falldown_checking_status.end();)
|
| | | {
|
| | | if (std::find(hit_traget_ids.begin(), hit_traget_ids.end(), i->first) == hit_traget_ids.end())
|
| | | {
|
| | | // remove since it not satisfy stop condition
|
| | | i = person_falldown_checking_status.erase(i);
|
| | | continue;
|
| | | }
|
| | | if (i->second >= check_min_hit_frames)
|
| | | {
|
| | | involve_targets.push_back(i->first);
|
| | | }
|
| | | i++;
|
| | | }
|
| | | VP_INFO(std::to_string(involve_targets.size()));
|
| | |
|
| | |
|
| | | if (involve_targets.size() > 0 && (meta->frame_index - last_notify) > (check_notify_interval * meta->fps))
|
| | | {
|
| | | person_falldown_result = true;
|
| | | 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, "person_falldown_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, "person_falldown_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<vp_objects::vp_point> involve_region;
|
| | | auto ba_result = std::make_shared<vp_objects::vp_ba_result>(vp_objects::vp_ba_type::FALLDOWN,
|
| | | meta->channel_index,
|
| | | meta->frame_index,
|
| | | involve_targets,
|
| | | involve_region,
|
| | | "person_falldown", // 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 person falldown.", 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()));
|
| | | }
|
| | | }
|
| | | if (involve_targets.size() == 0 && person_falldown_result)
|
| | | {
|
| | | person_falldown_result = false;
|
| | | last_notify = meta->frame_index;
|
| | | }
|
| | | return meta;
|
| | | }
|
| | | } |
| New file |
| | |
| | | #pragma once
|
| | |
|
| | | #include <map>
|
| | | #include <algorithm>
|
| | | #include "../vp_node.h"
|
| | | #include "../../objects/shapes/vp_point.h"
|
| | | #include "../../objects/shapes/vp_line.h"
|
| | | #include "../../objects/vp_image_record_control_meta.h"
|
| | | #include "../../objects/vp_video_record_control_meta.h"
|
| | |
|
| | | namespace vp_nodes {
|
| | | // behaviour analysis node for stop (support multi channels)
|
| | | class vp_ba_person_falldown_node: public vp_node |
| | | {
|
| | | private:
|
| | | // channel -> status of targets (id -> num of hit frames)
|
| | | std::map<int, std::map<int, int>> all_person_falldown_checking_status;
|
| | |
|
| | | // channel -> jam status of channel (jam or not)
|
| | | std::map<int, bool> all_person_falldown_results;
|
| | |
|
| | | // channel -> last frame index to notify jam
|
| | | std::map<int, int> all_last_notifys;
|
| | |
|
| | | // record params
|
| | | bool need_record_image;
|
| | | bool need_record_video;
|
| | |
|
| | | bool isPersonFallen(int person_width, int person_height,float fallThreshold) ;
|
| | |
|
| | | float person_fall_down_threshold = 1.5f;
|
| | |
|
| | | // jam checking logic parameters which may be configed by constructor passed in by user
|
| | | const int check_interval_frames = 1;
|
| | | const int check_min_hit_frames = 2 * 1; // 25 fps * 2 seconds
|
| | | |
| | | const int check_notify_interval = 10; // interval time (seconds) to notify (ensure not frequently)
|
| | | protected:
|
| | | virtual std::shared_ptr<vp_objects::vp_meta> handle_frame_meta(std::shared_ptr<vp_objects::vp_frame_meta> meta) override;
|
| | | public:
|
| | | vp_ba_person_falldown_node(std::string node_name, |
| | | bool need_record_image = true,
|
| | | bool need_record_video = true);
|
| | | ~vp_ba_person_falldown_node();
|
| | | std::string to_string() override;
|
| | | };
|
| | | } |
| New file |
| | |
| | |
|
| | |
|
| | | #include "vp_ba_person_gathering_node.h"
|
| | |
|
| | | namespace vp_nodes
|
| | | {
|
| | |
|
| | | vp_ba_person_gathering_node::vp_ba_person_gathering_node(std::string node_name,
|
| | | int min_gathering_person,
|
| | | bool need_record_image,
|
| | | bool need_record_video) : vp_node(node_name), min_gathering_person(min_gathering_person), 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_person_gathering_node::~vp_ba_person_gathering_node()
|
| | | {
|
| | | deinitialized();
|
| | | }
|
| | |
|
| | | std::string vp_ba_person_gathering_node::to_string()
|
| | | {
|
| | | /*
|
| | | * return vertexs of all jam regions
|
| | | * [channel0: x1,y1 x2,y2 ...][channel1: x1,y1 x2,y2 ...]...
|
| | | */
|
| | |
|
| | | return "vp_ba_person_gathering_node";
|
| | | }
|
| | |
|
| | | bool vp_ba_person_gathering_node::isNearby(int p1_width, int p1_x, int p1_y, int p2_width, int p2_x, int p2_y, float factor)
|
| | | {
|
| | | // 动态距离根据宽度计算
|
| | | float dynamicDistance = std::max(p1_width, p2_width) * factor;
|
| | |
|
| | | // 欧几里得距离计算
|
| | | float dx = p1_x - p2_x;
|
| | | float dy = p1_y - p2_y;
|
| | | float distance = std::sqrt(dx * dx + dy * dy);
|
| | |
|
| | | return distance < dynamicDistance;
|
| | | }
|
| | |
|
| | | std::shared_ptr<vp_objects::vp_meta> vp_ba_person_gathering_node::handle_frame_meta(std::shared_ptr<vp_objects::vp_frame_meta> meta)
|
| | | {
|
| | | // for current channel
|
| | | auto &person_gathering_checking_status = all_person_gathering_checking_status[meta->channel_index];
|
| | | auto &person_gathering_result = all_person_gathering_results[meta->channel_index];
|
| | | auto &last_notify = all_last_notifys[meta->channel_index];
|
| | |
|
| | | // for vp_frame_target only
|
| | | std::vector<int> hit_traget_ids;
|
| | | for (auto &target : meta->targets)
|
| | | {
|
| | | if (target->primary_label == target->class_label_of_person)
|
| | | {
|
| | | auto len = target->tracks.size();
|
| | | // auto loc = target->get_rect().track_point();
|
| | |
|
| | | // target has been tracked AND tracked enough frames
|
| | | if (len < check_interval_frames || target->track_id < 0)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | // if target inside of stop region or not
|
| | | // if (!point_in_poly(loc, jam_region))
|
| | | //{
|
| | | // continue;
|
| | | //}
|
| | |
|
| | | bool is_this_target_gathering= false;
|
| | |
|
| | | for (auto &tempTarget : meta->targets)
|
| | | {
|
| | |
|
| | | if (isNearby(target->width, target->x, target->y, tempTarget->width, tempTarget->x, tempTarget->y, person_gathering_distance_factor))
|
| | | {
|
| | | is_this_target_gathering = true;
|
| | | //person_gathering_checking_status[target->track_id]++;
|
| | | //hit_traget_ids.push_back(target->track_id);
|
| | | }
|
| | | }
|
| | | if (is_this_target_gathering)
|
| | | {
|
| | | person_gathering_checking_status[target->track_id]++;
|
| | | hit_traget_ids.push_back(target->track_id);
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // count for stop targets
|
| | | auto personGathers = 0;
|
| | | std::vector<int> involve_targets;
|
| | | for (auto i = person_gathering_checking_status.begin(); i != person_gathering_checking_status.end();)
|
| | | {
|
| | | if (std::find(hit_traget_ids.begin(), hit_traget_ids.end(), i->first) == hit_traget_ids.end())
|
| | | {
|
| | | // remove since it not satisfy stop condition
|
| | | i = person_gathering_checking_status.erase(i);
|
| | | continue;
|
| | | }
|
| | | if (i->second >= check_min_hit_frames)
|
| | | {
|
| | | involve_targets.push_back(i->first);
|
| | | personGathers++;
|
| | | }
|
| | | i++;
|
| | | }
|
| | | VP_INFO(std::to_string(involve_targets.size()));
|
| | |
|
| | |
|
| | |
|
| | | if (personGathers >= min_gathering_person && !person_gathering_result && (meta->frame_index - last_notify) > (check_notify_interval * meta->fps))
|
| | | {
|
| | | person_gathering_result = true;
|
| | | 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, "person_gathering_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, "person_gathering_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<vp_objects::vp_point> involve_region;
|
| | | auto ba_result = std::make_shared<vp_objects::vp_ba_result>(vp_objects::vp_ba_type::GATHERING,
|
| | | meta->channel_index,
|
| | | meta->frame_index,
|
| | | involve_targets,
|
| | | involve_region,
|
| | | "person_gathering", // 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 person falldown.", 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()));
|
| | | }
|
| | | }
|
| | | if (personGathers < min_gathering_person && person_gathering_result)
|
| | | {
|
| | | person_gathering_result = false;
|
| | | last_notify = meta->frame_index;
|
| | | }
|
| | | return meta;
|
| | | }
|
| | | } |
| New file |
| | |
| | | #pragma once
|
| | |
|
| | | #include <map>
|
| | | #include <algorithm>
|
| | | #include "../vp_node.h"
|
| | | #include "../../objects/shapes/vp_point.h"
|
| | | #include "../../objects/shapes/vp_line.h"
|
| | | #include "../../objects/vp_image_record_control_meta.h"
|
| | | #include "../../objects/vp_video_record_control_meta.h"
|
| | |
|
| | | namespace vp_nodes
|
| | | {
|
| | | // behaviour analysis node for stop (support multi channels)
|
| | | class vp_ba_person_gathering_node : public vp_node
|
| | | {
|
| | | private:
|
| | | // channel -> status of targets (id -> num of hit frames)
|
| | | std::map<int, std::map<int, int>> all_person_gathering_checking_status;
|
| | |
|
| | | // channel -> jam status of channel (jam or not)
|
| | | std::map<int, bool> all_person_gathering_results;
|
| | |
|
| | | // channel -> last frame index to notify jam
|
| | | std::map<int, int> all_last_notifys;
|
| | |
|
| | | // record params
|
| | | bool need_record_image;
|
| | | bool need_record_video;
|
| | |
|
| | | bool isNearby(int p1_width, int p1_x, int p1_y, int p2_width, int p2_x, int p2_y, float factor);
|
| | |
|
| | | float person_gathering_distance_factor = 4.0f;
|
| | |
|
| | | // jam checking logic parameters which may be configed by constructor passed in by user
|
| | | const int check_interval_frames = 1;
|
| | | const int check_min_hit_frames = 1 * 1; // 25 fps * 2 seconds
|
| | |
|
| | | int min_gathering_person = 3;
|
| | |
|
| | | const int check_notify_interval = 10; // interval time (seconds) to notify (ensure not frequently)
|
| | | protected:
|
| | | virtual std::shared_ptr<vp_objects::vp_meta> handle_frame_meta(std::shared_ptr<vp_objects::vp_frame_meta> meta) override;
|
| | |
|
| | | public:
|
| | | vp_ba_person_gathering_node(std::string node_name,
|
| | | int min_gathering_person,
|
| | | bool need_record_image = true,
|
| | | bool need_record_video = true);
|
| | | ~vp_ba_person_gathering_node();
|
| | | std::string to_string() override;
|
| | | };
|
| | | } |
| New file |
| | |
| | |
|
| | |
|
| | | #include "vp_ba_wrong_direction_node.h"
|
| | |
|
| | | namespace vp_nodes
|
| | | {
|
| | |
|
| | | vp_ba_wrong_direction_node::vp_ba_wrong_direction_node(std::string node_name,
|
| | | std::map<int, std::vector<vp_objects::vp_point>> left_lines,
|
| | | std::map<int, std::vector<vp_objects::vp_point>> right_lines,
|
| | | int half_width,
|
| | | bool need_record_image,
|
| | | bool need_record_video) : vp_node(node_name), all_left_lines(left_lines), all_right_lines(right_lines), half_width(half_width),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_wrong_direction_node::~vp_ba_wrong_direction_node()
|
| | | {
|
| | | deinitialized();
|
| | | }
|
| | |
|
| | | std::string vp_ba_wrong_direction_node::to_string()
|
| | | {
|
| | | /*
|
| | | * return vertexs of all jam regions
|
| | | * [channel0: x1,y1 x2,y2 ...][channel1: x1,y1 x2,y2 ...]...
|
| | | */
|
| | | std::stringstream ss;
|
| | | for (auto &r : all_left_lines)
|
| | | {
|
| | | ss << "[" << r.first << ":";
|
| | | for (auto &p : r.second)
|
| | | {
|
| | | ss << " " << p.x << "," << p.y;
|
| | | }
|
| | | ss << "]";
|
| | | }
|
| | | return ss.str();
|
| | | }
|
| | |
|
| | | bool vp_ba_wrong_direction_node::point_in_poly(vp_objects::vp_point p, std::vector<vp_objects::vp_point> region)
|
| | | {
|
| | | int i, j, c = 0;
|
| | | int nvert = region.size();
|
| | |
|
| | | for (i = 0, j = nvert - 1; i < nvert; j = i++)
|
| | | {
|
| | | if (((region[i].y > p.y) != (region[j].y > p.y)) &&
|
| | | (p.x < (region[j].x - region[i].x) * (p.y - region[i].y) / (region[j].y - region[i].y) + region[i].x))
|
| | | c = !c;
|
| | | }
|
| | | return c;
|
| | | }
|
| | |
|
| | | bool vp_ba_wrong_direction_node::check_wrong_direction(std::vector<vp_objects::vp_point> test_line, std::vector<vp_objects::vp_point> right_line, double angle_tolerance = 30.0)
|
| | | {
|
| | | if (test_line.size() != 2 || right_line.size() != 2)
|
| | | {
|
| | | // 线段必须由两个点组成
|
| | | return false;
|
| | | }
|
| | |
|
| | | // 计算 test_line 的方向向量
|
| | | double dx_test = test_line[1].x - test_line[0].x;
|
| | | double dy_test = test_line[1].y - test_line[0].y;
|
| | |
|
| | | // 计算 right_line 的方向向量
|
| | | double dx_right = right_line[1].x - right_line[0].x;
|
| | | double dy_right = right_line[1].y - right_line[0].y;
|
| | |
|
| | | // 计算两个向量的模
|
| | | double magnitude_test = std::sqrt(dx_test * dx_test + dy_test * dy_test);
|
| | | double magnitude_right = std::sqrt(dx_right * dx_right + dy_right * dy_right);
|
| | |
|
| | | if (magnitude_test == 0 || magnitude_right == 0)
|
| | | {
|
| | | // 如果某条线段的长度为零,则无法比较方向
|
| | | return false;
|
| | | }
|
| | |
|
| | | // 归一化方向向量
|
| | | dx_test /= magnitude_test;
|
| | | dy_test /= magnitude_test;
|
| | |
|
| | | dx_right /= magnitude_right;
|
| | | dy_right /= magnitude_right;
|
| | |
|
| | | // 计算两个向量的夹角余弦值
|
| | | double dot_product = dx_test * dx_right + dy_test * dy_right;
|
| | |
|
| | | // 将余弦值限制在 -1 到 1 的范围内(防止计算误差)
|
| | | dot_product = std::max(-1.0, std::min(1.0, dot_product));
|
| | |
|
| | | // 计算夹角(弧度制)
|
| | | double angle_rad = std::acos(dot_product);
|
| | |
|
| | | // 将夹角转换为角度制
|
| | | double angle_deg = angle_rad * 180.0 / 3.1415926;
|
| | |
|
| | | // 判断夹角是否在允许的范围内
|
| | | return angle_deg > angle_tolerance;
|
| | | }
|
| | |
|
| | | std::shared_ptr<vp_objects::vp_meta> vp_ba_wrong_direction_node::handle_frame_meta(std::shared_ptr<vp_objects::vp_frame_meta> meta)
|
| | | {
|
| | | // if need applied on current channel or not
|
| | | if (all_left_lines.count(meta->channel_index) == 0 || all_right_lines.count(meta->channel_index) == 0)
|
| | | {
|
| | | return meta;
|
| | | }
|
| | |
|
| | | // for current channel
|
| | | // auto &jam_region = all_jam_regions[meta->channel_index];
|
| | | auto &left_line = all_left_lines[meta->channel_index];
|
| | | auto &right_line = all_right_lines[meta->channel_index];
|
| | |
|
| | | auto &wrong_direction_checking_status = all_wrong_direction_checking_status[meta->channel_index];
|
| | | auto &wrong_direction_result = all_wrong_direction_results[meta->channel_index];
|
| | | auto &last_notify = all_last_notifys[meta->channel_index];
|
| | |
|
| | | // for vp_frame_target only
|
| | | // for vp_frame_target only
|
| | | std::vector<int> hit_traget_ids;
|
| | | for (auto &target : meta->targets)
|
| | | {
|
| | | if (target->primary_label != target->class_label_of_person)
|
| | | {
|
| | | auto len = target->tracks.size();
|
| | |
|
| | | // target has been tracked AND tracked enough frames
|
| | | if (len < check_interval_frames || target->track_id < 0)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | // if target inside of stop region or not
|
| | | // if (!point_in_poly(loc, jam_region))
|
| | | //{
|
| | | // continue;
|
| | | //}
|
| | | if (len > 2 && target->track_id >= 0)
|
| | | {
|
| | | // check the last 2 points in tracks
|
| | | auto p1 = target->tracks[len - 1].track_point();
|
| | | auto p2 = target->tracks[len - 2].track_point();
|
| | |
|
| | | // 使用 auto 自动推导类型
|
| | | auto test_line = {p2, p1};
|
| | |
|
| | | auto is_wrong_direction = (p1.x < half_width) ? check_wrong_direction(test_line, left_line) : check_wrong_direction(test_line, right_line);
|
| | |
|
| | | if (is_wrong_direction)
|
| | | {
|
| | | wrong_direction_checking_status[target->track_id]++;
|
| | | hit_traget_ids.push_back(target->track_id);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | std::vector<int> involve_targets;
|
| | | for (auto i = wrong_direction_checking_status.begin(); i != wrong_direction_checking_status.end();)
|
| | | {
|
| | | if (std::find(hit_traget_ids.begin(), hit_traget_ids.end(), i->first) == hit_traget_ids.end())
|
| | | {
|
| | | // remove since it not satisfy stop condition
|
| | | i = wrong_direction_checking_status.erase(i);
|
| | | continue;
|
| | | }
|
| | | if (i->second >= check_min_hit_frames)
|
| | | {
|
| | | involve_targets.push_back(i->first);
|
| | | }
|
| | | i++;
|
| | | }
|
| | | if (involve_targets.size() > 0 && (meta->frame_index - last_notify) > (check_notify_interval * meta->fps))
|
| | | {
|
| | | wrong_direction_result = true;
|
| | | 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, "wrong_direction_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, "wrong_direction_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<vp_objects::vp_point> involve_region{line.start, line.end};
|
| | | auto ba_result = std::make_shared<vp_objects::vp_ba_result>(vp_objects::vp_ba_type::WRONGDIRECTION,
|
| | | meta->channel_index,
|
| | | meta->frame_index,
|
| | | involve_targets,
|
| | | // involve_region,
|
| | | left_line,
|
| | | "wrong_direction", // 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 wrong direction.", 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()));
|
| | | }
|
| | | }
|
| | | if (involve_targets.size() == 0 && wrong_direction_result)
|
| | | {
|
| | | wrong_direction_result = false;
|
| | | last_notify = meta->frame_index;
|
| | | }
|
| | | return meta;
|
| | | }
|
| | | } |
| New file |
| | |
| | | #pragma once
|
| | |
|
| | | #include <map>
|
| | | #include <algorithm>
|
| | | #include "../vp_node.h"
|
| | | #include "../../objects/shapes/vp_point.h"
|
| | | #include "../../objects/shapes/vp_line.h"
|
| | | #include "../../objects/vp_image_record_control_meta.h"
|
| | | #include "../../objects/vp_video_record_control_meta.h"
|
| | |
|
| | | namespace vp_nodes {
|
| | | // behaviour analysis node for stop (support multi channels)
|
| | | class vp_ba_wrong_direction_node: public vp_node |
| | | {
|
| | | private:
|
| | | // channel -> vertexs of line, 1 channel supports only 1 left line at most (can be 0, which means no jam check on this channel)
|
| | | std::map<int, std::vector<vp_objects::vp_point>> all_left_lines;
|
| | |
|
| | | // channel -> vertexs of region, 1 channel supports only 1 right line at most (can be 0, which means no jam check on this channel)
|
| | | std::map<int, std::vector<vp_objects::vp_point>> all_right_lines;
|
| | |
|
| | | // channel -> status of targets (id -> num of hit frames)
|
| | | std::map<int, std::map<int, int>> all_wrong_direction_checking_status;
|
| | |
|
| | | // channel -> jam status of channel (jam or not)
|
| | | std::map<int, bool> all_wrong_direction_results;
|
| | |
|
| | | // channel -> last frame index to notify jam
|
| | | std::map<int, int> all_last_notifys;
|
| | |
|
| | | int half_width = 320;
|
| | |
|
| | | // record params
|
| | | bool need_record_image;
|
| | | bool need_record_video;
|
| | |
|
| | | // check if point inside of polygon
|
| | | bool point_in_poly(vp_objects::vp_point p, std::vector<vp_objects::vp_point> region);
|
| | |
|
| | | // check if direction is in right direction
|
| | | bool check_wrong_direction(std::vector<vp_objects::vp_point> test_line, std::vector<vp_objects::vp_point> right_line,double angle_tolerance);
|
| | |
|
| | | // jam checking logic parameters which may be configed by constructor passed in by user
|
| | | const int check_interval_frames = 5;
|
| | | const int check_min_hit_frames = 25 * 1; // 25 fps * 2 seconds
|
| | | |
| | | const int check_notify_interval = 10; // interval time (seconds) to notify (ensure not frequently)
|
| | | protected:
|
| | | virtual std::shared_ptr<vp_objects::vp_meta> handle_frame_meta(std::shared_ptr<vp_objects::vp_frame_meta> meta) override;
|
| | | public:
|
| | | vp_ba_wrong_direction_node(std::string node_name, |
| | | std::map<int, std::vector<vp_objects::vp_point>> all_left_lines,
|
| | | std::map<int, std::vector<vp_objects::vp_point>> all_right_lines,
|
| | | int half_width,
|
| | | bool need_record_image = true,
|
| | | bool need_record_video = true);
|
| | | ~vp_ba_wrong_direction_node();
|
| | | std::string to_string() override;
|
| | | };
|
| | | } |
| | |
| | |
|
| | | #include <fstream>
|
| | |
|
| | | #include <opencv2/core/cuda.hpp>
|
| | | #include "vp_infer_node.h"
|
| | |
|
| | | namespace vp_nodes {
|
| | |
| | | try {
|
| | | net = cv::dnn::readNet(model_path, model_config_path);
|
| | | #ifdef VP_WITH_CUDA
|
| | | net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA);
|
| | | net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA);
|
| | | // net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA);
|
| | | // net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA);
|
| | | // 检查可用的 GPU 数量
|
| | | int gpu_count = cv::cuda::getCudaEnabledDeviceCount();
|
| | | if (gpu_count > 0) {
|
| | | // 初始化随机数种子并随机选择一个 GPU
|
| | | std::srand(static_cast<unsigned>(std::time(nullptr)));
|
| | | int selected_gpu = std::rand() % gpu_count;
|
| | | // 设置 CUDA 设备并配置为使用指定 GPU
|
| | | cv::cuda::setDevice(selected_gpu);
|
| | | net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA);
|
| | | net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA);
|
| | |
|
| | | VP_INFO(vp_utils::string_format("[%s] Using CUDA on GPU %d", node_name.c_str(), selected_gpu));
|
| | | } else {
|
| | | VP_WARN(vp_utils::string_format("[%s] No CUDA-enabled GPUs detected. Running on CPU.", node_name.c_str()));
|
| | | }
|
| | | #endif
|
| | | }
|
| | | catch(const std::exception& e) {
|
| | |
| | |
|
| | | #pragma once
|
| | | #include <sstream>
|
| | | #include <opencv2/core/cuda.hpp>
|
| | | #include <opencv2/dnn.hpp>
|
| | | #include "vp_node.h"
|
| | |
|
| | |
| | | class vp_rtsp_src_node: public vp_src_node {
|
| | | private:
|
| | | /* data */
|
| | | std::string gst_template = "rtspsrc location=%s ! application/x-rtp,media=video ! rtph264depay ! h264parse ! %s ! videoconvert ! appsink";
|
| | | cv::VideoCapture rtsp_capture;
|
| | | //std::string gst_template = "rtspsrc location=%s ! application/x-rtp,media=video ! rtph264depay ! h264parse ! %s ! videoconvert ! appsink";
|
| | | std::string gst_template = "rtspsrc location=%s ! rtph264depay ! h264parse ! %s ! videoconvert ! appsink";
|
| | | cv::VideoCapture rtsp_capture;
|
| | | protected:
|
| | | // re-implemetation
|
| | | virtual void handle_run() override;
|
| | |
| | | STOP = 0b00000010, // enter stop status
|
| | | UNSTOP = 0b00000100, // leave stop status
|
| | | JAM = 0b00001000, // enter jam status
|
| | | UNJAM = 0b00010000 // leave jam status
|
| | | UNJAM = 0b00010000, // leave jam status
|
| | | GATHERING = 0b00100000,
|
| | | FALLDOWN = 0b01000000,
|
| | | WRONGDIRECTION =0b10000000
|
| | | /* more */
|
| | | };
|
| | |
|
| | |
| | | float primary_score;
|
| | | // label created by primary infer nodes
|
| | | std::string primary_label;
|
| | | // class id of person
|
| | | std::string class_label_of_person = "person";
|
| | |
|
| | | // frame the target belongs to
|
| | | int frame_index;
|
| | |
| | | add_executable(vp_test "vp_test.cpp")
|
| | | target_link_libraries(vp_test ${PROJECT_NAME})
|
| | |
|
| | | add_executable(from_argv_ba_wrong_direction "from_argv_ba_wrong_direction.cpp")
|
| | | target_link_libraries(from_argv_ba_wrong_direction ${PROJECT_NAME})
|
| | |
|
| | | add_executable(from_argv_ba_person "from_argv_ba_person.cpp")
|
| | | target_link_libraries(from_argv_ba_person ${PROJECT_NAME})
|
| | |
|
| | | add_executable(from_argv_ba_jam_rtsp "from_argv_ba_jam_rtsp.cpp")
|
| | | target_link_libraries(from_argv_ba_jam_rtsp ${PROJECT_NAME})
|
| | |
|
| | | add_executable(from_argv_ba_stop_rtsp "from_argv_ba_stop_rtsp.cpp")
|
| | | target_link_libraries(from_argv_ba_stop_rtsp ${PROJECT_NAME})
|
| | |
|
| | | add_executable(from_argv_ba_jam_rtsp_d "from_argv_ba_jam_rtsp_d.cpp")
|
| | | target_link_libraries(from_argv_ba_jam_rtsp_d ${PROJECT_NAME})
|
| | |
|
| | | add_executable(from_argv_ba_stop_rtsp_d "from_argv_ba_stop_rtsp_d.cpp")
|
| | | target_link_libraries(from_argv_ba_stop_rtsp_d ${PROJECT_NAME})
|
| | |
|
| | | # samples depend on Kafka
|
| | | if(VP_WITH_KAFKA)
|
| | | add_executable(message_broker_kafka_sample "message_broker_kafka_sample.cpp")
|
| New file |
| | |
| | | #include "../nodes/vp_file_src_node.h"
|
| | | #include "../nodes/infers/vp_trt_vehicle_detector.h"
|
| | | #include "../nodes/track/vp_sort_track_node.h"
|
| | | #include "../nodes/ba/vp_ba_stop_node.h"
|
| | | #include "../nodes/osd/vp_ba_stop_osd_node.h"
|
| | | #include "../nodes/vp_split_node.h"
|
| | | #include "../nodes/vp_screen_des_node.h"
|
| | |
|
| | | #include "../utils/analysis_board/vp_analysis_board.h"
|
| | |
|
| | | /*
|
| | | * ## ba stop sample ##
|
| | | * behaviour analysis for stop, single instance of ba node work on 2 channels.
|
| | | */
|
| | |
|
| | | int main() {
|
| | | VP_SET_LOG_LEVEL(vp_utils::vp_log_level::INFO);
|
| | | VP_LOGGER_INIT();
|
| | |
|
| | | // create nodes
|
| | | auto file_src_0 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_0", 0, "./vp_data/test_video/vehicle_stop.mp4", 0.6);
|
| | | auto file_src_1 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_1", 1, "./vp_data/test_video/vehicle_stop.mp4", 0.6);
|
| | | auto trt_vehicle_detector = std::make_shared<vp_nodes::vp_trt_vehicle_detector>("vehicle_detector", "./vp_data//models/trt/vehicle/vehicle_detection.trt");
|
| | | auto tracker = std::make_shared<vp_nodes::vp_sort_track_node>("sort_tracker");
|
| | | |
| | | // define a region in frame for every channel (value MUST in the scope of frame'size)
|
| | | std::map<int, std::vector<vp_objects::vp_point>> regions = {
|
| | | {0, std::vector<vp_objects::vp_point>{vp_objects::vp_point(20, 30), vp_objects::vp_point(600, 40), vp_objects::vp_point(600, 300), vp_objects::vp_point(10, 300)}}, // channel0 -> region
|
| | | {1, std::vector<vp_objects::vp_point>{vp_objects::vp_point(20, 30), vp_objects::vp_point(1000, 40), vp_objects::vp_point(1000, 600), vp_objects::vp_point(10, 600)}} // channel1 -> region
|
| | | };
|
| | | auto ba_stop = std::make_shared<vp_nodes::vp_ba_stop_node>("ba_stop", regions);
|
| | | auto osd = std::make_shared<vp_nodes::vp_ba_stop_osd_node>("osd");
|
| | | auto split = std::make_shared<vp_nodes::vp_split_node>("split", true);
|
| | | auto screen_des_0 = std::make_shared<vp_nodes::vp_screen_des_node>("screen_des_0", 0);
|
| | | auto screen_des_1 = std::make_shared<vp_nodes::vp_screen_des_node>("screen_des_1", 1);
|
| | | |
| | | // construct pipeline
|
| | | trt_vehicle_detector->attach_to({file_src_0, file_src_1});
|
| | | tracker->attach_to({trt_vehicle_detector});
|
| | | ba_stop->attach_to({tracker});
|
| | | osd->attach_to({ba_stop});
|
| | | split->attach_to({osd});
|
| | | screen_des_0->attach_to({split});
|
| | | screen_des_1->attach_to({split});
|
| | |
|
| | | file_src_0->start();
|
| | | file_src_1->start();
|
| | |
|
| | | // for debug purpose
|
| | | vp_utils::vp_analysis_board board({file_src_0, file_src_1});
|
| | | board.display();
|
| | | } |
| New file |
| | |
| | | { |
| | | "rtsp_sources": { |
| | | "1": "rtsp://192.168.1.24:8554/demo", |
| | | "2": "rtsp://192.168.1.24:8554/demo", |
| | | "3": "rtsp://192.168.1.24:8554/demo", |
| | | "4": "rtsp://192.168.1.24:8554/demo", |
| | | "5": "rtsp://192.168.1.24:8554/demo", |
| | | "6": "rtsp://192.168.1.24:8554/demo", |
| | | "7": "rtsp://192.168.1.24:8554/demo", |
| | | "8": "rtsp://192.168.1.24:8554/demo", |
| | | "9": "rtsp://192.168.1.24:8554/demo", |
| | | "10": "rtsp://192.168.1.24:8554/demo" |
| | | }, |
| | | "resize_ratio": 0.4, |
| | | "kafka_server": "192.168.0.85:9092", |
| | | "region_points": { |
| | | "1": [[0, 520], [450, 50], [650, 50], [1000, 520]], |
| | | "2": [[0, 520], [450, 50], [650, 50], [1000, 520]], |
| | | "3": [[0, 520], [450, 50], [650, 50], [1000, 520]], |
| | | "4": [[0, 520], [450, 50], [650, 50], [1000, 520]], |
| | | "5": [[0, 520], [450, 50], [650, 50], [1000, 520]], |
| | | "6": [[0, 520], [450, 50], [650, 50], [1000, 520]], |
| | | "7": [[0, 520], [450, 50], [650, 50], [1000, 520]], |
| | | "8": [[0, 520], [450, 50], [650, 50], [1000, 520]], |
| | | "9": [[0, 520], [450, 50], [650, 50], [1000, 520]], |
| | | "10": [[0, 520], [450, 50], [650, 50], [1000, 520]] |
| | | } |
| | | } |
| New file |
| | |
| | | #include "../nodes/vp_file_src_node.h" |
| | | #include "../nodes/vp_rtsp_src_node.h" |
| | | #include "../nodes/infers/vp_yolo_detector_node.h" |
| | | #include "../nodes/track/vp_sort_track_node.h" |
| | | #include "../nodes/ba/vp_ba_jam_node.h" |
| | | #include "../nodes/osd/vp_ba_jam_osd_node.h" |
| | | #include "../nodes/vp_screen_des_node.h" |
| | | #include "../nodes/vp_rtmp_des_node.h" |
| | | #include "../nodes/broker/vp_json_kafka_broker_node.h" |
| | | #include "../nodes/vp_file_des_node.h" |
| | | #include "../nodes/vp_split_node.h" |
| | | #include "../nodes/record/vp_record_node.h" |
| | | #include "../nodes/vp_fake_des_node.h" |
| | | #include "../utils/analysis_board/vp_analysis_board.h" |
| | | |
| | | #include <vector> |
| | | #include <string> |
| | | #include <iostream> |
| | | #include <map> |
| | | #include <memory> |
| | | |
| | | int main(int argc, char* argv[]) { |
| | | VP_SET_LOG_LEVEL(vp_utils::vp_log_level::WARN); |
| | | VP_LOGGER_INIT(); |
| | | |
| | | std::vector<std::string> args(argv + 1, argv + argc); |
| | | |
| | | // 默认的命令行参数 |
| | | std::string rtsp_base_url = "rtsp://192.168.1.24:8554/demo"; |
| | | std::string kafka_server_point = "192.168.0.85:9092"; |
| | | float resize_ratio = 0.4; |
| | | |
| | | std::vector<std::string> rtsp_urls; |
| | | |
| | | |
| | | // 解析命令行参数 |
| | | if (args.size() >= 22) { |
| | | for (int i = 0; i < 20; ++i) { |
| | | rtsp_urls.push_back(args[i]); |
| | | } |
| | | resize_ratio = std::stof(args[20]); |
| | | kafka_server_point = args[21]; |
| | | } else { |
| | | std::cout << "Usage: " << argv[0] << " <rtsp_path_1> ... <rtsp_path_20> <resize_ratio> <kafka_server_point>\n"; |
| | | std::cout << "Example: " << argv[0] << " rtsp://192.168.1.24:8554/demo 0.4 192.168.0.85:9092\n"; |
| | | return -1; |
| | | } |
| | | |
| | | // Create RTSP source nodes |
| | | std::vector<std::shared_ptr<vp_nodes::vp_rtsp_src_node>> rtsp_sources; |
| | | for (int i = 0; i < 20; ++i) { |
| | | rtsp_sources.push_back(std::make_shared<vp_nodes::vp_rtsp_src_node>( |
| | | "rtsp_src_" + std::to_string(i + 1), i + 1, rtsp_urls[i], resize_ratio, "avdec_h264")); |
| | | } |
| | | |
| | | auto yolo_detector = std::make_shared<vp_nodes::vp_yolo_detector_node>("yolo_detector", |
| | | "./vp_data/models/det_cls/yolov3-tiny-2022-0721_best.weights", |
| | | "./vp_data/models/det_cls/yolov3-tiny-2022-0721.cfg", |
| | | "./vp_data/models/det_cls/yolov3_tiny_5classes.txt"); |
| | | |
| | | auto tracker = std::make_shared<vp_nodes::vp_sort_track_node>("sort_tracker"); |
| | | |
| | | // Define regions for every channel |
| | | auto define_regions = [](int num_sources) { |
| | | std::map<int, std::vector<vp_objects::vp_point>> regions; |
| | | for (int i = 1; i <= num_sources; ++i) { |
| | | regions[i] = std::vector<vp_objects::vp_point>{ |
| | | vp_objects::vp_point(0, 520), vp_objects::vp_point(450, 50), |
| | | vp_objects::vp_point(650, 50), vp_objects::vp_point(1000, 520)}; |
| | | } |
| | | return regions; |
| | | }; |
| | | |
| | | auto ba_jam = std::make_shared<vp_nodes::vp_ba_jam_node>("ba_jam", define_regions(20)); |
| | | |
| | | auto json_kafka_broker_0 = std::make_shared<vp_nodes::vp_json_kafka_broker_node>( |
| | | "json_kafka_broker_0", kafka_server_point, "vp_ba_jam", vp_nodes::vp_broke_for::BARESULT); |
| | | |
| | | auto osd = std::make_shared<vp_nodes::vp_ba_jam_osd_node>("osd"); |
| | | auto recorder = std::make_shared<vp_nodes::vp_record_node>("recorder", "./record", "./record"); |
| | | auto split = std::make_shared<vp_nodes::vp_split_node>("split", true); |
| | | // Create 20 fake destination nodes, one for each channel |
| | | std::vector<std::shared_ptr<vp_nodes::vp_fake_des_node>> fake_des_nodes; |
| | | for (int i = 1; i <= 20; ++i) { |
| | | fake_des_nodes.push_back(std::make_shared<vp_nodes::vp_fake_des_node>("fake_des_" + std::to_string(i), i)); |
| | | } |
| | | |
| | | // Construct pipeline |
| | | for (auto& rtsp_source : rtsp_sources) { |
| | | yolo_detector->attach_to({rtsp_source}); |
| | | } |
| | | |
| | | tracker->attach_to({yolo_detector}); |
| | | ba_jam->attach_to({tracker}); |
| | | |
| | | json_kafka_broker_0->attach_to({ba_jam}); |
| | | osd->attach_to({json_kafka_broker_0}); |
| | | recorder->attach_to({osd}); |
| | | split->attach_to({recorder}); |
| | | |
| | | // Attach fake destination nodes (one for each channel) |
| | | for (auto& fake_des_node : fake_des_nodes) { |
| | | fake_des_node->attach_to({split}); |
| | | } |
| | | |
| | | // Start RTSP sources |
| | | for (auto& rtsp_source : rtsp_sources) { |
| | | rtsp_source->start(); |
| | | } |
| | | |
| | | std::string wait; |
| | | std::getline(std::cin, wait); |
| | | |
| | | // Cleanup |
| | | for (auto& rtsp_source : rtsp_sources) { |
| | | rtsp_source->detach_recursively(); |
| | | } |
| | | |
| | | return 0; |
| | | } |
| New file |
| | |
| | | #include "../nodes/vp_file_src_node.h" |
| | | #include "../nodes/vp_rtsp_src_node.h" |
| | | |
| | | #include "../nodes/infers/vp_yolo_detector_node.h" |
| | | #include "../nodes/track/vp_sort_track_node.h" |
| | | #include "../nodes/ba/vp_ba_jam_node.h" |
| | | #include "../nodes/osd/vp_ba_jam_osd_node.h" |
| | | #include "../nodes/vp_screen_des_node.h" |
| | | #include "../nodes/vp_rtmp_des_node.h" |
| | | #include "../nodes/broker/vp_json_kafka_broker_node.h" |
| | | #include "../nodes/vp_file_des_node.h" |
| | | #include "../nodes/record/vp_record_node.h" |
| | | #include "../nodes/vp_fake_des_node.h" |
| | | |
| | | #include "../utils/analysis_board/vp_analysis_board.h" |
| | | |
| | | /* |
| | | * ## ba crossline sample ## |
| | | * behaviour analysis for crossline. |
| | | */ |
| | | |
| | | int main(int argc, char* argv[]) { |
| | | VP_SET_LOG_LEVEL(vp_utils::vp_log_level::INFO); |
| | | VP_LOGGER_INIT(); |
| | | |
| | | std::vector<std::string> args(argv + 1, argv + argc); |
| | | // 默认的命令行参数 |
| | | std::string rtsp_path_1 = "rtsp://192.168.1.24:8554/demo"; |
| | | std::string rtsp_path_2 = "rtsp://192.168.1.24:8554/demo"; |
| | | std::string rtsp_path_3 = "rtsp://192.168.1.24:8554/demo"; |
| | | std::string rtsp_path_4 = "rtsp://192.168.1.24:8554/demo"; |
| | | std::string rtsp_path_5 = "rtsp://192.168.1.24:8554/demo"; |
| | | std::string rtsp_path_6 = "rtsp://192.168.1.24:8554/demo"; |
| | | std::string rtsp_path_7 = "rtsp://192.168.1.24:8554/demo"; |
| | | std::string rtsp_path_8 = "rtsp://192.168.1.24:8554/demo"; |
| | | std::string rtsp_path_9 = "rtsp://192.168.1.24:8554/demo"; |
| | | std::string rtsp_path_10 = "rtsp://192.168.1.24:8554/demo"; |
| | | |
| | | std::string kafka_server_point = "192.168.0.85:9092"; |
| | | |
| | | float resize_ratio = 0.4; |
| | | |
| | | // 如果提供了第一个和第二个参数,则覆盖默认的路径 |
| | | if (args.size() >= 3) { |
| | | rtsp_path_1 = args[0]; |
| | | rtsp_path_2 = args[1]; |
| | | rtsp_path_3 = args[2]; |
| | | rtsp_path_4 = args[3]; |
| | | rtsp_path_5 = args[4]; |
| | | rtsp_path_6 = args[5]; |
| | | rtsp_path_7 = args[6]; |
| | | rtsp_path_8 = args[7]; |
| | | rtsp_path_9 = args[8]; |
| | | rtsp_path_10 = args[9]; |
| | | resize_ratio = std::stof(args[10]); |
| | | kafka_server_point = args[11]; |
| | | |
| | | } else { |
| | | std::cout << "Usage: " << argv[0] << " <rtsp_path> <resize_ratio> <kafka_server_point>\n"; |
| | | std::cout << "Example: " << argv[0] << " rtsp://192.168.1.24:8554/demo 0.4 192.168.0.85:9092\n"; |
| | | return -1; |
| | | } |
| | | |
| | | |
| | | // create nodes |
| | | //auto rtsp_src_1 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_0", 0, rtsp_path, resize_ratio); |
| | | auto rtsp_src_1 = std::make_shared<vp_nodes::vp_rtsp_src_node>("rtsp_src_1", 1, rtsp_path_1, resize_ratio, "avdec_h264"); |
| | | auto rtsp_src_2 = std::make_shared<vp_nodes::vp_rtsp_src_node>("rtsp_src_2", 2, rtsp_path_2, resize_ratio, "avdec_h264"); |
| | | auto rtsp_src_3 = std::make_shared<vp_nodes::vp_rtsp_src_node>("rtsp_src_3", 3, rtsp_path_3, resize_ratio, "avdec_h264"); |
| | | auto rtsp_src_4 = std::make_shared<vp_nodes::vp_rtsp_src_node>("rtsp_src_4", 4, rtsp_path_4, resize_ratio, "avdec_h264"); |
| | | auto rtsp_src_5 = std::make_shared<vp_nodes::vp_rtsp_src_node>("rtsp_src_5", 5, rtsp_path_5, resize_ratio, "avdec_h264"); |
| | | auto rtsp_src_6 = std::make_shared<vp_nodes::vp_rtsp_src_node>("rtsp_src_6", 6, rtsp_path_6, resize_ratio, "avdec_h264"); |
| | | auto rtsp_src_7 = std::make_shared<vp_nodes::vp_rtsp_src_node>("rtsp_src_7", 7, rtsp_path_7, resize_ratio, "avdec_h264"); |
| | | auto rtsp_src_8 = std::make_shared<vp_nodes::vp_rtsp_src_node>("rtsp_src_8", 8, rtsp_path_8, resize_ratio, "avdec_h264"); |
| | | auto rtsp_src_9 = std::make_shared<vp_nodes::vp_rtsp_src_node>("rtsp_src_9", 9, rtsp_path_9, resize_ratio, "avdec_h264"); |
| | | auto rtsp_src_10 = std::make_shared<vp_nodes::vp_rtsp_src_node>("rtsp_src_10", 10, rtsp_path_10, resize_ratio, "avdec_h264"); |
| | | auto yolo_detector = std::make_shared<vp_nodes::vp_yolo_detector_node>("yolo_detector", "./vp_data/models/det_cls/yolov3-tiny-2022-0721_best.weights", "./vp_data/models/det_cls/yolov3-tiny-2022-0721.cfg", "./vp_data/models/det_cls/yolov3_tiny_5classes.txt"); |
| | | auto tracker = std::make_shared<vp_nodes::vp_sort_track_node>("sort_tracker"); |
| | | |
| | | // define a region in frame for every channel (value MUST in the scope of frame'size) |
| | | std::map<int, std::vector<vp_objects::vp_point>> regions = { |
| | | //{0, std::vector<vp_objects::vp_point>{vp_objects::vp_point(641, 58), vp_objects::vp_point(747, 51), vp_objects::vp_point(1132, 267), vp_objects::vp_point(366, 678)}} |
| | | {1, std::vector<vp_objects::vp_point>{vp_objects::vp_point(0, 520), vp_objects::vp_point(450, 50), vp_objects::vp_point(650, 50), vp_objects::vp_point(1000, 520)}}, |
| | | {2, std::vector<vp_objects::vp_point>{vp_objects::vp_point(0, 520), vp_objects::vp_point(450, 50), vp_objects::vp_point(650, 50), vp_objects::vp_point(1000, 520)}}, |
| | | {3, std::vector<vp_objects::vp_point>{vp_objects::vp_point(0, 520), vp_objects::vp_point(450, 50), vp_objects::vp_point(650, 50), vp_objects::vp_point(1000, 520)}}, |
| | | {4, std::vector<vp_objects::vp_point>{vp_objects::vp_point(0, 520), vp_objects::vp_point(450, 50), vp_objects::vp_point(650, 50), vp_objects::vp_point(1000, 520)}}, |
| | | {5, std::vector<vp_objects::vp_point>{vp_objects::vp_point(0, 520), vp_objects::vp_point(450, 50), vp_objects::vp_point(650, 50), vp_objects::vp_point(1000, 520)}}, |
| | | {6, std::vector<vp_objects::vp_point>{vp_objects::vp_point(0, 520), vp_objects::vp_point(450, 50), vp_objects::vp_point(650, 50), vp_objects::vp_point(1000, 520)}}, |
| | | {7, std::vector<vp_objects::vp_point>{vp_objects::vp_point(0, 520), vp_objects::vp_point(450, 50), vp_objects::vp_point(650, 50), vp_objects::vp_point(1000, 520)}}, |
| | | {8, std::vector<vp_objects::vp_point>{vp_objects::vp_point(0, 520), vp_objects::vp_point(450, 50), vp_objects::vp_point(650, 50), vp_objects::vp_point(1000, 520)}}, |
| | | {9, std::vector<vp_objects::vp_point>{vp_objects::vp_point(0, 520), vp_objects::vp_point(450, 50), vp_objects::vp_point(650, 50), vp_objects::vp_point(1000, 520)}}, |
| | | {10, std::vector<vp_objects::vp_point>{vp_objects::vp_point(0, 520), vp_objects::vp_point(450, 50), vp_objects::vp_point(650, 50), vp_objects::vp_point(1000, 520)}} |
| | | |
| | | }; |
| | | auto ba_jam = std::make_shared<vp_nodes::vp_ba_jam_node>("ba_jam", regions); |
| | | |
| | | auto json_kafka_broker_0 = std::make_shared<vp_nodes::vp_json_kafka_broker_node>("json_kafka_broker_0", kafka_server_point, "vp_ba_jam", vp_nodes::vp_broke_for::BARESULT); |
| | | auto osd = std::make_shared<vp_nodes::vp_ba_jam_osd_node>("osd"); |
| | | auto recorder = std::make_shared<vp_nodes::vp_record_node>("recorder", "./record", "./record"); |
| | | auto fake_des_0 = std::make_shared<vp_nodes::vp_fake_des_node>("fake_des_0", 2); |
| | | |
| | | // construct pipeline |
| | | yolo_detector->attach_to({rtsp_src_1,rtsp_src_2,rtsp_src_3,rtsp_src_4,rtsp_src_5,rtsp_src_6,rtsp_src_7,rtsp_src_8,rtsp_src_9,rtsp_src_10}); |
| | | tracker->attach_to({yolo_detector}); |
| | | ba_jam->attach_to({tracker}); |
| | | |
| | | json_kafka_broker_0->attach_to({ba_jam}); |
| | | osd->attach_to({json_kafka_broker_0}); |
| | | recorder->attach_to({osd}); |
| | | |
| | | fake_des_0->attach_to({recorder}); |
| | | |
| | | rtsp_src_1->start(); |
| | | rtsp_src_2->start(); |
| | | rtsp_src_3->start(); |
| | | rtsp_src_4->start(); |
| | | rtsp_src_5->start(); |
| | | rtsp_src_6->start(); |
| | | rtsp_src_7->start(); |
| | | rtsp_src_8->start(); |
| | | rtsp_src_9->start(); |
| | | rtsp_src_10->start(); |
| | | |
| | | std::string wait; |
| | | std::getline(std::cin, wait); |
| | | rtsp_src_1->detach_recursively(); |
| | | } |
| New file |
| | |
| | | #include "../nodes/vp_file_src_node.h" |
| | | #include "../nodes/vp_rtsp_src_node.h" |
| | | |
| | | #include "../nodes/infers/vp_yolo_detector_node.h" |
| | | #include "../nodes/track/vp_sort_track_node.h" |
| | | #include "../nodes/ba/vp_ba_jam_node.h" |
| | | #include "../nodes/osd/vp_ba_jam_osd_node.h" |
| | | #include "../nodes/vp_screen_des_node.h" |
| | | #include "../nodes/vp_rtmp_des_node.h" |
| | | #include "../nodes/broker/vp_json_kafka_broker_node.h" |
| | | #include "../nodes/vp_file_des_node.h" |
| | | #include "../nodes/record/vp_record_node.h" |
| | | #include "../nodes/vp_fake_des_node.h" |
| | | #include "../utils/analysis_board/vp_analysis_board.h" |
| | | |
| | | /* |
| | | * ## ba crossline sample ## |
| | | * behaviour analysis for crossline. |
| | | */ |
| | | |
| | | int main(int argc, char* argv[]) { |
| | | VP_SET_LOG_LEVEL(vp_utils::vp_log_level::INFO); |
| | | VP_LOGGER_INIT(); |
| | | |
| | | std::vector<std::string> args(argv + 1, argv + argc); |
| | | // 默认的命令行参数 |
| | | std::string rtsp_path = "rtsp://192.168.1.24:8554/demo"; |
| | | std::string kafka_server_point = "192.168.0.85:9092"; |
| | | |
| | | float resize_ratio = 0.4; |
| | | int skip_interval = 1; |
| | | |
| | | // 如果提供了第一个和第二个参数,则覆盖默认的路径 |
| | | if (args.size() >= 4) { |
| | | rtsp_path = args[0]; |
| | | resize_ratio = std::stof(args[1]); |
| | | kafka_server_point = args[2]; |
| | | skip_interval = std::stoi(args[3]); |
| | | } else { |
| | | std::cout << "Usage: " << argv[0] << " <rtsp_path> <resize_ratio> <kafka_server_point> <skip_interval>\n"; |
| | | std::cout << "Example: " << argv[0] << " rtsp://192.168.1.24:8554/demo 0.4 192.168.0.85:9092 5 \n"; |
| | | return -1; |
| | | } |
| | | |
| | | |
| | | // create nodes |
| | | // auto rtsp_src_1 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_0", 0, rtsp_path, resize_ratio, skip_interval); |
| | | auto rtsp_src_1 = std::make_shared<vp_nodes::vp_rtsp_src_node>("rtsp_src_1", 0, rtsp_path, resize_ratio, "avdec_h264", skip_interval); |
| | | auto yolo_detector = std::make_shared<vp_nodes::vp_yolo_detector_node>("yolo_detector", "./vp_data/models/det_cls/yolov3-tiny-2022-0721_best.weights", "./vp_data/models/det_cls/yolov3-tiny-2022-0721.cfg", "./vp_data/models/det_cls/yolov3_tiny_5classes.txt"); |
| | | auto tracker = std::make_shared<vp_nodes::vp_sort_track_node>("sort_tracker"); |
| | | |
| | | // define a region in frame for every channel (value MUST in the scope of frame'size) |
| | | std::map<int, std::vector<vp_objects::vp_point>> regions = { |
| | | //{0, std::vector<vp_objects::vp_point>{vp_objects::vp_point(641, 58), vp_objects::vp_point(747, 51), vp_objects::vp_point(1132, 267), vp_objects::vp_point(366, 678)}} |
| | | {0, std::vector<vp_objects::vp_point>{vp_objects::vp_point(0, 520), vp_objects::vp_point(450, 50), vp_objects::vp_point(650, 50), vp_objects::vp_point(1000, 520)}} |
| | | }; |
| | | auto ba_jam = std::make_shared<vp_nodes::vp_ba_jam_node>("ba_jam", regions); |
| | | auto json_kafka_broker_0 = std::make_shared<vp_nodes::vp_json_kafka_broker_node>("json_kafka_broker_0", kafka_server_point, "vp_ba_jam", vp_nodes::vp_broke_for::BARESULT); |
| | | auto osd = std::make_shared<vp_nodes::vp_ba_jam_osd_node>("osd"); |
| | | auto recorder = std::make_shared<vp_nodes::vp_record_node>("recorder", "./record", "./record"); |
| | | auto fake_des_2 = std::make_shared<vp_nodes::vp_fake_des_node>("fake_des_2", 0); |
| | | |
| | | // construct pipeline |
| | | yolo_detector->attach_to({rtsp_src_1}); |
| | | tracker->attach_to({yolo_detector}); |
| | | ba_jam->attach_to({tracker}); |
| | | json_kafka_broker_0->attach_to({ba_jam}); |
| | | osd->attach_to({json_kafka_broker_0}); |
| | | recorder->attach_to({osd}); |
| | | fake_des_2->attach_to({recorder}); |
| | | |
| | | |
| | | rtsp_src_1->start(); |
| | | |
| | | // for debug purpose |
| | | vp_utils::vp_analysis_board board({rtsp_src_1}); |
| | | board.display(1, false); |
| | | |
| | | std::string wait; |
| | | std::getline(std::cin, wait); |
| | | rtsp_src_1->detach_recursively(); |
| | | } |
| New file |
| | |
| | | #include "../nodes/vp_file_src_node.h"
|
| | | #include "../nodes/infers/vp_yolo_detector_node.h"
|
| | | #include "../nodes/track/vp_sort_track_node.h"
|
| | | #include "../nodes/ba/vp_ba_person_gathering_node.h"
|
| | | #include "../nodes/ba/vp_ba_person_falldown_node.h"
|
| | | #include "../nodes/osd/vp_ba_stop_osd_node.h"
|
| | | #include "../nodes/vp_screen_des_node.h"
|
| | | #include "../nodes/broker/vp_json_kafka_broker_node.h"
|
| | | #include "../nodes/record/vp_record_node.h"
|
| | |
|
| | | #include "../utils/analysis_board/vp_analysis_board.h"
|
| | |
|
| | | /*
|
| | | * ## ba crossline sample ##
|
| | | * behaviour analysis for crossline.
|
| | | */
|
| | |
|
| | | int main(int argc, char* argv[]) {
|
| | | VP_SET_LOG_LEVEL(vp_utils::vp_log_level::INFO);
|
| | | VP_LOGGER_INIT();
|
| | |
|
| | | std::vector<std::string> args(argv + 1, argv + argc);
|
| | | // 默认的命令行参数
|
| | | std::string video_path = "./vp_data/test_video/gathering.mp4";
|
| | |
|
| | | float resize_ratio = 1.0;
|
| | |
|
| | | // 如果提供了第一个和第二个参数,则覆盖默认的路径
|
| | | if (args.size() >= 1) {
|
| | | video_path = args[0];
|
| | | if (args.size() >= 2){
|
| | | resize_ratio = std::stof(args[1]);
|
| | | }
|
| | | } else {
|
| | | std::cout << "Usage: " << argv[0] << " <video_path> [resize_ratio]\n";
|
| | | std::cout << "Example: " << argv[0] << " ./vp_data/test_video/gathering.mp4 1.0\n";
|
| | | return -1;
|
| | | }
|
| | |
|
| | |
|
| | | // create nodes
|
| | | auto file_src_0 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_0", 0, video_path, resize_ratio);
|
| | | auto yolo_detector = std::make_shared<vp_nodes::vp_yolo_detector_node>("yolo_detector", "./vp_data/models/det_cls/yolov3-tiny-2022-0721_best.weights", "./vp_data/models/det_cls/yolov3-tiny-2022-0721.cfg", "./vp_data/models/det_cls/yolov3_tiny_5classes.txt");
|
| | | auto tracker = std::make_shared<vp_nodes::vp_sort_track_node>("sort_tracker");
|
| | | |
| | | int min_gathering_count = 2;
|
| | | auto ba_person_gathering = std::make_shared<vp_nodes::vp_ba_person_gathering_node>("vp_ba_person_gathering_node", min_gathering_count,true,true);
|
| | | auto ba_person_falldown = std::make_shared<vp_nodes::vp_ba_person_falldown_node>("vp_ba_person_falldown_node", true,true);
|
| | | auto json_kafka_broker_0 = std::make_shared<vp_nodes::vp_json_kafka_broker_node>("json_kafka_broker_0", "192.168.0.85:9092", "vp_ba_person", vp_nodes::vp_broke_for::BARESULT);
|
| | | auto osd = std::make_shared<vp_nodes::vp_ba_stop_osd_node>("osd");
|
| | | auto recorder = std::make_shared<vp_nodes::vp_record_node>("recorder", "./record", "./record");
|
| | | auto screen_des_0 = std::make_shared<vp_nodes::vp_screen_des_node>("screen_des_0", 0);
|
| | | |
| | | // construct pipeline
|
| | | yolo_detector->attach_to({file_src_0});
|
| | | tracker->attach_to({yolo_detector});
|
| | | ba_person_gathering->attach_to({tracker});
|
| | | ba_person_falldown->attach_to({ba_person_gathering});
|
| | | json_kafka_broker_0->attach_to({ba_person_falldown});
|
| | | osd->attach_to({json_kafka_broker_0});
|
| | | recorder->attach_to({osd});
|
| | | screen_des_0->attach_to({recorder});
|
| | |
|
| | |
|
| | | file_src_0->start();
|
| | |
|
| | | // for debug purpose
|
| | | vp_utils::vp_analysis_board board({file_src_0});
|
| | | board.display(1, false);
|
| | |
|
| | | std::string wait;
|
| | | std::getline(std::cin, wait);
|
| | | file_src_0->detach_recursively();
|
| | | } |
| New file |
| | |
| | | #include "../nodes/vp_file_src_node.h"
|
| | | #include "../nodes/vp_rtsp_src_node.h"
|
| | | #include "../nodes/infers/vp_trt_vehicle_detector.h"
|
| | | #include "../nodes/track/vp_sort_track_node.h"
|
| | | #include "../nodes/ba/vp_ba_stop_node.h"
|
| | | #include "../nodes/osd/vp_ba_stop_osd_node.h"
|
| | | #include "../nodes/vp_screen_des_node.h"
|
| | | #include "../nodes/broker/vp_json_kafka_broker_node.h"
|
| | | #include "../nodes/vp_file_des_node.h"
|
| | | #include "../nodes/record/vp_record_node.h"
|
| | |
|
| | | #include "../utils/analysis_board/vp_analysis_board.h"
|
| | |
|
| | | /*
|
| | | * ## ba stop sample ##
|
| | | * behaviour analysis for stop, single instance of ba node work on 2 channels.
|
| | | */
|
| | |
|
| | | int main(int argc, char* argv[]) {
|
| | | VP_SET_LOG_LEVEL(vp_utils::vp_log_level::INFO);
|
| | | VP_LOGGER_INIT();
|
| | |
|
| | | std::vector<std::string> args(argv + 1, argv + argc);
|
| | | // 默认的命令行参数
|
| | | std::string rtsp_path = "rtsp://192.168.1.24:8554/demo";
|
| | | std::string kafka_server_point = "192.168.0.85:9092";
|
| | |
|
| | | float resize_ratio = 0.4;
|
| | |
|
| | | // 如果提供了第一个和第二个参数,则覆盖默认的路径
|
| | | if (args.size() >= 3) {
|
| | | rtsp_path = args[0];
|
| | | resize_ratio = std::stof(args[1]);
|
| | | kafka_server_point = args[2];
|
| | | |
| | | } else {
|
| | | std::cout << "Usage: " << argv[0] << " <rtsp_path> <resize_ratio> <kafka_server_point>\n";
|
| | | std::cout << "Example: " << argv[0] << " rtsp://192.168.1.24:8554/demo 0.4 192.168.0.85:9092\n";
|
| | | return -1;
|
| | | }
|
| | |
|
| | |
|
| | | // create nodes
|
| | | //auto rtsp_src_1 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_0", 0, rtsp_path, resize_ratio);
|
| | | auto rtsp_src_1 = std::make_shared<vp_nodes::vp_rtsp_src_node>("rtsp_src_1", 0, rtsp_path, resize_ratio, "avdec_h264"); |
| | | auto trt_vehicle_detector = std::make_shared<vp_nodes::vp_trt_vehicle_detector>("vehicle_detector", "./vp_data//models/trt/vehicle/vehicle_detection.trt");
|
| | | auto tracker = std::make_shared<vp_nodes::vp_sort_track_node>("sort_tracker");
|
| | | |
| | | // define a region in frame for every channel (value MUST in the scope of frame'size)
|
| | | std::map<int, std::vector<vp_objects::vp_point>> regions = {
|
| | | //{0, std::vector<vp_objects::vp_point>{vp_objects::vp_point(641, 58), vp_objects::vp_point(747, 51), vp_objects::vp_point(1132, 267), vp_objects::vp_point(366, 678)}}
|
| | | {0, std::vector<vp_objects::vp_point>{vp_objects::vp_point(0, 520), vp_objects::vp_point(450, 50), vp_objects::vp_point(650, 50), vp_objects::vp_point(1000, 520)}}
|
| | | };
|
| | | auto ba_stop = std::make_shared<vp_nodes::vp_ba_stop_node>("ba_stop", regions);
|
| | | auto json_kafka_broker_0 = std::make_shared<vp_nodes::vp_json_kafka_broker_node>("json_kafka_broker_0", kafka_server_point, "vp_ba_stop", vp_nodes::vp_broke_for::BARESULT);
|
| | | auto osd = std::make_shared<vp_nodes::vp_ba_stop_osd_node>("osd");
|
| | | auto recorder = std::make_shared<vp_nodes::vp_record_node>("recorder", "./record", "./record");
|
| | | auto screen_des_0 = std::make_shared<vp_nodes::vp_screen_des_node>("screen_des_0", 0);
|
| | | auto file_des_node_0 = std::make_shared<vp_nodes::vp_file_des_node>("file_des_0", 0, "out-a-osd", "out-a-osd", 1);
|
| | | |
| | | // construct pipeline
|
| | | trt_vehicle_detector->attach_to({rtsp_src_1});
|
| | | tracker->attach_to({trt_vehicle_detector});
|
| | | ba_stop->attach_to({tracker});
|
| | | json_kafka_broker_0->attach_to({ba_stop});
|
| | | osd->attach_to({json_kafka_broker_0});
|
| | | recorder->attach_to({osd});
|
| | |
|
| | | screen_des_0->attach_to({recorder});
|
| | | file_des_node_0->attach_to({recorder});
|
| | |
|
| | | rtsp_src_1->start();
|
| | |
|
| | | // for debug purpose
|
| | | vp_utils::vp_analysis_board board({rtsp_src_1});
|
| | | board.display();
|
| | |
|
| | | std::string wait;
|
| | | std::getline(std::cin, wait);
|
| | | rtsp_src_1->detach_recursively();
|
| | |
|
| | | } |
| New file |
| | |
| | | #include "../nodes/vp_file_src_node.h"
|
| | | #include "../nodes/vp_rtsp_src_node.h"
|
| | | #include "../nodes/infers/vp_trt_vehicle_detector.h"
|
| | | #include "../nodes/track/vp_sort_track_node.h"
|
| | | #include "../nodes/ba/vp_ba_stop_node.h"
|
| | | #include "../nodes/osd/vp_ba_stop_osd_node.h"
|
| | | #include "../nodes/vp_screen_des_node.h"
|
| | | #include "../nodes/broker/vp_json_kafka_broker_node.h"
|
| | | #include "../nodes/vp_file_des_node.h"
|
| | | #include "../nodes/record/vp_record_node.h"
|
| | |
|
| | | #include "../utils/analysis_board/vp_analysis_board.h"
|
| | |
|
| | | /*
|
| | | * ## ba stop sample ##
|
| | | * behaviour analysis for stop, single instance of ba node work on 2 channels.
|
| | | */
|
| | |
|
| | | int main(int argc, char* argv[]) {
|
| | | VP_SET_LOG_LEVEL(vp_utils::vp_log_level::INFO);
|
| | | VP_LOGGER_INIT();
|
| | |
|
| | | std::vector<std::string> args(argv + 1, argv + argc);
|
| | | // 默认的命令行参数
|
| | | std::string rtsp_path = "rtsp://192.168.1.24:8554/demo";
|
| | | std::string kafka_server_point = "192.168.0.85:9092";
|
| | |
|
| | | float resize_ratio = 0.4;
|
| | |
|
| | | // 如果提供了第一个和第二个参数,则覆盖默认的路径
|
| | | if (args.size() >= 3) {
|
| | | rtsp_path = args[0];
|
| | | resize_ratio = std::stof(args[1]);
|
| | | kafka_server_point = args[2];
|
| | | |
| | | } else {
|
| | | std::cout << "Usage: " << argv[0] << " <rtsp_path> <resize_ratio> <kafka_server_point>\n";
|
| | | std::cout << "Example: " << argv[0] << " rtsp://192.168.1.24:8554/demo 0.4 192.168.0.85:9092\n";
|
| | | return -1;
|
| | | }
|
| | |
|
| | |
|
| | | // create nodes
|
| | | //auto rtsp_src_1 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_0", 0, rtsp_path, resize_ratio);
|
| | | auto rtsp_src_1 = std::make_shared<vp_nodes::vp_rtsp_src_node>("rtsp_src_1", 0, rtsp_path, resize_ratio, "avdec_h264"); |
| | | auto trt_vehicle_detector = std::make_shared<vp_nodes::vp_trt_vehicle_detector>("vehicle_detector", "./vp_data//models/trt/vehicle/vehicle_detection.trt");
|
| | | auto tracker = std::make_shared<vp_nodes::vp_sort_track_node>("sort_tracker");
|
| | | |
| | | // define a region in frame for every channel (value MUST in the scope of frame'size)
|
| | | std::map<int, std::vector<vp_objects::vp_point>> regions = {
|
| | | //{0, std::vector<vp_objects::vp_point>{vp_objects::vp_point(641, 58), vp_objects::vp_point(747, 51), vp_objects::vp_point(1132, 267), vp_objects::vp_point(366, 678)}}
|
| | | {0, std::vector<vp_objects::vp_point>{vp_objects::vp_point(0, 520), vp_objects::vp_point(450, 50), vp_objects::vp_point(650, 50), vp_objects::vp_point(1000, 520)}}
|
| | | };
|
| | | auto ba_stop = std::make_shared<vp_nodes::vp_ba_stop_node>("ba_stop", regions);
|
| | | auto json_kafka_broker_0 = std::make_shared<vp_nodes::vp_json_kafka_broker_node>("json_kafka_broker_0", kafka_server_point, "vp_ba_stop", vp_nodes::vp_broke_for::BARESULT);
|
| | | auto osd = std::make_shared<vp_nodes::vp_ba_stop_osd_node>("osd");
|
| | | auto recorder = std::make_shared<vp_nodes::vp_record_node>("recorder", "./record", "./record");
|
| | | auto screen_des_0 = std::make_shared<vp_nodes::vp_screen_des_node>("screen_des_0", 0);
|
| | | auto file_des_node_0 = std::make_shared<vp_nodes::vp_file_des_node>("file_des_0", 0, "out-a-osd", "out-a-osd", 1);
|
| | | |
| | | // construct pipeline
|
| | | trt_vehicle_detector->attach_to({rtsp_src_1});
|
| | | tracker->attach_to({trt_vehicle_detector});
|
| | | ba_stop->attach_to({tracker});
|
| | | json_kafka_broker_0->attach_to({ba_stop});
|
| | | osd->attach_to({json_kafka_broker_0});
|
| | | recorder->attach_to({osd});
|
| | |
|
| | | screen_des_0->attach_to({recorder});
|
| | | file_des_node_0->attach_to({recorder});
|
| | |
|
| | | rtsp_src_1->start();
|
| | |
|
| | | // for debug purpose
|
| | | vp_utils::vp_analysis_board board({rtsp_src_1});
|
| | | board.display();
|
| | |
|
| | | std::string wait;
|
| | | std::getline(std::cin, wait);
|
| | | rtsp_src_1->detach_recursively();
|
| | |
|
| | | } |
| New file |
| | |
| | | #include "../nodes/vp_file_src_node.h"
|
| | | #include "../nodes/infers/vp_yolo_detector_node.h"
|
| | | #include "../nodes/track/vp_sort_track_node.h"
|
| | | #include "../nodes/ba/vp_ba_wrong_direction_node.h"
|
| | | #include "../nodes/osd/vp_ba_stop_osd_node.h"
|
| | | #include "../nodes/vp_screen_des_node.h"
|
| | | #include "../nodes/broker/vp_json_kafka_broker_node.h"
|
| | | #include "../nodes/record/vp_record_node.h"
|
| | |
|
| | | #include "../utils/analysis_board/vp_analysis_board.h"
|
| | |
|
| | | /*
|
| | | * ## ba crossline sample ##
|
| | | * behaviour analysis for crossline.
|
| | | */
|
| | |
|
| | | int main(int argc, char* argv[]) {
|
| | | VP_SET_LOG_LEVEL(vp_utils::vp_log_level::INFO);
|
| | | VP_LOGGER_INIT();
|
| | |
|
| | | std::vector<std::string> args(argv + 1, argv + argc);
|
| | | // 默认的命令行参数
|
| | | std::string video_path = "./vp_data/test_video/vehicle_count.mp4";
|
| | |
|
| | | float resize_ratio = 0.4;
|
| | |
|
| | | // 如果提供了第一个和第二个参数,则覆盖默认的路径
|
| | | if (args.size() >= 1) {
|
| | | video_path = args[0];
|
| | | if (args.size() >= 2){
|
| | | resize_ratio = std::stof(args[1]);
|
| | | }
|
| | | } else {
|
| | | std::cout << "Usage: " << argv[0] << " <video_path> [resize_ratio]\n";
|
| | | std::cout << "Example: " << argv[0] << " ./vp_data/test_video/vehicle_count.mp4 0.4\n";
|
| | | return -1;
|
| | | }
|
| | |
|
| | |
|
| | | // create nodes
|
| | | auto file_src_0 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_0", 0, video_path, resize_ratio);
|
| | | auto yolo_detector = std::make_shared<vp_nodes::vp_yolo_detector_node>("yolo_detector", "./vp_data/models/det_cls/yolov3-tiny-2022-0721_best.weights", "./vp_data/models/det_cls/yolov3-tiny-2022-0721.cfg", "./vp_data/models/det_cls/yolov3_tiny_5classes.txt");
|
| | | auto tracker = std::make_shared<vp_nodes::vp_sort_track_node>("sort_tracker");
|
| | | |
| | | // define a line in frame for every channel (value MUST in the scope of frame'size)
|
| | | vp_objects::vp_point left_start(10, 10); // change to proper value
|
| | | vp_objects::vp_point left_end(10, 20); // change to proper value
|
| | | vp_objects::vp_point right_start(10, 20); // change to proper value
|
| | | vp_objects::vp_point right_end(10, 10); // change to proper value
|
| | | std::map<int, std::vector<vp_objects::vp_point>> left_lines = {{0, {left_start, left_end}}}; // channel0 -> point vector
|
| | | std::map<int, std::vector<vp_objects::vp_point>> right_lines = {{0, {right_start, right_end}}}; // channel0 -> point vector
|
| | | int half_screen_width = 384;
|
| | | auto ba_wrong_direction = std::make_shared<vp_nodes::vp_ba_wrong_direction_node>("vp_ba_wrong_direction_node", left_lines,right_lines,half_screen_width,true,true);
|
| | | auto json_kafka_broker_0 = std::make_shared<vp_nodes::vp_json_kafka_broker_node>("json_kafka_broker_0", "192.168.0.85:9092", "vp_ba_wrong_direction", vp_nodes::vp_broke_for::BARESULT);
|
| | | auto osd = std::make_shared<vp_nodes::vp_ba_stop_osd_node>("osd");
|
| | | auto recorder = std::make_shared<vp_nodes::vp_record_node>("recorder", "./record", "./record");
|
| | | auto screen_des_0 = std::make_shared<vp_nodes::vp_screen_des_node>("screen_des_0", 0);
|
| | | |
| | | // construct pipeline
|
| | | yolo_detector->attach_to({file_src_0});
|
| | | tracker->attach_to({yolo_detector});
|
| | | ba_wrong_direction->attach_to({tracker});
|
| | | json_kafka_broker_0->attach_to({ba_wrong_direction});
|
| | | osd->attach_to({json_kafka_broker_0});
|
| | | recorder->attach_to({osd});
|
| | | screen_des_0->attach_to({recorder});
|
| | |
|
| | |
|
| | | file_src_0->start();
|
| | |
|
| | | // for debug purpose
|
| | | vp_utils::vp_analysis_board board({file_src_0});
|
| | | board.display(1, false);
|
| | |
|
| | | std::string wait;
|
| | | std::getline(std::cin, wait);
|
| | | file_src_0->detach_recursively();
|
| | | } |