# Kinect Depth calculation [closed]

Sorry guys, i am desperate for answer. That is why i didn't follow the rules of this website. I sincerly apologise. For this code, i have come up with a better one. float cx = 320.0; float cy = 240.0; float minDistance = -10; float scaleFactor = 0.0021;

for (int v=0, n=0 ; v<480 ; v++)
{
for (int u=0 ; u<640 ; u++, n++)
{
Vec3f result;
result.x = float(((u - cx) * t_gamma[depth[n]]+ minDistance)   * scaleFactor * (cx/cy));
result.y = float(((v - cy) * t_gamma[depth[n]]+ minDistance)   * scaleFactor);
result.z = float(t_gamma[depth[n]]);

}

}

// OS X requires GLUT to run on the main thread

return 0;


} is this code better? i have tried to save the depth data but all the data is zero. I don't know where is the problem?

edit retag reopen merge delete

### Closed for the following reason duplicate question by Wim close date 2011-08-02 11:26:49

Why do you want to do this yourself? Is it an exercise or are you interested in the results. For the latter I would highly recommend using the openni_camera node as it already gives your 3D data.
I am an intern in a company and i was asked to do this... Using the OpenKinect.
I would really appreciate any help provided...
If your depth data is zero, the code above is probably not the problem. Does OpenKinect provide samples? Then use those, otherwise you can still use the ROS node, remove the ROS stuff and use it for yourself (respecting the license of course).

Sort by » oldest newest most voted

This message is double posted see original one HERE

more

It's not really the original. That link was another question before (and should probably be returned to its original question). As I was just skimming through the code. This is what openni_camera does:

for (int v = 0; v < (int)cloud_msg->height; ++v, depth_idx += depthSkip)
{
for (int u = 0; u < (int)cloud_msg->width; ++u, depth_idx += depthStep, ++pt_iter)
{
pcl::PointXYZ& pt = *pt_iter;

// Check for invalid measurements
if (depth_md[depth_idx] == 0 ||
depth_md[depth_idx] == depth.getNoSampleValue () ||
{
// not valid
pt.x = pt.y = pt.z = bad_point;
continue;
}

// Fill in XYZ
pt.x = (u - centerX) * depth_md[depth_idx] * constant;
pt.y = (v - centerY) * depth_md[depth_idx] * constant;
pt.z = depth_md[depth_idx] * 0.001;
}
}

more