main.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #include "nodes/base/base.hpp"
  2. #include "nodes/stream/streamNode.hpp"
  3. #include "nodes/infer/inferNode.hpp"
  4. #include "nodes/draw/drawNode.hpp"
  5. #include "nodes/track/trackNode.hpp"
  6. #include "nodes/analyze/analyzeNode.hpp"
  7. #include "nodes/httpPush/httpPush.hpp"
  8. #include "nodes/record/recordNode.hpp"
  9. #include "plog/Log.h"
  10. #include "plog/Initializers/RollingFileInitializer.h"
  11. #include "graph/graph.hpp"
  12. void run_from_json()
  13. {
  14. }
  15. void test_depth()
  16. {
  17. 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);
  18. src_node0->set_skip_frame(1);
  19. std::shared_ptr<Infer> depth_model = load("model/depth.engine", ModelType::DEPTH_ANYTHING, {}, 0, 0.25, 0.45);
  20. std::shared_ptr<GNode::InferNode> infer_node = std::make_shared<GNode::InferNode>("depth");
  21. infer_node->set_model_instance(depth_model, depth_model->get_gpu_id());
  22. std::shared_ptr<GNode::DrawNode> draw_node = std::make_shared<GNode::DrawNode>("draw");
  23. std::shared_ptr<GNode::HttpPushNode> push_node = std::make_shared<GNode::HttpPushNode>("push", "172.16.20.168", 8080, "/push");
  24. GNode::LinkNode(src_node0, infer_node);
  25. GNode::LinkNode(infer_node, draw_node);
  26. GNode::LinkNode(draw_node, push_node);
  27. push_node->start();
  28. draw_node->start();
  29. infer_node->start();
  30. src_node0->start();
  31. std::this_thread::sleep_for(std::chrono::seconds(10));
  32. }
  33. void test_yolo()
  34. {
  35. OverflowStrategy stage = OverflowStrategy::BlockTimeout;
  36. int max_size = 100;
  37. std::vector<std::string> names = {
  38. "person", "bicycle", "car",
  39. "motorcycle", "airplane", "bus",
  40. "train", "truck", "boat",
  41. "traffic light", "fire hydrant", "stop sign",
  42. "parking meter", "bench", "bird",
  43. "cat", "dog", "horse",
  44. "sheep", "cow", "elephant",
  45. "bear", "zebra", "giraffe",
  46. "backpack", "umbrella", "handbag",
  47. "tie", "suitcase", "frisbee",
  48. "skis", "snowboard", "sports ball",
  49. "kite", "baseball bat", "baseball glove",
  50. "skateboard", "surfboard", "tennis racket",
  51. "bottle", "wine glass", "cup",
  52. "fork", "knife", "spoon",
  53. "bowl", "banana", "apple",
  54. "sandwich", "orange", "broccoli",
  55. "carrot", "hot dog", "pizza",
  56. "donut", "cake", "chair",
  57. "couch", "potted plant", "bed",
  58. "dining table", "toilet", "tv",
  59. "laptop", "mouse", "remote",
  60. "keyboard", "cell phone", "microwave",
  61. "oven", "toaster", "sink",
  62. "refrigerator", "book", "clock",
  63. "vase", "scissors", "teddy bear",
  64. "hair drier", "toothbrush"};
  65. // std::vector<std::string> names = { "person", "clothes", "vest" };
  66. // std::vector<std::string> names = { "person", "car", "close", "open" };
  67. // 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);
  68. std::shared_ptr<GNode::StreamNode> src_node0 = std::make_shared<GNode::StreamNode>("src0", "carperson.mp4", 1, GNode::DecodeType::GPU);
  69. src_node0->set_skip_frame(1);
  70. std::shared_ptr<Infer> yolo_model = load("model/model1.engine", ModelType::YOLO11SEG, names, 1, 0.25, 0.45);
  71. std::shared_ptr<GNode::InferNode> infer_node = std::make_shared<GNode::InferNode>("seg");
  72. infer_node->set_model_instance(yolo_model, yolo_model->get_gpu_id());
  73. std::shared_ptr<GNode::TrackNode> track_node = std::make_shared<GNode::TrackNode>("tracker", "person", 30, 30);
  74. std::shared_ptr<GNode::AnalyzeNode> analyze_node = std::make_shared<GNode::AnalyzeNode>("analyze");
  75. std::shared_ptr<GNode::DrawNode> draw_node = std::make_shared<GNode::DrawNode>("draw");
  76. std::shared_ptr<GNode::RecordNode> record_node = std::make_shared<GNode::RecordNode>("record");
  77. record_node->set_record_path("result/result.mp4");
  78. record_node->set_fps(25);
  79. record_node->set_fourcc(cv::VideoWriter::fourcc('m', 'p', '4', 'v'));
  80. GNode::LinkNode(src_node0, infer_node, max_size, stage);
  81. GNode::LinkNode(infer_node, track_node, max_size, stage);
  82. GNode::LinkNode(track_node, analyze_node, max_size, stage);
  83. GNode::LinkNode(analyze_node, draw_node, max_size, stage);
  84. GNode::LinkNode(draw_node, record_node, max_size, stage);
  85. record_node->start();
  86. draw_node->start();
  87. analyze_node->start();
  88. track_node->start();
  89. infer_node->start();
  90. src_node0->start();
  91. getchar();
  92. }
  93. void test_multi()
  94. {
  95. std::vector<std::string> names = { "person", "clothes", "vest" };
  96. 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);
  97. src_node0->set_skip_frame(10);
  98. 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);
  99. src_node1->set_skip_frame(10);
  100. 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);
  101. src_node2->set_skip_frame(10);
  102. std::shared_ptr<Infer> yolo_model = load("model/yolo11s.engine", ModelType::YOLO11, names, 1, 0.25, 0.45);
  103. std::shared_ptr<GNode::InferNode> infer_node1 = std::make_shared<GNode::InferNode>("yolo11");
  104. infer_node1->set_model_instance(yolo_model, yolo_model->get_gpu_id());
  105. std::shared_ptr<Infer> depth_model = load("model/depth.engine", ModelType::DEPTH_ANYTHING, {}, 1, 0.25, 0.45);
  106. std::shared_ptr<GNode::InferNode> infer_node2 = std::make_shared<GNode::InferNode>("depth");
  107. infer_node2->set_model_instance(depth_model, depth_model->get_gpu_id());
  108. std::shared_ptr<GNode::DrawNode> draw_node = std::make_shared<GNode::DrawNode>("draw");
  109. std::shared_ptr<GNode::HttpPushNode> push_node = std::make_shared<GNode::HttpPushNode>("push", "172.16.20.168", 8080, "/push");
  110. GNode::LinkNode(src_node0, infer_node1);
  111. GNode::LinkNode(src_node1, infer_node1);
  112. GNode::LinkNode(src_node2, infer_node1);
  113. GNode::LinkNode(infer_node1, infer_node2);
  114. GNode::LinkNode(infer_node2, draw_node);
  115. GNode::LinkNode(draw_node, push_node);
  116. push_node->start();
  117. draw_node->start();
  118. infer_node1->start();
  119. infer_node2->start();
  120. src_node0->start();
  121. src_node1->start();
  122. src_node2->start();
  123. getchar();
  124. }
  125. void test_from_json(const std::string& json_path)
  126. {
  127. }
  128. int main(int argc , char* argv[])
  129. {
  130. plog::init(plog::info, "log/vsp.log", 1000000, 5);
  131. if (argc < 2) {
  132. std::cerr << "Usage: " << argv[0] << " <json_path>" << std::endl;
  133. return 1;
  134. }
  135. const char* json_path = argv[1];
  136. Graph::Graph graph_manager;
  137. graph_manager.create_from_json(std::string(json_path));
  138. for (const auto& p : graph_manager.getPipelines()) {
  139. std::cout << "Pipeline ID: " << p.pipeline_id << ", Description: " << p.description << ", Nodes: " << p.nodes.size() << std::endl;
  140. for(const auto& node : p.nodes) {
  141. std::cout << " - Node Name: " << node->get_name() << std::endl;
  142. }
  143. }
  144. graph_manager.start_pipelines();
  145. getchar();
  146. return 0;
  147. }
  148. // TODO
  149. // 硬解码、软解码 完成 软解使用opencv + ffmpeg,硬解使用nvcodec + ffmpeg
  150. // 模型复用 完成,基类加锁保证一致性
  151. // 画图节点 完成
  152. // 推送节点 基本完成
  153. // 日志 完成
  154. // YOLO11 seg 完成
  155. // 分析节点
  156. // 通过配置文件创建 pipeline
  157. // 置信度阈值修改
  158. // 设置电子围栏