ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

kinect + pcl visualizer + ros, memory overflow problem

asked 2012-09-19 23:37:41 -0500

Luis Parra gravatar image

updated 2016-10-24 09:02:34 -0500

ngrennan gravatar image

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?

edit retag flag offensive close merge delete

Comments

@dejanpan oh great. I thought that was rate not buffer 2000 mseconds.. I will reduce the number and try again.

Luis Parra gravatar image Luis Parra  ( 2012-09-20 21:01:01 -0500 )edit

@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!!.

Luis Parra gravatar image Luis Parra  ( 2012-09-20 21:40:20 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2012-09-20 12:09:52 -0500

dejanpan gravatar image

I would certainly not buffer 2000 point clouds, but rather 10 or so.

edit flag offensive delete link more
0

answered 2012-09-20 01:59:26 -0500

Flowers gravatar image

Easy way to find it is to call printf() in every function and let it print a function-related string(like "main while loop")...if you repeat that step you'll finally find the line of code that results in the error an can ask for further help.

First guess:

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(); }

ensure removePointCloud() gives the memory free...maybe check there for the mistake...

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-09-19 23:37:41 -0500

Seen: 2,227 times

Last updated: Sep 20 '12