update cloud reprojection node to sync image+cloud, looks sync good
This commit is contained in:
@@ -17,22 +17,20 @@ limitations under the License.
|
||||
#include <rclcpp/rclcpp.hpp>
|
||||
#include <sensor_msgs/msg/point_cloud2.hpp>
|
||||
#include <sensor_msgs/msg/image.hpp>
|
||||
#include <sensor_msgs/msg/compressed_image.hpp>
|
||||
#include <nav_msgs/msg/odometry.hpp>
|
||||
#include <image_transport/image_transport.hpp>
|
||||
#include <cv_bridge/cv_bridge.h>
|
||||
#include <message_filters/subscriber.h>
|
||||
#include <message_filters/time_synchronizer.h>
|
||||
#include <message_filters/sync_policies/exact_time.h>
|
||||
#include <message_filters/sync_policies/approximate_time.h>
|
||||
#else
|
||||
#include <ros/ros.h>
|
||||
#include <sensor_msgs/PointCloud2.h>
|
||||
#include <sensor_msgs/Image.h>
|
||||
#include <sensor_msgs/CompressedImage.h>
|
||||
#include <nav_msgs/Odometry.h>
|
||||
#include <cv_bridge/cv_bridge.h>
|
||||
#include <message_filters/subscriber.h>
|
||||
#include <message_filters/time_synchronizer.h>
|
||||
#include <message_filters/sync_policies/exact_time.h>
|
||||
#include <message_filters/sync_policies/approximate_time.h>
|
||||
#endif
|
||||
|
||||
@@ -55,28 +53,46 @@ private:
|
||||
using PointCloud2 = sensor_msgs::msg::PointCloud2;
|
||||
using Odometry = nav_msgs::msg::Odometry;
|
||||
using Image = sensor_msgs::msg::Image;
|
||||
using CompressedImage = sensor_msgs::msg::CompressedImage;
|
||||
|
||||
std::string cloud_slam_topic_;
|
||||
std::string odometry_topic_;
|
||||
std::string wiwc_topic_;
|
||||
std::string camera_image_topic_;
|
||||
std::string sync_topic_prefix_;
|
||||
std::string reprojected_image_topic_;
|
||||
std::string combined_compressed_topic_;
|
||||
int combined_jpeg_quality_;
|
||||
|
||||
message_filters::Subscriber<PointCloud2> cloud_sub_;
|
||||
message_filters::Subscriber<Odometry> odom_sub_;
|
||||
message_filters::Subscriber<Odometry> wiwc_sub_;
|
||||
message_filters::Subscriber<CompressedImage> image_compressed_sub_;
|
||||
|
||||
typedef message_filters::sync_policies::ApproximateTime<PointCloud2, Odometry, Odometry> MySyncPolicy;
|
||||
typedef message_filters::sync_policies::ApproximateTime<PointCloud2, Odometry, Odometry, CompressedImage> MySyncPolicy;
|
||||
typedef message_filters::Synchronizer<MySyncPolicy> Sync;
|
||||
std::shared_ptr<Sync> sync_;
|
||||
|
||||
std::string sync_cloud_topic_;
|
||||
std::string sync_odom_topic_;
|
||||
std::string sync_wiwc_topic_;
|
||||
std::string sync_image_topic_;
|
||||
|
||||
rclcpp::Publisher<PointCloud2>::SharedPtr sync_cloud_pub_;
|
||||
rclcpp::Publisher<Odometry>::SharedPtr sync_odom_pub_;
|
||||
rclcpp::Publisher<Odometry>::SharedPtr sync_wiwc_pub_;
|
||||
rclcpp::Publisher<CompressedImage>::SharedPtr sync_image_pub_;
|
||||
|
||||
image_transport::Publisher reprojected_image_pub_;
|
||||
rclcpp::Publisher<CompressedImage>::SharedPtr combined_pub_;
|
||||
|
||||
std::unique_ptr<CloudReprojector> reprojector_;
|
||||
|
||||
void loadParameters();
|
||||
void syncCallback(const PointCloud2::ConstSharedPtr& cloud_msg,
|
||||
const Odometry::ConstSharedPtr& odom_msg,
|
||||
const Odometry::ConstSharedPtr& wiwc_msg);
|
||||
const Odometry::ConstSharedPtr& wiwc_msg,
|
||||
const CompressedImage::ConstSharedPtr& image_compressed_msg);
|
||||
};
|
||||
#else
|
||||
class CloudReprojectionRosNode
|
||||
@@ -90,23 +106,41 @@ private:
|
||||
std::string cloud_slam_topic_;
|
||||
std::string odometry_topic_;
|
||||
std::string wiwc_topic_;
|
||||
std::string camera_image_topic_;
|
||||
std::string sync_topic_prefix_;
|
||||
std::string reprojected_image_topic_;
|
||||
std::string combined_compressed_topic_;
|
||||
int combined_jpeg_quality_;
|
||||
|
||||
std::string sync_cloud_topic_;
|
||||
std::string sync_odom_topic_;
|
||||
std::string sync_wiwc_topic_;
|
||||
std::string sync_image_topic_;
|
||||
|
||||
message_filters::Subscriber<sensor_msgs::PointCloud2> cloud_sub_;
|
||||
message_filters::Subscriber<nav_msgs::Odometry> odom_sub_;
|
||||
message_filters::Subscriber<nav_msgs::Odometry> wiwc_sub_;
|
||||
message_filters::Subscriber<sensor_msgs::CompressedImage> image_compressed_sub_;
|
||||
|
||||
typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::PointCloud2, nav_msgs::Odometry, nav_msgs::Odometry> MySyncPolicy;
|
||||
typedef message_filters::sync_policies::ApproximateTime<
|
||||
sensor_msgs::PointCloud2, nav_msgs::Odometry, nav_msgs::Odometry, sensor_msgs::CompressedImage> MySyncPolicy;
|
||||
typedef message_filters::Synchronizer<MySyncPolicy> Sync;
|
||||
std::shared_ptr<Sync> sync_;
|
||||
|
||||
ros::Publisher sync_cloud_pub_;
|
||||
ros::Publisher sync_odom_pub_;
|
||||
ros::Publisher sync_wiwc_pub_;
|
||||
ros::Publisher sync_image_pub_; // CompressedImage
|
||||
|
||||
ros::Publisher reprojected_image_pub_;
|
||||
ros::Publisher combined_pub_;
|
||||
|
||||
std::unique_ptr<CloudReprojector> reprojector_;
|
||||
|
||||
void loadParameters();
|
||||
void syncCallback(const sensor_msgs::PointCloud2ConstPtr& cloud_msg,
|
||||
const nav_msgs::OdometryConstPtr& odom_msg,
|
||||
const nav_msgs::OdometryConstPtr& wiwc_msg);
|
||||
const nav_msgs::OdometryConstPtr& wiwc_msg,
|
||||
const sensor_msgs::CompressedImageConstPtr& image_compressed_msg);
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -57,6 +57,10 @@ public:
|
||||
cv::Mat reprojectCloud(const pcl::PointCloud<pcl::PointXYZRGB>& cloud_odom,
|
||||
const OdomPose& odom_pose);
|
||||
|
||||
/** Same transform as reprojectCloud, but draw points using camera-frame depth z (grayscale) instead of RGB. */
|
||||
cv::Mat reprojectCloudDepth(const pcl::PointCloud<pcl::PointXYZRGB>& cloud_odom,
|
||||
const OdomPose& odom_pose);
|
||||
|
||||
void setPointRadius(int radius) { point_radius_ = radius; }
|
||||
int getPointRadius() const { return point_radius_; }
|
||||
|
||||
@@ -76,6 +80,7 @@ private:
|
||||
Eigen::Matrix4d odomPoseToMatrix(const OdomPose& odom) const;
|
||||
|
||||
cv::Mat projectCloudToImage(const pcl::PointCloud<pcl::PointXYZRGB>& cloud_in_cam) const;
|
||||
cv::Mat projectCloudToImageDepth(const pcl::PointCloud<pcl::PointXYZRGB>& cloud_in_cam) const;
|
||||
|
||||
CameraParams camera_params_;
|
||||
ExtrinsicParams extrinsic_params_;
|
||||
|
||||
@@ -16,15 +16,14 @@ limitations under the License.
|
||||
#ifdef ROS2
|
||||
#include <rclcpp/rclcpp.hpp>
|
||||
#include <sensor_msgs/msg/image.hpp>
|
||||
#include <sensor_msgs/msg/compressed_image.hpp>
|
||||
#include <cv_bridge/cv_bridge.h>
|
||||
#include <mutex>
|
||||
#else
|
||||
#include <ros/ros.h>
|
||||
#include <sensor_msgs/Image.h>
|
||||
#include <sensor_msgs/CompressedImage.h>
|
||||
#include <cv_bridge/cv_bridge.h>
|
||||
#include <message_filters/subscriber.h>
|
||||
#include <message_filters/sync_policies/approximate_time.h>
|
||||
#include <message_filters/synchronizer.h>
|
||||
#endif
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
@@ -39,25 +38,26 @@ public:
|
||||
|
||||
private:
|
||||
using Image = sensor_msgs::msg::Image;
|
||||
using CompressedImage = sensor_msgs::msg::CompressedImage;
|
||||
|
||||
std::string reprojected_topic_;
|
||||
std::string camera_topic_;
|
||||
std::string overlay_topic_;
|
||||
double alpha_; // blend alpha for overlay
|
||||
std::string output_topic_;
|
||||
int jpeg_quality_;
|
||||
|
||||
rclcpp::Subscription<Image>::SharedPtr reproj_sub_;
|
||||
rclcpp::Subscription<Image>::SharedPtr camera_sub_;
|
||||
rclcpp::Publisher<Image>::SharedPtr overlay_pub_;
|
||||
rclcpp::Publisher<CompressedImage>::SharedPtr combined_pub_;
|
||||
|
||||
// Cache latest images
|
||||
cv::Mat latest_reproj_img_;
|
||||
cv::Mat latest_camera_img_;
|
||||
std_msgs::msg::Header latest_header_;
|
||||
std_msgs::msg::Header latest_reproj_header_;
|
||||
std_msgs::msg::Header latest_camera_header_;
|
||||
std::mutex mutex_;
|
||||
|
||||
void reprojCallback(const Image::ConstSharedPtr& msg);
|
||||
void cameraCallback(const Image::ConstSharedPtr& msg);
|
||||
void publishOverlay();
|
||||
void publishHcatCompressed();
|
||||
};
|
||||
#else
|
||||
#include <mutex>
|
||||
@@ -71,21 +71,21 @@ private:
|
||||
|
||||
std::string reprojected_topic_;
|
||||
std::string camera_topic_;
|
||||
std::string overlay_topic_;
|
||||
double alpha_; // blend alpha for overlay
|
||||
std::string output_topic_;
|
||||
int jpeg_quality_;
|
||||
|
||||
ros::Subscriber reproj_sub_;
|
||||
ros::Subscriber camera_sub_;
|
||||
ros::Publisher overlay_pub_;
|
||||
ros::Publisher combined_pub_;
|
||||
|
||||
// Cache latest images
|
||||
cv::Mat latest_reproj_img_;
|
||||
cv::Mat latest_camera_img_;
|
||||
std_msgs::Header latest_header_;
|
||||
std_msgs::Header latest_reproj_header_;
|
||||
std_msgs::Header latest_camera_header_;
|
||||
std::mutex mutex_;
|
||||
|
||||
void reprojCallback(const sensor_msgs::ImageConstPtr& msg);
|
||||
void cameraCallback(const sensor_msgs::ImageConstPtr& msg);
|
||||
void publishOverlay();
|
||||
void publishHcatCompressed();
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user