Browse Source

update record node

leon 4 tuần trước cách đây
mục cha
commit
d6c1e0ac91

+ 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->result)
+            for (auto& box : metaData->boxes)
             {
                 uint8_t b, g, r;
                 std::tie(b, g, r) = random_color(box.class_id);

+ 1 - 0
src/nodes/infer/inferNode.cpp

@@ -25,6 +25,7 @@ void print_mat(const cv::Mat& mat, int max_rows = 10, int max_cols = 10)
 
 void InferNode::handle_data(std::shared_ptr<meta::MetaData>& meta_data)
 {
+    checkRuntime(cudaSetDevice(device_id_));
     cv::Mat image = meta_data->image;
     int width = image.cols;
     int height = image.rows;

+ 44 - 29
src/nodes/record/recordNode.cpp

@@ -5,41 +5,56 @@
 namespace GNode
 {
 
-void RecordNode::work()
+void RecordNode::handle_data(std::shared_ptr<meta::MetaData>& meta_data)
 {
-    PLOGI.printf("RecordNode : [%s] start", name_.c_str());
-    while (running_)
+    cv::Mat image = meta_data->draw_image;
+    if (!writer_.isOpened())
     {
-        bool has_data = false;
-        for (auto& input_buffer : input_buffers_)
+        writer_.open(record_path_, fourcc_, fps_, cv::Size(image.cols, image.rows));
+        if (!writer_.isOpened())
         {
-            std::shared_ptr<meta::MetaData> metaData;
-            if (!input_buffer.second->try_pop(metaData))
-            {
-                continue;
-            }
-            has_data = true;
-            // printf("Node %s get data from %s\n", name_.c_str(), input_buffer.first.c_str());
-            cv::Mat image = metaData->draw_image;
-            if (!writer_.isOpened())
-            {
-                writer_.open(record_path_, fourcc_, fps_, cv::Size(image.cols, image.rows));
-                if (!writer_.isOpened())
-                {
-                    PLOGE.printf("RecordNode : [%s] cannot open video writer", name_.c_str());
-                    break;
-                }
-            }
-            writer_ << image;
-        }
-        if (!has_data) {
-            std::unique_lock<std::mutex> lock(mutex_);
-            cond_var_->wait_for(lock, std::chrono::milliseconds(100), [this] {
-                return !running_;  // 等待时检查退出条件
-            });
+            PLOGE.printf("RecordNode : [%s] cannot open video writer", name_.c_str());
+            break;
         }
     }
+    writer_ << image;
 }
 
+// void RecordNode::work()
+// {
+//     PLOGI.printf("RecordNode : [%s] start", name_.c_str());
+//     while (running_)
+//     {
+//         bool has_data = false;
+//         for (auto& input_buffer : input_buffers_)
+//         {
+//             std::shared_ptr<meta::MetaData> metaData;
+//             if (!input_buffer.second->try_pop(metaData))
+//             {
+//                 continue;
+//             }
+//             has_data = true;
+//             // printf("Node %s get data from %s\n", name_.c_str(), input_buffer.first.c_str());
+//             cv::Mat image = metaData->draw_image;
+//             if (!writer_.isOpened())
+//             {
+//                 writer_.open(record_path_, fourcc_, fps_, cv::Size(image.cols, image.rows));
+//                 if (!writer_.isOpened())
+//                 {
+//                     PLOGE.printf("RecordNode : [%s] cannot open video writer", name_.c_str());
+//                     break;
+//                 }
+//             }
+//             writer_ << image;
+//         }
+//         if (!has_data) {
+//             std::unique_lock<std::mutex> lock(mutex_);
+//             cond_var_->wait_for(lock, std::chrono::milliseconds(100), [this] {
+//                 return !running_;  // 等待时检查退出条件
+//             });
+//         }
+//     }
+// }
+
 
 }   // namespace GNode

+ 1 - 1
src/nodes/record/recordNode.hpp

@@ -24,7 +24,7 @@ public:
         }
     }
 
-    void work() override;
+    void handle_data(std::shared_ptr<meta::MetaData>& meta_data) override;
     void set_record_path(const std::string& path) { record_path_ = path; }
     void set_fps(int fps) { fps_ = fps; }
     void set_fourcc(int fourcc) { fourcc_ = fourcc; }