Sfoglia il codice sorgente

测试分析节点

leon 1 mese fa
parent
commit
3f78bd8162

+ 3 - 6
src/nodes/analyze/analyzeNode.cpp

@@ -1,6 +1,7 @@
 #include "nodes/base/base.hpp"
 #include "nodes/analyze/analyzeNode.hpp"
 
+#include "nodes/analyze/function/cross.hpp"
 
 namespace GNode
 {
@@ -23,12 +24,8 @@ void AnalyzeNode::work()
             int width = metaData->image.cols;
             int height = metaData->image.rows;
 
-            auto boxes = metaData->boxes;
-            for (auto& box : boxes)
-            {
-                // 将分析的结果存入到 metaData->result 中
-            }
-            metaData->result = boxes;
+            auto res = person_cross_line(metaData->track_boxes, cv::Point(0, 0), cv::Point(width, height));
+            metaData->result = res;
             for (auto& output_buffer : output_buffers_)
             {
                 // printf("Node %s push data to %s\n", name_.c_str(), output_buffer.first.c_str());

+ 39 - 0
src/nodes/analyze/function/cross.cpp

@@ -0,0 +1,39 @@
+#include "nodes/analyze/function/cross.hpp"
+#include "opencv2/opencv.hpp"
+#include <unordered_map>
+data::BoxArray person_cross_line(const data::BoxArray& boxes, const cv::Point& line_start, const cv::Point& line_end)
+{
+    // 记录之前人在线的那一侧
+    static std::unordered_map<int, Side> person_side;
+    data::BoxArray result;
+    for (auto& box : boxes)
+    {
+        cv::Point bottom_center((box.left + box.right) / 2, box.bottom);
+        // > 0 代表在线段的左侧
+        if ((center.x - line_start.x) * (line_end.y - line_start.y) - (center.y - line_start.y) * (line_end.x - line_start.x) > 0)
+        {
+            if (person_side.find(box.class_id) == person_side.end())
+            {
+                person_side[box.class_id] = Side::LEFT;
+            }
+            else if (person_side[box.class_id] == Side::RIGHT)
+            {
+                person_side[box.class_id] = Side::LEFT;
+                result.push_back(box);
+            }
+        }
+        else
+        {
+            if (person_side.find(box.class_id) == person_side.end())
+            {
+                person_side[box.class_id] = Side::RIGHT;
+            }
+            else if (person_side[box.class_id] == Side::LEFT)
+            {
+                person_side[box.class_id] = Side::RIGHT;
+                result.push_back(box);
+            }
+        }
+    }
+    return result;
+}

+ 17 - 0
src/nodes/analyze/function/cross.hpp

@@ -0,0 +1,17 @@
+#ifndef CROSS_HPP__
+#define CROSS_HPP__
+
+#include "common/data.hpp"
+#include "common/meta.hpp"
+
+// 人员跨越线段检测
+
+enum class Side
+{
+    LEFT = 0,
+    RIGHT = 1
+};
+
+data::BoxArray person_cross_line(const data::BoxArray& boxes, const cv::Point& line_start, const cv::Point& line_end);
+
+#endif // CROSS_HPP__

+ 1 - 1
src/nodes/draw/drawNode.cpp

@@ -78,7 +78,7 @@ void DrawNode::work()
             int image_width = image.cols;
             int image_height = image.rows;
             PositionManager<float> pm(getFontSize);
-            for (auto& box : metaData->track_boxes)
+            for (auto& box : metaData->result)
             {
                 uint8_t b, g, r;
                 std::tie(b, g, r) = random_color(box.class_id);