mirror of
https://github.com/orbbec/OrbbecSDK_ROS2.git
synced 2026-09-12 11:10:19 +08:00
fixed save 10 image
This commit is contained in:
@@ -396,6 +396,7 @@ class OBCameraNode {
|
||||
bool enable_d2c_viewer_ = false;
|
||||
std::unique_ptr<D2CViewer> d2c_viewer_ = nullptr;
|
||||
std::map<stream_index_pair, std::atomic_bool> save_images_;
|
||||
std::map<stream_index_pair, int> save_images_count_;
|
||||
std::atomic_bool save_point_cloud_{false};
|
||||
std::atomic_bool save_colored_point_cloud_{false};
|
||||
rclcpp::Service<std_srvs::srv::Empty>::SharedPtr save_images_srv_;
|
||||
|
||||
@@ -1181,17 +1181,19 @@ void OBCameraNode::onNewFrameCallback(const std::shared_ptr<ob::Frame> &frame,
|
||||
|
||||
void OBCameraNode::saveImageToFile(const stream_index_pair &stream_index, const cv::Mat &image,
|
||||
const sensor_msgs::msg::Image::SharedPtr &image_msg) {
|
||||
if (save_images_[stream_index]) {
|
||||
if (save_images_[stream_index] && save_images_count_[stream_index] > 0) {
|
||||
auto now = time(nullptr);
|
||||
std::stringstream ss;
|
||||
ss << std::put_time(localtime(&now), "%Y%m%d_%H%M%S");
|
||||
auto current_path = std::filesystem::current_path().string();
|
||||
auto fps = fps_[stream_index];
|
||||
int index = 10 - save_images_count_[stream_index];
|
||||
--save_images_count_[stream_index];
|
||||
std::string file_suffix = stream_index == DEPTH ? ".raw" : ".png";
|
||||
std::string filename = current_path + "/image/" + stream_name_[stream_index] + "_" +
|
||||
std::to_string(image_msg->width) + "x" +
|
||||
std::to_string(image_msg->height) + "_" + std::to_string(fps) + "hz_" +
|
||||
ss.str() + file_suffix;
|
||||
ss.str() + "_" + std::to_string(index) + file_suffix;
|
||||
if (!std::filesystem::exists(current_path + "/image")) {
|
||||
std::filesystem::create_directory(current_path + "/image");
|
||||
}
|
||||
@@ -1209,7 +1211,6 @@ void OBCameraNode::saveImageToFile(const stream_index_pair &stream_index, const
|
||||
} else {
|
||||
RCLCPP_ERROR_STREAM(logger_, "Unsupported stream type: " << stream_index.first);
|
||||
}
|
||||
save_images_[stream_index] = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -645,6 +645,7 @@ void OBCameraNode::saveImageCallback(const std::shared_ptr<std_srvs::srv::Empty:
|
||||
for (const auto& stream_index : IMAGE_STREAMS) {
|
||||
if (enable_stream_[stream_index]) {
|
||||
save_images_[stream_index] = true;
|
||||
save_images_count_[stream_index] = 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user