PCD viewer problem for Object Detection using Kinect
I am working on object detection using ROS-PCL. Using a Kinect camera I save point clouds generated by the following code in a .pcd file. My problem is that I am unable to see the object as a point cloud in the PCD file viewer. Is the code a problem? It generates a PCD file but I do not know if it works on giving a proper point cloud in .pcd. I just obtain a straight line of points in the middle of the PCD viewer for all objects. Please help.
#include <ros/ros.h>
#include <pcl_ros/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <boost/foreach.hpp>
pcl::PointCloud<pcl::PointXYZRGB> PC;
void callback(const sensor_msgs::PointCloud2ConstPtr& msg)
{
printf("Writing the file...\n");
pcl::fromROSMsg(*msg, PC);
int a = pcl::io::savePCDFileBinary"/home/rootx/pcl_proj/pcd/temp.pcd", PC);
printf("Saved the pcd file...%d Return %d\n", PC.points.size(), a);
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "sub_pcl");
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscrib<sensor_msgs::PointCloud2>("points2", 1, callback);
ros::spin();
}
I tried this command to view pcd file pcd_viewer: rosrun perception_pcl pcd_viewer "filename"
Edit: Using pcl::PointCloud<pcl::pointxyzrgba> PC; instead of the statement used in the code, as suggested, gives an error: terminate called after throwing an instance of 'pcl::InvalidConversionException' what(): Failed to find a field named: 'rgba'. Cannot convert message to PCL type. Aborted.
Does it need a header file I haven't added perhaps?