0
$\begingroup$

Rosanswers logo

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


Originally posted by DavidLavy on ROS Answers with karma: 139 on 2012-05-03

Post score: 0


Original comments

Comment by Mac on 2012-08-09:
...the output is an image? You're publishing a PointCloud2. That's not an Image. Is there a typo in your question?

Comment by lfelipesv on 2014-01-28:
I'm with this problem now, someone know the answer?

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

'Formats' are not compatible.

  • Format 1: cvArr requires the first 4 bytes to determine what data the matrix (or rather a cvMat object) would have. The 1st four bytes contain a rather important datatype information like CV_32FC1, CV_8UC1. Also, OpenCV is rather sensitive to RBG, BGR. Your error is caused since the first 4 bytes are of nothing OpenCV can understand

  • Format 2: image_view takes image parameter, BUT that is a topic, not a file

So, OpenCV is saying it can't understand whatever you are trying to do, but the actual error lies in the fact that you are subscribed to an empty topic.


Originally posted by kunaltyagi with karma: 105 on 2014-10-05

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.