OpenCV error using PCL + ROS + Kinect
Hi,
I'm working with PCL, ROS to use my kinect, I got an error when I use the following code:
#include <pcl/point_types.h> #include <pcl/filters/voxel_grid.h> #include <pcl_ros/point_cloud.h> #include <ros/ros.h> #include <boost/foreach.hpp> #include <sensor_msgs/PointCloud2.h> #include <pcl/io/pcd_io.h>
using namespace std; ros::Publisher pub; typedef pcl::PointXYZRGB rgbpoint; typedef pcl::PointCloud<pcl::PointXYZRGB> cloudrgb; typedef cloudrgb::Ptr cloudrgbptr; void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud) { cloudrgbptr PC (new cloudrgb()); cloudrgbptr PC_filtered (new cloudrgb()); pcl::fromROSMsg(*cloud, *PC); //Now you can process this PC using the pcl functions sensor_msgs::PointCloud2 cloud_filtered;
// Perform the actual filtering pcl::VoxelGrid<pcl::PointXYZRGB> sor ; sor.setInputCloud (PC); sor.setLeafSize (0.01, 0.01, 0.01); sor.filter (*PC_filtered);
//Convert the pcl cloud back to rosmsg pcl::toROSMsg(PC_filtered, cloud_filtered); //Set the header of the cloud cloud_filtered.header.frame_id = cloud->header.frame_id; // Publish the data //You may have to set the header frame id of the cloud_filtered also pub.publish (cloud_filtered); } int main(int argc, char * argv) { ros::init(argc, argv, "test_pcl_ros"); ros::NodeHandle nh; ros::Subscriber sub = nh.subscribe("camera/rgb/points", 1, cloud_cb); pub = nh.advertise<sensor_msgs::PointCloud2> ("/camera/rgb/david", 1); ros::spin(); }
And use the following commands:
$ roscore
$ rosrun openni_camera openni_node
$ rosrun my_pcl_test run_test input:=/camera/rgb/points
$ rosrun pcl_ros convert_pointcloud_to_image input:=/camera/rgb/david output:=/camera/rgb/david_img
Until that line everything works fine,the output is published as a Type: sensor_msgs/Image, but then I want to output the image in a window doing:
$ rosrun image_view image_view image:=/camera/rgb/david_img
I get this error:
OpenCV Error: Bad argument (Unknown array type) in cvarrToMat, file /tmp/buildd/libopencv-2.3.1+svn6514+branch23/modules/core/src/matrix.cpp, line 646 terminate called after throwing an instance of 'cv::Exception' what(): /tmp/buildd/libopencv-2.3.1+svn6514+branch23/modules/core/src/matrix.cpp:646: error: (-5) Unknown array type in function cvarrToMat
Any clue why is this happening, thanks in advance!
David
...the output is an image? You're publishing a PointCloud2. That's not an Image. Is there a typo in your question?
I'm with this problem now, someone know the answer?