kinect + pcl visualizer + ros, memory overflow problem
Hello
I'm trying to get a pointcloud2 message from the kinect and visualize it using pcl visualizer class, for this I have done the following (forgive the global variables,it's just a test):
#include <iostream>
#include <cstdlib>
// ROS
#include <ros/ros.h>
// PCL
#include <pcl/ros/conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/visualization/pcl_visualizer.h>
boost::shared_ptr<pcl::visualization::PCLVisualizer> visor;
pcl::PointCloud<pcl::PointXYZRGB>::Ptr ptCloud (new pcl::PointCloud<pcl::PointXYZRGB>);
sensor_msgs::PointCloud2 cloud;
boost::shared_ptr<pcl::visualization::PCLVisualizer> createVis ()
{
// --------------------------------------------
// -----Open 3D viewer and add properties-----
// --------------------------------------------
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
viewer->setBackgroundColor (0, 0, 0);
viewer->addCoordinateSystem (1.0);
viewer->initCameraParameters ();
return viewer;
}
void updateVis(boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer, pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr cloud){
pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(cloud);
viewer->removePointCloud();
viewer->addPointCloud<pcl::PointXYZRGB> (cloud, rgb);
viewer->spinOnce();
}
void showPCL(sensor_msgs::PointCloud2 points){
cloud = points;
pcl::fromROSMsg<pcl::PointXYZRGB>(cloud, *(ptCloud.get()));
updateVis(visor, ptCloud);
}
/**
*/
int main(int argc, char **argv) {
using namespace ros;
visor = createVis();
init(argc,argv,"kinQual");
NodeHandle nh;
Subscriber subDepth = nh.subscribe<>("camera/depth_registered/points",2000,showPCL);
while(!visor->wasStopped()){
sleep(1);
spin();
}
return 0;
}
but whenever I run it after watching a bit of the pointcloud, I get an awful message:
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted (core dumped)
It seems to be a pointer or memory that gets overflow, so I need to delete it, but where?
@dejanpan oh great. I thought that was rate not buffer 2000 mseconds.. I will reduce the number and try again.
@dejanpan, it happens that you were right, it overflowed with 2000 cloud points, if you post it as answer Ill give it to you. Thanks a lot!!.