0
$\begingroup$

Rosanswers logo

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?


Originally posted by Luis Parra on ROS Answers with karma: 11 on 2012-09-19

Post score: 0


Original comments

Comment by Luis Parra on 2012-09-20:
@dejanpan oh great. I thought that was rate not buffer 2000 mseconds.. I will reduce the number and try again.

Comment by Luis Parra on 2012-09-20:
@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!!.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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


Originally posted by dejanpan with karma: 1420 on 2012-09-20

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.