wangrong
2025-01-20 d4675814490906969a39daa3e79ac560fe705410
add all in one and gethering && person falldown && wrongway
6个文件已添加
2个文件已修改
744 ■■■■■ 已修改文件
nodes/ba/vp_ba_report_detect_node.cpp 99 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nodes/ba/vp_ba_report_detect_node.h 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nodes/vp_rtsp_ffmpeg_src_node.cpp 269 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nodes/vp_rtsp_ffmpeg_src_node.h 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
objects/ba/vp_ba_result.h 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
samples/from_argv_all_in_one_rtsp.cpp 137 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
samples/from_argv_all_in_one_sample.cpp 129 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
samples/from_argv_ba_crossline_rtsp.cpp 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nodes/ba/vp_ba_report_detect_node.cpp
New file
@@ -0,0 +1,99 @@
#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;
    }
}
nodes/ba/vp_ba_report_detect_node.h
New file
@@ -0,0 +1,49 @@
#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_report_detect_node : public vp_node
    {
    private:
        // channel -> detect status of channel (has or not)
        std::map<int, int> all_detect_result_counts;
        // channel -> last frame index to notify jam
        std::map<int, int> all_last_notifys;
        // only appliy to some certain classes
        std::vector<int> class_ids ={0};
        std::string detect_type_name;
        // record params
        bool need_record_image;
        bool need_record_video;
        // checking logic parameters which may be configed by constructor passed in by user
        const int check_min_hit_frames = 2 * 1; // 25 fps * 2 seconds
        const int check_notify_interval = 5; // 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_report_detect_node(std::string node_name,
                                    std::string detect_type_name,
                                    std::vector<int> class_ids,
                                    bool need_record_image = true,
                                    bool need_record_video = true);
        ~vp_ba_report_detect_node();
        std::string to_string() override;
    };
}
nodes/vp_rtsp_ffmpeg_src_node.cpp
New file
@@ -0,0 +1,269 @@
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/videoio.hpp>
#include "vp_rtsp_ffmpeg_src_node.h"
#include "../utils/vp_utils.h"
#include <cstdio>
#include <memory>
#include <iostream>
#include <stdexcept>
namespace vp_nodes
{
    vp_rtsp_ffmpeg_src_node::vp_rtsp_ffmpeg_src_node(std::string node_name,
                                                     int channel_index,
                                                     std::string rtsp_url,
                                                     float resize_ratio,
                                                     int skip_interval,
                                                     bool use_gpu,
                                                     std::string ffmpeg_format,
                                                     std::string ffmpeg_pix_fmt) : vp_src_node(node_name, channel_index, resize_ratio),
                                                                                   rtsp_url(rtsp_url),
                                                                                   skip_interval(skip_interval),
                                                                                   use_gpu(use_gpu),
                                                                                   ffmpeg_format(ffmpeg_format),
                                                                                   ffmpeg_pix_fmt(ffmpeg_pix_fmt)
    {
        assert(skip_interval >= 0 && skip_interval <= 9);
        if (use_gpu)
        {
            this->ffmpeg_template = vp_utils::string_format(this->ffmpeg_template, rtsp_url.c_str(), ffmpeg_format.c_str(), ffmpeg_pix_fmt.c_str(), std::to_string(100 + channel_index).c_str());
        }
        VP_INFO(vp_utils::string_format("[%s] [%s]", node_name.c_str(), ffmpeg_template.c_str()));
        this->initialized();
    }
    std::vector<int> vp_rtsp_ffmpeg_src_node::initialize_stream_properties()
    {
        try
        {
            // FFmpeg command to probe stream metadata
            std::string ffprobe_command = vp_utils::string_format(
                "ffprobe -v error -select_streams v:0 -show_entries stream=width,height,r_frame_rate -of csv=p=0 %s",
                rtsp_url.c_str());
            // Execute command and capture output
            FILE *pipe = popen(ffprobe_command.c_str(), "r");
            if (!pipe)
            {
                throw std::runtime_error("Failed to execute ffprobe command.");
            }
            char buffer[128];
            std::string result = "";
            while (fgets(buffer, sizeof(buffer), pipe) != nullptr)
            {
                result += buffer;
            }
            pclose(pipe);
            // Parse the output (expected format: width,height,r_frame_rate)
            std::stringstream ss(result);
            std::string width_str, height_str, fps_str;
            std::getline(ss, width_str, ',');
            std::getline(ss, height_str, ',');
            std::getline(ss, fps_str, ',');
            // Parse width and height
            int video_width = std::stoi(width_str);
            int video_height = std::stoi(height_str);
            int fps=25;
            // Parse r_frame_rate (e.g., "299/12" or "25")
            if (fps_str.find('/') != std::string::npos)
            {
                // Handle fractional frame rates
                std::stringstream fps_ss(fps_str);
                std::string numerator_str, denominator_str;
                std::getline(fps_ss, numerator_str, '/');
                std::getline(fps_ss, denominator_str, '/');
                // Convert to integer values
                int numerator = std::stoi(numerator_str);
                int denominator = std::stoi(denominator_str);
                // Calculate and round to the nearest integer
                int fps = static_cast<int>(std::round(static_cast<float>(numerator) / denominator));
            }
            else
            {
                // Handle integer frame rates
                int fps = std::stoi(fps_str);
            }
            // Optional: Correct minor deviations (e.g., if fps is close to 25)
            if (std::abs(fps - 25) < 1)
            {
                fps = 25; // Force fps to 25 if very close
            }
            // Debug log for parsed properties
            VP_INFO(vp_utils::string_format("Stream URL:%s Stream properties - Width: %d, Height: %d, FPS: %d",
                                            rtsp_url, video_width, video_height, fps));
            return std::vector<int>{video_width, video_height, fps};
        }catch (...)
        {
            return std::vector<int>{0, 0, 0};
        }
    }
    vp_rtsp_ffmpeg_src_node::~vp_rtsp_ffmpeg_src_node()
    {
        deinitialized();
    }
    // define how to read video from rtsp stream, create frame meta etc.
    // please refer to the implementation of vp_node::handle_run.
    void vp_rtsp_ffmpeg_src_node::handle_run()
    {
        std::vector<int> stream_infos = initialize_stream_properties();
        int original_width = stream_infos[0];
        int original_height = stream_infos[1];
        int original_fps = stream_infos[2];
        int video_width = original_width;
        int video_height = original_height;
        // set true fps because skip some frames
        int fps = original_fps / (skip_interval + 1);
        cv::Mat frame;
        int skip = 0;
        FILE* ffmpeg_pipe ;
        // Create a pipe buffer to read raw data from FFmpeg
        size_t frame_size = original_height * original_width * 3; // Adjust this based on expected frame size (e.g., 1920x1080 with RGB)
        unsigned char *frame_buffer = new unsigned char[frame_size];
        if (use_gpu)
        {
            VP_INFO(this->ffmpeg_template);
            ffmpeg_pipe = popen(this->ffmpeg_template.c_str(), "r");
            if (!ffmpeg_pipe)
            {
                VP_WARN("Failed to start FFmpeg process, switching USING CPU.");
                use_gpu = false;
            }
        }
        while (alive)
        {
            // check if need workc
            gate.knock();
            if (!use_gpu)
            {
                // try to open capture
                if (!rtsp_capture.isOpened())
                {
                    if (!rtsp_capture.open(this->rtsp_url, cv::CAP_FFMPEG))
                    {
                        VP_WARN(vp_utils::string_format("[%s] open rtsp failed, try again...", node_name.c_str()));
                        continue;
                    }
                }
                if (video_width == 0 || video_height == 0 || fps == 0)
                {
                    video_width = rtsp_capture.get(cv::CAP_PROP_FRAME_WIDTH);
                    video_height = rtsp_capture.get(cv::CAP_PROP_FRAME_HEIGHT);
                    fps = rtsp_capture.get(cv::CAP_PROP_FPS);
                    original_fps = fps;
                    original_width = video_width;
                    original_height = video_height;
                    // set true fps because skip some frames
                    fps = fps / (skip_interval + 1);
                }
                // stream_info_hooker activated if need
                vp_stream_info stream_info{channel_index, original_fps, original_width, original_height, to_string()};
                invoke_stream_info_hooker(node_name, stream_info);
                rtsp_capture >> frame;
            }
            else
            {
                // Read the raw video data from the pipe into a frame
                if (fread(frame_buffer, sizeof(unsigned char), frame_size, ffmpeg_pipe) <= 0)
                {
                    VP_WARN("Failed to read frame from FFmpeg pipe, retrying...");
                    continue;
                }
                // stream_info_hooker activated if need
                vp_stream_info stream_info{channel_index, original_fps, original_width, original_height, to_string()};
                invoke_stream_info_hooker(node_name, stream_info);
                // Convert the raw video data into an OpenCV Mat object
                frame = cv::Mat(original_height, original_width, CV_8UC3, frame_buffer);
            }
            if (frame.empty())
            {
                VP_WARN(vp_utils::string_format("[%s] reading frame empty, total frame==>%d", node_name.c_str(), frame_index));
                continue;
            }
            // need skip
            if (skip < skip_interval)
            {
                skip++;
                continue;
            }
            skip = 0;
            cv::Mat resize_frame;
            if (this->resize_ratio != 1.0f)
            {
                cv::resize(frame, resize_frame, cv::Size(), resize_ratio, resize_ratio);
            }
            else
            {
                resize_frame = frame.clone(); // clone!;
            }
            // set true size because resize
            video_width = resize_frame.cols;
            video_height = resize_frame.rows;
            this->frame_index++;
            // create frame meta
            auto out_meta =
                std::make_shared<vp_objects::vp_frame_meta>(resize_frame, this->frame_index, this->channel_index, video_width, video_height, fps);
            if (out_meta != nullptr)
            {
                this->out_queue.push(out_meta);
                // handled hooker activated if need
                if (this->meta_handled_hooker)
                {
                    meta_handled_hooker(node_name, out_queue.size(), out_meta);
                }
                // important! notify consumer of out_queue in case it is waiting.
                this->out_queue_semaphore.signal();
                VP_DEBUG(vp_utils::string_format("[%s] after handling meta, out_queue.size()==>%d", node_name.c_str(), out_queue.size()));
            }
        }
        if (use_gpu)
        {
            fclose(ffmpeg_pipe);
        }
        // send dead flag for dispatch_thread
        this->out_queue.push(nullptr);
        this->out_queue_semaphore.signal();
    }
    // return stream url
    std::string vp_rtsp_ffmpeg_src_node::to_string()
    {
        return rtsp_url;
    }
}
nodes/vp_rtsp_ffmpeg_src_node.h
New file
@@ -0,0 +1,44 @@
#pragma once
#include <string>
#include "vp_src_node.h"
namespace vp_nodes {
    // rtsp source node, receive video stream via rtsp protocal.
    // example:
    // rtsp://admin:admin12345@192.168.77.110:554/
    class vp_rtsp_ffmpeg_src_node: public vp_src_node {
    private:
        /* data */
        std::string ffmpeg_template = "ffmpeg -hwaccel cuda -i %s -f %s -pix_fmt %s pipe:%s" ;
        cv::VideoCapture rtsp_capture;
        std::vector<int> initialize_stream_properties() ;
    protected:
        // re-implemetation
        virtual void handle_run() override;
    public:
        vp_rtsp_ffmpeg_src_node(std::string node_name,
                        int channel_index,
                        std::string rtsp_url,
                        float resize_ratio = 1.0,
                        int skip_interval = 0,
                        bool use_gpu = false,
                        std::string ffmpeg_format = "rawvideo",  // other options: avi/mp4/mov/mkv/flv/gif/h264/hevc
                        std::string ffmpeg_pix_fmt= "yuv420p");
        ~vp_rtsp_ffmpeg_src_node();
        virtual std::string to_string() override;
        std::string rtsp_url;
        bool use_gpu = false;
        std::string ffmpeg_format = "rawvideo";
        std::string ffmpeg_pix_fmt = "yuv420p";
        // 0 means no skip
        int skip_interval = 0;
    };
}
objects/ba/vp_ba_result.h
@@ -12,12 +12,13 @@
        NONE = 0b00000000,       // none
        CROSSLINE = 0b00000001,  // cross line
        STOP = 0b00000010,       // enter stop status
        UNSTOP = 0b00000100,     // leave stop status
        JAM = 0b00001000,        // enter jam status
        UNJAM = 0b00010000,      // leave jam status
        GATHERING = 0b00100000,
        FALLDOWN = 0b01000000,
        WRONGDIRECTION =0b10000000
        UNSTOP = 0b00000011,     // leave stop status
        JAM = 0b00000100,        // enter jam status
        UNJAM = 0b00000101,      // leave jam status
        GATHERING = 0b00000110,
        FALLDOWN = 0b00000111,
        WRONGDIRECTION =0b00001000,
        DETECTREPORT =0b00001001
        /* more */
    };
samples/from_argv_all_in_one_rtsp.cpp
New file
@@ -0,0 +1,137 @@
#include "../nodes/vp_file_src_node.h"
#include "../nodes/vp_rtsp_src_node.h"
#include "../nodes/vp_rtsp_ffmpeg_src_node.h"
#include "../nodes/vp_split_node.h"
#include "../nodes/infers/vp_trt_vehicle_detector.h"
#include "../nodes/infers/vp_trt_vehicle_plate_detector.h"
#include "../nodes/infers/vp_trt_vehicle_color_classifier.h"
#include "../nodes/infers/vp_yolo_detector_node.h"
#include "../nodes/osd/vp_osd_node.h"
#include "../nodes/vp_sync_node.h"
#include "../nodes/track/vp_sort_track_node.h"
#include "../nodes/ba/vp_ba_jam_node.h"
#include "../nodes/ba/vp_ba_stop_node.h"
#include "../nodes/ba/vp_ba_wrong_direction_node.h"
#include "../nodes/ba/vp_ba_person_gathering_node.h"
#include "../nodes/ba/vp_ba_person_falldown_node.h"
#include "../nodes/ba/vp_ba_report_detect_node.h"
#include "../nodes/osd/vp_ba_stop_osd_node.h"
#include "../nodes/broker/vp_json_kafka_broker_node.h"
#include "../nodes/record/vp_record_node.h"
#include "../nodes/vp_screen_des_node.h"
#include "../nodes/vp_fake_des_node.h"
#include "../nodes/vp_placeholder_node.h"
#include "../utils/analysis_board/vp_analysis_board.h"
/*
* ## firesmoke_detect_sample ##
* detect firesmoke using yolo.
*/
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://127.0.0.1:8554/demo";
    std::string kafka_server_point = "127.0.0.1:9092";
    float resize_ratio = 0.4;
    int skip_interval = 3;
    int channel_index = 21;
    // 如果提供了第一个和第二个参数,则覆盖默认的路径
    if (args.size() >= 5) {
        rtsp_path = args[0];
        resize_ratio = std::stof(args[1]);
        kafka_server_point = args[2];
        skip_interval = std::stoi(args[3]);
        channel_index = std::stoi(args[4]);
    } else {
        std::cout << "Usage: " << argv[0] << " <rtsp_path> <resize_ratio> <kafka_server_point> <skip_interval>\n";
        std::cout << "Example: " << argv[0] << " rtsp://admin:Shmixcqwe%21%40%23@172.18.10.113/Streaming/Channels/101 0.4 172.18.0.247:9092 5 21 \n";
        return -1;
    }
    // create nodes
    //auto file_src_0 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_0", 0, rtsp_path, resize_ratio);
    //auto file_src_0 = std::make_shared<vp_nodes::vp_rtsp_src_node>("rtsp_src_1", 0, rtsp_path, resize_ratio, "avdec_h264", skip_interval);
    auto file_src_0 = std::make_shared<vp_nodes::vp_rtsp_ffmpeg_src_node>("rtsp_src_1", channel_index, rtsp_path, resize_ratio, skip_interval);
    //auto file_src_1 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_1", 1, "./vp_data/test_video/falldown.mp4", 0.5);
    //auto split = std::make_shared<vp_nodes::vp_split_node>("split", false, true);  // split by deep-copy not by channel!
    //branch 0
    //auto trt_vehicle_detector = std::make_shared<vp_nodes::vp_trt_vehicle_detector>("vehicle_detector", "./vp_data/models/trt/vehicle/vehicle_detection.trt");
    auto vehicle_detector = std::make_shared<vp_nodes::vp_yolo_detector_node>("vehicle_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 trt_vehicle_plate_detector = std::make_shared<vp_nodes::vp_trt_vehicle_plate_detector>("vehicle_plate_detector", "./vp_data/models/trt/plate/vehicle_plate_box_detection.trt", "./vp_data/models/trt/plate/vehicle_plate_text_recognition.trt");
    auto trt_vehicle_color_classifier = std::make_shared<vp_nodes::vp_trt_vehicle_color_classifier>("color_cls", "./vp_data/models/trt/vehicle/vehicle_color_detection.trt", std::vector<int>{0, 1, 2});
    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_jam = std::make_shared<vp_nodes::vp_ba_jam_node>("ba_jam", regions);
    auto ba_stop = std::make_shared<vp_nodes::vp_ba_stop_node>("ba_stop", regions);
    // 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 = 800;
    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);
    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 firesmoke_detector = std::make_shared<vp_nodes::vp_yolo_detector_node>("firesmoke_detector", "./vp_data/models/det_cls/firesmoke_yolov5s.onnx", "", "./vp_data/models/det_cls/firesmoke_3classes.txt", 640, 384,1,1000,0.8,0.8);
    auto ba_report_detect = std::make_shared<vp_nodes::vp_ba_report_detect_node>("ba_report_detect_node","fire_smoke",std::vector<int>{1000,1001,1002}, true,true);
    auto json_kafka_broker_0 = std::make_shared<vp_nodes::vp_json_kafka_broker_node>("json_kafka_broker_0", kafka_server_point, "vp_ba_result", vp_nodes::vp_broke_for::BARESULT);
    auto osd_0 = std::make_shared<vp_nodes::vp_ba_stop_osd_node>("osd_0", "./vp_data/font/NotoSansCJKsc-Medium.otf");
    auto recorder = std::make_shared<vp_nodes::vp_record_node>("recorder", "./record", "./record");
    // for testing. USING fake_des node in production
    auto screen_des_0 = std::make_shared<vp_nodes::vp_screen_des_node>("screen_des_0", 0);
    auto fake_des_0 = std::make_shared<vp_nodes::vp_fake_des_node>("fake_des_0", 0);
    // construct pipeline
    vehicle_detector->attach_to({file_src_0});
    trt_vehicle_plate_detector->attach_to({vehicle_detector});
    trt_vehicle_color_classifier->attach_to({trt_vehicle_plate_detector});
    tracker->attach_to({trt_vehicle_color_classifier});
    ba_jam->attach_to({tracker});
    ba_stop->attach_to({ba_jam});
    ba_wrong_direction->attach_to({ba_stop});
    ba_person_gathering->attach_to({ba_wrong_direction});
    ba_person_falldown->attach_to({ba_person_gathering});
    firesmoke_detector->attach_to({ba_person_falldown});
    ba_report_detect->attach_to({firesmoke_detector});
    json_kafka_broker_0->attach_to({ba_report_detect});
    osd_0->attach_to({json_kafka_broker_0});
    recorder->attach_to({osd_0});
    fake_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();
}
samples/from_argv_all_in_one_sample.cpp
New file
@@ -0,0 +1,129 @@
#include "../nodes/vp_file_src_node.h"
#include "../nodes/vp_split_node.h"
#include "../nodes/infers/vp_trt_vehicle_detector.h"
#include "../nodes/infers/vp_trt_vehicle_plate_detector.h"
#include "../nodes/infers/vp_trt_vehicle_color_classifier.h"
#include "../nodes/infers/vp_yolo_detector_node.h"
#include "../nodes/osd/vp_osd_node.h"
#include "../nodes/vp_sync_node.h"
#include "../nodes/track/vp_sort_track_node.h"
#include "../nodes/ba/vp_ba_jam_node.h"
#include "../nodes/ba/vp_ba_stop_node.h"
#include "../nodes/ba/vp_ba_wrong_direction_node.h"
#include "../nodes/ba/vp_ba_person_gathering_node.h"
#include "../nodes/ba/vp_ba_person_falldown_node.h"
#include "../nodes/ba/vp_ba_report_detect_node.h"
#include "../nodes/osd/vp_ba_stop_osd_node.h"
#include "../nodes/broker/vp_json_kafka_broker_node.h"
#include "../nodes/record/vp_record_node.h"
#include "../nodes/vp_screen_des_node.h"
#include "../nodes/vp_fake_des_node.h"
#include "../nodes/vp_placeholder_node.h"
#include "../utils/analysis_board/vp_analysis_board.h"
/*
* ## firesmoke_detect_sample ##
* detect firesmoke using yolo.
*/
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/all_in_one.mp4";
    float resize_ratio = 0.5;
    // 如果提供了第一个和第二个参数,则覆盖默认的路径
    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/all_in_one.mp4 0.5\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 file_src_1 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_1", 1, "./vp_data/test_video/falldown.mp4", 0.5);
    //auto split = std::make_shared<vp_nodes::vp_split_node>("split", false, true);  // split by deep-copy not by channel!
    //branch 0
    //auto trt_vehicle_detector = std::make_shared<vp_nodes::vp_trt_vehicle_detector>("vehicle_detector", "./vp_data/models/trt/vehicle/vehicle_detection.trt");
    auto vehicle_detector = std::make_shared<vp_nodes::vp_yolo_detector_node>("vehicle_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 trt_vehicle_plate_detector = std::make_shared<vp_nodes::vp_trt_vehicle_plate_detector>("vehicle_plate_detector", "./vp_data/models/trt/plate/vehicle_plate_box_detection.trt", "./vp_data/models/trt/plate/vehicle_plate_text_recognition.trt");
    auto trt_vehicle_color_classifier = std::make_shared<vp_nodes::vp_trt_vehicle_color_classifier>("color_cls", "./vp_data/models/trt/vehicle/vehicle_color_detection.trt", std::vector<int>{0, 1, 2});
    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_jam = std::make_shared<vp_nodes::vp_ba_jam_node>("ba_jam", regions);
    auto ba_stop = std::make_shared<vp_nodes::vp_ba_stop_node>("ba_stop", regions);
    // 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);
    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 firesmoke_detector = std::make_shared<vp_nodes::vp_yolo_detector_node>("firesmoke_detector", "./vp_data/models/det_cls/firesmoke_yolov5s.onnx", "", "./vp_data/models/det_cls/firesmoke_3classes.txt", 640, 384,1,1000,0.8,0.8);
    auto ba_report_detect = std::make_shared<vp_nodes::vp_ba_report_detect_node>("ba_report_detect_node","fire_smoke",std::vector<int>{1000,1001,1002}, 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_vehicle", vp_nodes::vp_broke_for::BARESULT);
    auto osd_0 = std::make_shared<vp_nodes::vp_ba_stop_osd_node>("osd_0", "./vp_data/font/NotoSansCJKsc-Medium.otf");
    auto recorder = std::make_shared<vp_nodes::vp_record_node>("recorder", "./record", "./record");
    // for testing. USING fake_des node in production
    auto screen_des_0 = std::make_shared<vp_nodes::vp_screen_des_node>("screen_des_0", 0);
    auto fake_des_0 = std::make_shared<vp_nodes::vp_fake_des_node>("fake_des_0", 0);
    // construct pipeline
    vehicle_detector->attach_to({file_src_0});
    trt_vehicle_plate_detector->attach_to({vehicle_detector});
    trt_vehicle_color_classifier->attach_to({trt_vehicle_plate_detector});
    tracker->attach_to({trt_vehicle_color_classifier});
    ba_jam->attach_to({tracker});
    ba_stop->attach_to({ba_jam});
    ba_wrong_direction->attach_to({ba_stop});
    ba_person_gathering->attach_to({ba_wrong_direction});
    ba_person_falldown->attach_to({ba_person_gathering});
    firesmoke_detector->attach_to({ba_person_falldown});
    ba_report_detect->attach_to({firesmoke_detector});
    json_kafka_broker_0->attach_to({ba_report_detect});
    osd_0->attach_to({json_kafka_broker_0});
    recorder->attach_to({osd_0});
    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();
}
samples/from_argv_ba_crossline_rtsp.cpp
@@ -1,5 +1,6 @@
#include "../nodes/vp_file_src_node.h"
#include "../nodes/vp_rtsp_src_node.h"
#include "../nodes/vp_rtsp_ffmpeg_src_node.h"
#include "../nodes/infers/vp_yolo_detector_node.h"
#include "../nodes/track/vp_sort_track_node.h"
@@ -33,7 +34,6 @@
        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.130.228:9092\n";
@@ -43,7 +43,7 @@
    // create nodes
    //auto file_src_0 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_0", 0, video_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 rtsp_src_1 = std::make_shared<vp_nodes::vp_rtsp_ffmpeg_src_node>("rtsp_src_1", 0, rtsp_path, resize_ratio,0,true);
    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");