ROS中点云数据的叠加处理

在我们处理点云数据的时候,我们经常会对点云的数据进行累加到一起在进行操作,也就是将几帧数据叠加为一个数据在进行处理,这在低线束的情况下是经常用到的,具体的操作过程如下:

class object3dDetector {
  /*************Publish And  Subcriber*************/
private:
    ros::NodeHandle n;
    ros::Subscriber point_date_sub;
    ros::Publisher raw_point_pub;
    sensor_msgs::PointCloud2 raw_point;

public:
    object3dDetector() {
//     ----------------------sub and scrb defination----------------------
        point_date_sub = n.subscribe("/livox/lidar", 3, &object3dDetector::callback, this);
        raw_point_pub = n.advertise<sensor_msgs::PointCloud2>("/raw_Point", 3);
    }
    void getpoint_callback(const sensor_msgs::PointCloud2::ConstPtr &livox_msg);
    void callback(const sensor_msgs::PointCloud2::ConstPtr &msg);
};
int i=1;//一定要放在回调函数外.
pcl::PointCloud<pcl::PointXYZ>::Ptr temp_cloud(new pcl::PointCloud<pcl::PointXYZ>);

void object3dDetector::callback(const sensor_msgs::PointCloud2::ConstPtr &msg) {
    cout << "msg:" << (msg->height) * (msg->width) << endl;
    auto startTime = std::chrono::steady_clock::now();
    //累计数据
    if (i < 3) {
        pcl::PointCloud<pcl::PointXYZ>::Ptr transfer_cloud(new pcl::PointCloud<pcl::PointXYZ>);
        pcl::fromROSMsg(*msg, *transfer_cloud);
        *temp_cloud += *transfer_cloud;
//        cout<<"COUNT POINTS_NUM[:"<<i<<"]:"<<temp_cloud->points.size()<<endl;
        i++;
    } else {

        pcl::PointCloud<pcl::PointXYZ>::Ptr transfer_cloud(new pcl::PointCloud<pcl::PointXYZ>);
        pcl::fromROSMsg(*msg, *transfer_cloud);
        *temp_cloud += *transfer_cloud;
        pcl::toROSMsg(*temp_cloud, raw_point);
        *********todo****************
   i=1;
temp_cloud->clear();//清除点云数据,进行下一次累计.
}
}
int main(int argc, char **argv) {
t << "------------------DO it!-----------------------" << endl;
    ros::init(argc, argv, "object3d_detector");

    object3dDetector A;
    ros::spin();
    }

到此就可以了.

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐