Segmentation fault in Point-cloud-library PCL visualizer

Shishir P Rao Source

I am trying to generate a point cloud from disparity map obtained from SGBM method. I have the RGB image, the disparity image, Q matrix stored in an XML file. I am using the code given in this blog. When I execute the code obtained from the blog with the supplied images and Q matrix I am getting segmentation fault. I am including the code segment which I feel is causing the segmentation fault.

//This function creates a PCL visualizer, sets the point cloud to view and returns a pointer
boost::shared_ptr<pcl::visualization::PCLVisualizer> createVisualizer (pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr cloud)
{
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
viewer->setBackgroundColor (0, 0, 0);
pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(cloud);
viewer->addPointCloud<pcl::PointXYZRGB> (cloud, rgb, "reconstruction");
viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "reconstruction");
viewer->addCoordinateSystem ( 1.0 );
viewer->initCameraParameters ();
return (viewer);
}

When I comment out this section and the call to this function is made in the main program there is no error. The function call used in the main function is given below.

 point_cloud_ptr->width = (int) point_cloud_ptr->points.size();
 point_cloud_ptr->height = 1;
//Create visualizer // Two lines below is the function call
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer;
viewer = createVisualizer( point_cloud_ptr );
//Main loop
while ( !viewer->wasStopped())
{
 viewer->spinOnce(100);
 boost::this_thread::sleep (boost::posix_time::microseconds (100000));
}

Just for ref the pastebin link to full code is here

c++opencvsegmentation-faultcomputer-visionpoint-cloud-library

Answers

answered 3 years ago Shishir P Rao #1

I found out the problem. It was with the version of OpenCV. I went back to Opencv 2.4.9 and it worked like charm.

Now I'm using Ubuntu 14.04 + OpenCV 2.4.9 + Latest Version of PCL

Appreciate all the help. Thank you.

comments powered by Disqus