Ask Your Question
0

OpenCV error using PCL + ROS + Kinect

asked 2012-05-03 09:11:14 -0500

DavidLavy gravatar image

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

edit retag flag offensive close merge delete

Comments

1

...the output is an image? You're publishing a PointCloud2. That's not an Image. Is there a typo in your question?

Mac gravatar image Mac  ( 2012-08-09 22:26:12 -0500 )edit

I'm with this problem now, someone know the answer?

lfelipesv gravatar image lfelipesv  ( 2014-01-27 23:59:11 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-10-05 16:20:23 -0500

kunaltyagi gravatar image

updated 2014-10-05 16:21:12 -0500

'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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-05-03 09:11:14 -0500

Seen: 885 times

Last updated: Oct 05 '14