#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/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;
|
bool usegpu = false; // 新增参数,默认值为 false
|
|
// 如果提供了至少 6 个参数,则覆盖默认值
|
if (args.size() >= 6) {
|
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]);
|
std::string usegpu_arg = args[5];
|
// 将字符串转换为布尔值,支持 true/false 或 1/0
|
std::transform(usegpu_arg.begin(), usegpu_arg.end(), usegpu_arg.begin(), ::tolower);
|
if (usegpu_arg == "true" || usegpu_arg == "1") {
|
usegpu = true;
|
} else if (usegpu_arg == "false" || usegpu_arg == "0") {
|
usegpu = false;
|
} else {
|
std::cerr << "Invalid value for <usegpu>. Please use 'true', 'false', '1', or '0'.\n";
|
return -1;
|
}
|
} else {
|
std::cout << "Usage: " << argv[0] << " <rtsp_path> <resize_ratio> <kafka_server_point> <skip_interval> <channel_index> <usegpu>\n";
|
std::cout << "Example: " << argv[0] << " rtsp://127.0.0.1:8554/demo 0.4 127.0.0.1:9092 5 21 true\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, usegpu);
|
//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 = {
|
{channel_index, std::vector<vp_objects::vp_point>{vp_objects::vp_point(280, 30), vp_objects::vp_point(340, 30), vp_objects::vp_point(600, 330), vp_objects::vp_point(30, 350)}}, // channel0 -> region
|
{1, std::vector<vp_objects::vp_point>{vp_objects::vp_point(280, 30), vp_objects::vp_point(340, 30), vp_objects::vp_point(600, 330), vp_objects::vp_point(30, 350)}} // 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);
|
|
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});
|
json_kafka_broker_0->attach_to({ba_stop});
|
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();
|
|
}
|