How can I get depth data from Kinect?
Hi guys, I'm quite new to ROS. I'm using the Ubuntu 12.04 and openni driver.
What I've been trying to do is to use Kinect to detect whether a door is open or closed. My idea is to write a node to subscribe to camera/depth/image
, and and can retrieve a distance at the center point in the image.
But when I use rostopic echo camera/depth/image
I just get a lot of numbers like 0, 0, 65, 128, 36, 56, 77, 102, 140, 65
.
So does anyone know what should I do with these numbers, or are there other ways to get depth data?
Firstly, thank Martin Günther's answer, it really help me a lot. And I already solve the problem by using OpenCV. Here is part of my code, it's very easy. If some beginners cannot understand that hackish solution, maybe you should try this one:
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include ..........
namespace enc = sensor_msgs::image_encodings;
void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
cv_bridge::CvImagePtr cv_ptr;
try
{
cv_ptr = cv_bridge::toCvCopy(msg, enc::TYPE_16UC1);//now cv_ptr is the matrix, do not forget "TYPE_" before "16UC1"
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("cv_bridge exception: %s", e.what());
return;
}
int depth = cv_ptr->image.at<short int>(cv::Point(240,320));//you can change 240,320 to your interested pixel
ROS_INFO("Depth: %d", depth);
}
int main(int argc, char **argv)
{.........}
Hello, thanks for updating your solution here. It is quite easy to understand. But I have a question. Is there any quick solution to get the minimum depth of pixels. I know doing a for loop will give me the minimum depth. But is there any other solution for this?