From a9bfeef59bf8cda8b219c9b7a436f2ed21ca011b Mon Sep 17 00:00:00 2001 From: Orange <2314753575@qq.com> Date: Tue, 16 Jun 2026 22:08:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=8C=E7=BB=B4=E7=A0=81?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E7=9A=84=E7=BC=93=E5=AD=98=E6=9C=BA=E5=88=B6?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E5=AE=83=E7=9A=84=E5=90=AF=E5=8A=A8=E5=8F=82?= =?UTF-8?q?=E6=95=B0=EF=BC=88=E9=BB=98=E8=AE=A4=E4=BD=BF=E7=94=A8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ src/qr_detection/src/qr_dete_depth.cpp | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4cf7969..039630c 100644 --- a/README.md +++ b/README.md @@ -102,4 +102,6 @@ foxglove # 启动foxbridge 启动键盘控制: `ros2 run teleop_twist_keyboard teleop_twist_keyboard ` +运行二维码检测(无缓存版): +`ros2 run qr_detection qr_dete_depth_node --ros-args -p use_buffer:=false` # 五、日志 diff --git a/src/qr_detection/src/qr_dete_depth.cpp b/src/qr_detection/src/qr_dete_depth.cpp index d3c9efc..364ec40 100644 --- a/src/qr_detection/src/qr_dete_depth.cpp +++ b/src/qr_detection/src/qr_dete_depth.cpp @@ -13,6 +13,7 @@ public: MinimalHbmemSubscriber() : Node("qr_detection"), detect_qr_code_(true) // 默认检测二维码 { + use_buffer = this->declare_parameter("use_buffer", true); // 声明参数,默认使用缓存 // 订阅 /aurora/rgb/image_raw(sensor_msgs::msg::Image 格式) subscription_image_ = this->create_subscription( @@ -85,6 +86,7 @@ private: RCLCPP_INFO(this->get_logger(), "Decoded %s symbol \"%s\"", symbol->get_type_name().c_str(), symbol->get_data().c_str()); } + qr_results_buff_ = qr_results; // 更新缓存 } else { qr_results = "QR Code not detected"; RCLCPP_INFO(this->get_logger(), "QR Code not detected"); @@ -92,7 +94,12 @@ private: // 发布 QR 结果 auto message = std_msgs::msg::String(); - message.data = qr_results; + if (use_buffer){ + message.data = qr_results_buff_; + } + else{ + message.data = qr_results; + } publisher_->publish(message); } @@ -118,8 +125,12 @@ private: // QR code results 发布器 rclcpp::Publisher::SharedPtr publisher_; + // 参数 + bool use_buffer; // 二维码检测标志位 bool detect_qr_code_; + // 二维码检测结果缓存 + std::string qr_results_buff_; }; int main(int argc, char * argv[])