Ask Your Question

Regarding Publishing Kinect Depth Image

asked 2012-12-06 23:42:21 -0500

Subhasis gravatar image

updated 2014-04-20 14:09:26 -0500

ngrennan gravatar image

Hi All,

I have kinect Depth image as mentioned below. I am trying to publish this from my node. I am having problem in converting my image to buffer which is needed to send it as a message. Please find below my code. I would be glad if somecan guide where I am doing a mistake.


image_transport::Publisher publisher_depth = it.advertise("kinectcamera/depth", 1);

kinectDepthImage = cvCreateImage( cvSize(640,480),IPL_DEPTH_16U,1);
here I store the image from Kinect
cvShowImage("Depth", kinectDepthImage); // This shows me fine the image. I have no issue.

//Now I try to publish it i any of the two ways And this is where It fails.

 cv::WImageBuffer_16u depthBufer(kinectDepthImage); 
 cv::WImageBuffer1_16u depthBufer(kinectDepthImage);

sensor_msgs::ImagePtr depth_msg = sensor_msgs::CvBridge::cvToImgMsg(depthBufer.Ipl(), "mono16");


my error is " /opt/ros/fuerte/include/opencv2/core/wimage.hpp:243: cv::WImage<T>::WImage(IplImage*) [with T = short unsigned int, IplImage = _IplImage]: Assertion `!img || img->depth == Depth()' failed.
pass1Aborted (core dumped) "

Please help me with this.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2012-12-07 12:56:54 -0500

I'm not sure why it's failing and whether this would make a difference, but have you tried using the C++ API for OpenCV?

image_transport::Publisher publisher_depth = it.advertise("kinectcamera/depth", 1);

// create image
cv::Mat kinectDepthImage = cv::Mat(480, 640, CV_16UC1);

// fill out image - for example
for (int u = 0; u < 640; ++u)
for (int v = 0; v < 480; ++v)<uint16_t>(v,u) = some value here;

sensor_msgs::ImagePtr depth_msg = sensor_msgs::CvBridge::cvToImgMsg(kinectDepthImage);
edit flag offensive delete link more

answered 2012-12-07 18:35:20 -0500

Well, according to the error message it is either:

depthBufer.Ipl() is returning null


depthBufer.Ipl()->depth != "mono16"

Could you check those values? Although at first glance I see nothing wrong with your code.

edit flag offensive delete link more

answered 2012-12-12 09:34:19 -0500

Subhasis gravatar image

Hi Martin,

Thanks for replying. But, I already verified the depth. it says 16. which refers to the correct depth and should point to mono16. Can you provide any other solution to this problem ?

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


Asked: 2012-12-06 23:42:21 -0500

Seen: 892 times

Last updated: Dec 12 '12