123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- #include "nodes/base/base.hpp"
- #include "nodes/stream/streamNode.hpp"
- #include "nodes/infer/inferNode.hpp"
- #include "nodes/draw/drawNode.hpp"
- #include "nodes/track/trackNode.hpp"
- #include "nodes/analyze/analyzeNode.hpp"
- #include "nodes/httpPush/httpPush.hpp"
- #include "nodes/record/recordNode.hpp"
- #include "plog/Log.h"
- #include "plog/Initializers/RollingFileInitializer.h"
- #include "graph/graph.hpp"
- void run_from_json()
- {
-
- }
- void test_depth()
- {
- std::shared_ptr<GNode::StreamNode> src_node0 = std::make_shared<GNode::StreamNode>("src0", "rtsp://admin:lww123456@172.16.22.16:554/Streaming/Channels/201", 0, GNode::DecodeType::GPU);
- src_node0->set_skip_frame(1);
- std::shared_ptr<Infer> depth_model = load("model/depth.engine", ModelType::DEPTH_ANYTHING, {}, 0, 0.25, 0.45);
- std::shared_ptr<GNode::InferNode> infer_node = std::make_shared<GNode::InferNode>("depth");
- infer_node->set_model_instance(depth_model, depth_model->get_gpu_id());
- std::shared_ptr<GNode::DrawNode> draw_node = std::make_shared<GNode::DrawNode>("draw");
- std::shared_ptr<GNode::HttpPushNode> push_node = std::make_shared<GNode::HttpPushNode>("push", "172.16.20.168", 8080, "/push");
-
- GNode::LinkNode(src_node0, infer_node);
- GNode::LinkNode(infer_node, draw_node);
- GNode::LinkNode(draw_node, push_node);
- push_node->start();
- draw_node->start();
- infer_node->start();
- src_node0->start();
- std::this_thread::sleep_for(std::chrono::seconds(10));
- }
- void test_yolo()
- {
- OverflowStrategy stage = OverflowStrategy::BlockTimeout;
- int max_size = 100;
- std::vector<std::string> names = {
- "person", "bicycle", "car",
- "motorcycle", "airplane", "bus",
- "train", "truck", "boat",
- "traffic light", "fire hydrant", "stop sign",
- "parking meter", "bench", "bird",
- "cat", "dog", "horse",
- "sheep", "cow", "elephant",
- "bear", "zebra", "giraffe",
- "backpack", "umbrella", "handbag",
- "tie", "suitcase", "frisbee",
- "skis", "snowboard", "sports ball",
- "kite", "baseball bat", "baseball glove",
- "skateboard", "surfboard", "tennis racket",
- "bottle", "wine glass", "cup",
- "fork", "knife", "spoon",
- "bowl", "banana", "apple",
- "sandwich", "orange", "broccoli",
- "carrot", "hot dog", "pizza",
- "donut", "cake", "chair",
- "couch", "potted plant", "bed",
- "dining table", "toilet", "tv",
- "laptop", "mouse", "remote",
- "keyboard", "cell phone", "microwave",
- "oven", "toaster", "sink",
- "refrigerator", "book", "clock",
- "vase", "scissors", "teddy bear",
- "hair drier", "toothbrush"};
- // std::vector<std::string> names = { "person", "clothes", "vest" };
- // std::vector<std::string> names = { "person", "car", "close", "open" };
- // std::shared_ptr<GNode::StreamNode> src_node0 = std::make_shared<GNode::StreamNode>("src0", "rtsp://admin:lww123456@172.16.22.16:554/Streaming/Channels/201", 0, GNode::DecodeType::GPU);
- std::shared_ptr<GNode::StreamNode> src_node0 = std::make_shared<GNode::StreamNode>("src0", "carperson.mp4", 1, GNode::DecodeType::GPU);
- src_node0->set_skip_frame(1);
- std::shared_ptr<Infer> yolo_model = load("model/model1.engine", ModelType::YOLO11SEG, names, 1, 0.25, 0.45);
- std::shared_ptr<GNode::InferNode> infer_node = std::make_shared<GNode::InferNode>("seg");
- infer_node->set_model_instance(yolo_model, yolo_model->get_gpu_id());
- std::shared_ptr<GNode::TrackNode> track_node = std::make_shared<GNode::TrackNode>("tracker", "person", 30, 30);
- std::shared_ptr<GNode::AnalyzeNode> analyze_node = std::make_shared<GNode::AnalyzeNode>("analyze");
- std::shared_ptr<GNode::DrawNode> draw_node = std::make_shared<GNode::DrawNode>("draw");
- std::shared_ptr<GNode::RecordNode> record_node = std::make_shared<GNode::RecordNode>("record");
- record_node->set_record_path("result/result.mp4");
- record_node->set_fps(25);
- record_node->set_fourcc(cv::VideoWriter::fourcc('m', 'p', '4', 'v'));
-
- GNode::LinkNode(src_node0, infer_node, max_size, stage);
- GNode::LinkNode(infer_node, track_node, max_size, stage);
- GNode::LinkNode(track_node, analyze_node, max_size, stage);
- GNode::LinkNode(analyze_node, draw_node, max_size, stage);
- GNode::LinkNode(draw_node, record_node, max_size, stage);
- record_node->start();
- draw_node->start();
- analyze_node->start();
- track_node->start();
- infer_node->start();
- src_node0->start();
- getchar();
- }
- void test_multi()
- {
- std::vector<std::string> names = { "person", "clothes", "vest" };
- std::shared_ptr<GNode::StreamNode> src_node0 = std::make_shared<GNode::StreamNode>("src0", "rtsp://admin:lww123456@172.16.22.16:554/Streaming/Channels/101", 0, GNode::DecodeType::GPU);
- src_node0->set_skip_frame(10);
- std::shared_ptr<GNode::StreamNode> src_node1 = std::make_shared<GNode::StreamNode>("src1", "rtsp://admin:lww123456@172.16.22.16:554/Streaming/Channels/201", 0, GNode::DecodeType::GPU);
- src_node1->set_skip_frame(10);
- std::shared_ptr<GNode::StreamNode> src_node2 = std::make_shared<GNode::StreamNode>("src2", "rtsp://admin:lww123456@172.16.22.16:554/Streaming/Channels/301", 0, GNode::DecodeType::GPU);
- src_node2->set_skip_frame(10);
- std::shared_ptr<Infer> yolo_model = load("model/yolo11s.engine", ModelType::YOLO11, names, 1, 0.25, 0.45);
- std::shared_ptr<GNode::InferNode> infer_node1 = std::make_shared<GNode::InferNode>("yolo11");
- infer_node1->set_model_instance(yolo_model, yolo_model->get_gpu_id());
- std::shared_ptr<Infer> depth_model = load("model/depth.engine", ModelType::DEPTH_ANYTHING, {}, 1, 0.25, 0.45);
- std::shared_ptr<GNode::InferNode> infer_node2 = std::make_shared<GNode::InferNode>("depth");
- infer_node2->set_model_instance(depth_model, depth_model->get_gpu_id());
- std::shared_ptr<GNode::DrawNode> draw_node = std::make_shared<GNode::DrawNode>("draw");
- std::shared_ptr<GNode::HttpPushNode> push_node = std::make_shared<GNode::HttpPushNode>("push", "172.16.20.168", 8080, "/push");
- GNode::LinkNode(src_node0, infer_node1);
- GNode::LinkNode(src_node1, infer_node1);
- GNode::LinkNode(src_node2, infer_node1);
- GNode::LinkNode(infer_node1, infer_node2);
- GNode::LinkNode(infer_node2, draw_node);
- GNode::LinkNode(draw_node, push_node);
- push_node->start();
- draw_node->start();
- infer_node1->start();
- infer_node2->start();
- src_node0->start();
- src_node1->start();
- src_node2->start();
- getchar();
- }
- void test_from_json(const std::string& json_path)
- {
-
- }
- int main(int argc , char* argv[])
- {
- plog::init(plog::info, "log/vsp.log", 1000000, 5);
- if (argc < 2) {
- std::cerr << "Usage: " << argv[0] << " <json_path>" << std::endl;
- return 1;
- }
- const char* json_path = argv[1];
- Graph::Graph graph_manager;
- graph_manager.create_from_json(std::string(json_path));
- for (const auto& p : graph_manager.getPipelines()) {
- std::cout << "Pipeline ID: " << p.pipeline_id << ", Description: " << p.description << ", Nodes: " << p.nodes.size() << std::endl;
- for(const auto& node : p.nodes) {
- std::cout << " - Node Name: " << node->get_name() << std::endl;
- }
- }
- graph_manager.start_pipelines();
- getchar();
- return 0;
- }
- // TODO
- // 硬解码、软解码 完成 软解使用opencv + ffmpeg,硬解使用nvcodec + ffmpeg
- // 模型复用 完成,基类加锁保证一致性
- // 画图节点 完成
- // 推送节点 基本完成
- // 日志 完成
- // YOLO11 seg 完成
- // 分析节点
- // 通过配置文件创建 pipeline
- // 置信度阈值修改
- // 设置电子围栏
|