Exception thrown when deserializing message of length [453372] from [/my_filter]: std::bad_alloc
Hello,
I am trying to publish PCL point clouds which are obtained from velodyne point cloud. The program is compiled and running. I can even see the height and width information from the PCL point clouds but when I open RVIZ and visualize the published PCL point clouds, I get this message.
[ERROR] [1602489936.969819842]: Exception thrown when deserializing message of length [453372] from [/my_filter]: std::bad_alloc
ros::Publisher ptc_pub;
void callback(const ImageConstPtr& image, const PointCloud2ConstPtr& pt_cloud)
{
pcl::PointCloud<pcl::PointXYZ> pcl_cloud;
pcl::fromROSMsg(*pt_cloud, pcl_cloud);
int PCLwidth = pcl_cloud.width;
int PCLheight = pcl_cloud.height;
cout<< "width = "<<PCLwidth <<endl;
cout<< "height"<<PCLheight <<endl;
ptc_pub.publish(pcl_cloud);
// ros::spinOnce();
// loop_rate.sleep();
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "my_filter");
ros::NodeHandle node_;
ros::Publisher ptc_pub = node_.advertise<PointCloud>("pcl_pts", 1);
// ros::Rate loop_rate(10);
message_filters::Subscriber<Image> img_sub(node_, "cam_1/color/image_raw", 1);
message_filters::Subscriber<PointCloud2> pointcloud_sub(node_, "velodyne_points", 1);
typedef sync_policies::ApproximateTime<Image, PointCloud2> MySyncPolicy;
Synchronizer<MySyncPolicy> sync(MySyncPolicy(10),img_sub, pointcloud_sub);
sync.registerCallback(boost::bind(&callback, _1,_2));
ros::spin();
return 0;
}
What I am doing wrong ? My guess is that I have placed the publisher wrong or is it something else ? I am new to ROS and cpp. Any suggestion will be really useful.
Thanks.