How to understand the depth of a pixel with the kinect
Hi!
I'm new of ROS and for an university project i have to grab a cup with a robot. For first i have to understand where the cup is. I have implemented an algorithm that segment the cup from the rest of the scene, and then it calculate the kaypoints of the new image. At this point i can determinate the "central" of my keypoints, that is broadly the centre of my cup.
The problem now is that till here i have worked with openCV and with the sensor_msgs/image, but to understand the depth of my pixel (the cup position) i need the registered depth topic.
What i couldn't understand it's: How i can subscribe the /camera/depth_registered/points (sensor_msgs/PointCloud2) to extract the RGB image (for the procedure that till here i did with sensor_msgs/image) and the depth image to know the depth of my task's pixel?
thanks
Luca
UPDATE
this is my callback
void callback(const sensor_msgs::PointCloud2::ConstPtr& msg) {
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::fromROSMsg (*msg, *cloud);
cv::Mat imageFrame;
if (cloud->isOrganized()) {
imageFrame = cv::Mat(cloud->height, cloud->width, CV_8UC3);
for (int h=0; h<imageFrame.rows; h++) {
for (int w=0; w<imageFrame.cols; w++) {
pcl::PointXYZRGB point = cloud->at(w, h);
Eigen::Vector3i rgb = point.getRGBVector3i();
imageFrame.at<cv::Vec3b>(h,w)[0] = rgb[2];
imageFrame.at<cv::Vec3b>(h,w)[1] = rgb[1];
imageFrame.at<cv::Vec3b>(h,w)[2] = rgb[0];
int i = centre_x + centre_y*cloud->width;
depth[call_count] = (float)cloud->points[i].z;
}
}
}
}//end callback
like you suggested to me. i tried to put the depth of my pixel in a vector, so i thought that i could see at least some values different to 0 (for the noise of the kinect i know that it's possible that some depth values in a point could be 0 or near 0 sometimes). But in my case all values still 0.