fix: harden multi-camera verification capture

This commit is contained in:
slz
2026-09-10 14:25:33 +08:00
parent 1f1b541bda
commit 7c65ea9983
3 changed files with 238 additions and 69 deletions
@@ -1,4 +1,5 @@
#include <rclcpp/rclcpp.hpp>
#include <sensor_msgs/image_encodings.hpp>
#include <sensor_msgs/msg/image.hpp>
#if __has_include(<message_filters/subscriber.hpp>)
@@ -298,7 +299,17 @@ class ImageSyncNode : public rclcpp::Node {
try {
for (const auto &msg : msgs) {
auto cv_image = cv_bridge::toCvShare(msg);
images.push_back(cv_image->image.clone());
cv::Mat image;
if (msg->encoding == sensor_msgs::image_encodings::RGB8) {
cv::cvtColor(cv_image->image, image, cv::COLOR_RGB2BGR);
} else if (msg->encoding == sensor_msgs::image_encodings::RGBA8) {
cv::cvtColor(cv_image->image, image, cv::COLOR_RGBA2BGR);
} else if (msg->encoding == sensor_msgs::image_encodings::BGRA8) {
cv::cvtColor(cv_image->image, image, cv::COLOR_BGRA2BGR);
} else {
image = cv_image->image.clone();
}
images.push_back(std::move(image));
timestamps.push_back(stamp_to_seconds(msg->header.stamp));
}
} catch (cv_bridge::Exception &e) {
@@ -477,8 +488,14 @@ class ImageSyncNode : public rclcpp::Node {
cv::applyColorMap(tmp, image, cv::COLORMAP_JET);
} else if (images[i].channels() == 3) {
image = images[i].clone();
} else if (images[i].channels() == 4) {
cv::cvtColor(images[i], image, cv::COLOR_BGRA2BGR);
} else {
cv::cvtColor(images[i], image, cv::COLOR_GRAY2BGR);
RCLCPP_WARN(this->get_logger(), "Display first channel of unsupported %d-channel image %s",
images[i].channels(), topic_infos[i].topic.c_str());
cv::Mat first_channel;
cv::extractChannel(images[i], first_channel, 0);
cv::cvtColor(first_channel, image, cv::COLOR_GRAY2BGR);
}
const std::string text = topic_infos[i].camera_name + " " + topic_infos[i].image_type +