wangrong
2025-01-23 02819b5c047bb354b0ef2374e7c6a6ac4bbd5bba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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");
    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();
   
}