#include <iostream> #include <fstream> #include <numeric> #include <regex> #include…
- User
#include #include #include #include #include #include #include <opencv2/core.hpp> #include <opencv2/highgui.hpp> #include <opencv2/imgproc.hpp> #include <rclcpp/rclcpp.hpp> #include <sensor_msgs/msg/point_cloud2.hpp> // For publishing LiDAR points #include <sensor_msgs/msg/image.hpp> // For publishing camera images #include #include <std_msgs/msg/string.hpp> #include <opencv2/opencv.hpp>
struct LidarPoint { // single lidar point in space float x,y,z,r; };
using namespace std; std::thread cameraLidarProjectionThread; std::mutex imageMutex; std::mutex pointMutex; bool img, poi; rclcpp::Publisher<sensor_msgs::msg::Image>::SharedPtr publisher; cv::Mat image; std::vector lidarPoints; // store calibration data in OpenCV matrices cv::Mat P_rect_00(3, 4, cv::DataType::type); // 3x4 projection matrix after rectification cv::Mat R_rect_00(4, 4, cv::DataType::type); // 3x3 rectifying rotation to make image planes co-planar cv::Mat RT(4, 4, cv::DataType::type); // rotation matrix and translation vector
void loadCalibrationData(cv::Mat &P_rect_00, cv::Mat &R_rect_00, cv::Mat &RT) { RT.at(0, 0) = 7.533745e-03; RT.at(0, 1) = -9.999714e-01; RT.at(0, 2) = -6.166020e-04; RT.at(0, 3) = -4.069766e-03; RT.at(1, 0) = 1.480249e-02; RT.at(1, 1) = 7.280733e-04; RT.at(1, 2) = -9.998902e-01; RT.at(1, 3) = -7.631618e-02; RT.at(2, 0) = 9.998621e-01; RT.at(2, 1) = 7.523790e-03; RT.at(2, 2) = 1.480755e-02; RT.at(2, 3) = -2.717806e-01; RT.at(3, 0) = 0.0; RT.at(3, 1) = 0.0; RT.at(3, 2) = 0.0; RT.at(3, 3) = 1.0;
codeR_rect_00.at<double>(0, 0) = 9.999239e-01; R_rect_00.at<double>(0, 1) = 9.837760e-03; R_rect_00.at<double>(0, 2) = -7.445048e-03; R_rect_00.at<double>(0, 3) = 0.0; R_rect_00.at<double>(1, 0) = -9.869795e-03; R_rect_00.at<double>(1, 1) = 9.999421e-01; R_rect_00.at<double>(1, 2) = -4.278459e-03; R_rect_00.at<double>(1, 3) = 0.0; R_rect_00.at<double>(2, 0) = 7.402527e-03; R_rect_00.at<double>(2, 1) = 4.351614e-03; R_rect_00.at<double>(2, 2) = 9.999631e-01; R_rect_00.at<double>(2, 3) = 0.0; R_rect_00.at<double>(3, 0) = 0; R_rect_00.at<double>(3, 1) = 0; R_rect_00.at<double>(3, 2) = 0; R_rect_00.at<double>(3, 3) = 1; P_rect_00.at<double>(0, 0) = 7.215377e+02; P_rect_00.at<double>(0, 1) = 0.000000e+00; P_rect_00.at<double>(0, 2) = 6.095593e+02; P_rect_00.at<double>(0, 3) = 0.000000e+00; P_rect_00.at<double>(1, 0) = 0.000000e+00; P_rect_00.at<double>(1, 1) = 7.215377e+02; P_rect_00.at<double>(1, 2) = 1.728540e+02; P_rect_00.at<double>(1, 3) = 0.000000e+00; P_rect_00.at<double>(2, 0) = 0.000000e+00; P_rect_00.at<double>(2, 1) = 0.000000e+00; P_rect_00.at<double>(2, 2) = 1.000000e+00; P_rect_00.at<double>(2, 3) = 0.000000e+00; - Assistant
- User
explain the projection logic in detail
- Assistant
- User
explain the process of subscribing and projection in different steps with titles, elaborate
- Assistant
- User
explain the process of subscribing and projection in different steps with titles, elaborate more in words less in code
- Assistant
- User
give a general overview in 100 words
- Assistant
The provided code sets up a ROS2 node for subscribing to camera images and LiDAR point cloud data, then projects the LiDAR points onto the camera images. Calibration matrices are loaded to transform 3D LiDAR coordinates to 2D image pixels. Separate threads handle image and point cloud callbacks, storing new data in global variables with mutex locks for thread safety. The projection thread checks for new data, applies the transformation, creates a blended overlay of the LiDAR points on the image, and publishes the result as a new ROS2 image message, enabling real-time sensor fusion visualization.