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

publish point cloud xyz

asked 2015-03-27 19:45:15 -0600

dmngu9 gravatar image

updated 2015-03-27 22:35:02 -0600

l0g1x gravatar image

i wrote a ros node for kinect pointcloud 2 to pass through filter and publish it to a topic. But when i run the node, it give me this error

/usr/include/boost/smart_ptr/shared_ptr.hpp:646: typename boost::detail::sp_dereference<t>::type boost::shared_ptr<t>::operator*() const [with T = pcl::PointCloud<pcl::pointxyz>; typename boost::detail::sp_dereference<t>::type = pcl::PointCloud<pcl::pointxyz>&]: Assertion `px != 0' failed. Aborted (core dumped)

I cant seem to fix this problem. please help

class Listener
{

public:

    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_passthrough;

    void callback(const sensor_msgs::PointCloud2ConstPtr& kinect_output);

};
// end class

void Listener::callback(const sensor_msgs::PointCloud2ConstPtr& kinect_output)
{
    pcl::PCLPointCloud2::Ptr pc2 (new pcl::PCLPointCloud2());

    pcl_conversions::toPCL (*kinect_output, *pc2);

    pcl::PCLPointCloud2::Ptr cloud_filtered (new pcl::PCLPointCloud2 ());

    pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
    sor.setInputCloud (pc2);
    sor.setLeafSize(0.01f,0.01f,0.01f);
    sor.filter(*cloud_filtered);// filter the point cloud
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloudXYZ (new pcl::PointCloud<pcl::PointXYZ>);//object cloud for point cloud type XYZ
    pcl::fromPCLPointCloud2(*cloud_filtered,*cloudXYZ);

    //create passthrough filter object
    pcl::PassThrough<pcl::PointXYZ> pass;
    pass.setInputCloud (cloudXYZ);
    pass.setFilterFieldName("z");
    pass.setFilterLimits(0.5, 1.5);
    pass.filter(*cloud_passthrough);
}

int main (int argc, char **argv)
{
    ros::init (argc, argv, "PointCloud2_to_pointCloudXYZ");

    ros::NodeHandle nh;

    Listener listener;

    ros::Publisher pub = nh.advertise<pcl::PointCloud<pcl::PointXYZ> >("/filtered", 1000);
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
    cloud -> points = listener.cloud_passthrough->points;
    ros::Rate loop_rate(10);    
    ros::Subscriber sub = nh.subscribe <sensor_msgs::PointCloud2> ("/camera/depth/points",1000,&Listener::callback, &listener);
    while (ros::ok())
    {
        pub.publish (cloud);
        ros::spinOnce();
        loop_rate.sleep();
    }//end while loop   
    return 0;
}//end main
edit retag flag offensive close merge delete

Comments

Must be the intraprocesd in node. How can i go about it?

dmngu9 gravatar image dmngu9  ( 2015-03-27 23:30:22 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
9

answered 2015-03-29 13:08:11 -0600

ahendrix gravatar image

Assertion 'px != 0' failed. means that you're using a boost::shared_ptr before it's initialized somewhere.

In particular, I notice that you're not initializing cloud_passthrough anywhere. You should probably write a constructor for your Listener class and initialize it there.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-03-27 19:45:15 -0600

Seen: 9,925 times

Last updated: Mar 29 '15