Depth in Meters

3,731 views
Skip to first unread message

alantrrs

unread,
Dec 10, 2010, 9:58:00 PM12/10/10
to OpenNI
Hi there,
Im wondering how to get the depth of every pixel in meters using
OpenNI?
With libfreenect I used this formulas:
float dist =100/(-0.0030711016*rawdisparity + 3.3309495161); //ros
distance (cm)
float dist2 = 12.36 * tanf(rawdisparity/ 2842.5 + 1.1863);//Stéphane
Magnenat distance (cm)

where rawdisparity is an unsigned short (16bit) but only 11bits of
those are actually used.

Now with OpenNI I get depth info with:
const XnDepthPixel* pDepthMap = depth.GetDepthMap();
from the documentation I see that XnDepthPixel is 16bit also, but
more than 11 bits are used.

From NiSimpleViewer.cpp I can see that they #define MAX_DEPTH 10000 so
my questions are:

Is this really the maximum value that we will find in a XnDepthPixel*
or is it arbitrarily defined for visualization purposes only? and how
can we convert this value to meters?

Thanks in advance..

Suat Gedikli

unread,
Dec 10, 2010, 10:57:05 PM12/10/10
to openn...@googlegroups.com
Hi,

so the depthmap gives back the Z-value for each pixel in mm
(millimeters). Thus if you want to get the full 3D position (X,Y,Z) of a
pixel (u,v), then use following formula:

XnUInt64 F_;
XnDouble pixel_size_;

// get the focal length in mm (ZPS = zero plane distance)
depth_.GetIntProperty ("ZPD", F_)

// get the pixel size in mm ("ZPPS" = pixel size at zero plane)
depth_.GetRealProperty ("ZPPS", pixel_size_)

X = (u - 320) * depth_md_[k] * pixel_size_ * 0.001 / F_;
Y = (v - 240) * depth_md_[k] * pixel_size_ * 0.001 / F_;
Z = depth_md_[k] * 0.001; // from mm in meters!


I hope this helps you,

Suat

alantrrs

unread,
Dec 10, 2010, 11:14:55 PM12/10/10
to OpenNI
awesome! thank you very much Suat!

suat gedikli

unread,
Dec 11, 2010, 3:39:02 AM12/11/10
to OpenNI
One thing i forgot to say:
The actual pixel size is twice the pixel size returned by
"depth_.GetRealProperty ("ZPPS", pixel_size_)". This results from the
fact, that the actual sensor is 1280x1024 and the pixel size is given
for that resolution, so you have to multiply by 2.

Cheers,
Suat

On Dec 10, 8:14 pm, alantrrs <alan.trrs.n...@gmail.com> wrote:
> awesome! thank you very much Suat!
>
> On Dec 10, 9:57 pm, Suat Gedikli <suat.gedi...@googlemail.com> wrote:
>
> > Hi,
>
> > so the depthmap gives back the Z-value for each pixel in mm
> > (millimeters). Thus if you want to get the full 3D position (X,Y,Z) of a
> > pixel (u,v), then use following formula:
>
> > XnUInt64 F_;
> > XnDouble pixel_size_;
>
> > // get the focal length in mm (ZPS = zero plane distance)
> > depth_.GetIntProperty ("ZPD", F_)
>
> > // get the pixel size in mm ("ZPPS" = pixel size at zero plane)
> > depth_.GetRealProperty ("ZPPS", pixel_size_)
>
> > X = (u - 320) * depth_md_[k] * pixel_size_ * 0.001 / F_;
> > Y = (v - 240) * depth_md_[k] * pixel_size_ * 0.001 / F_;
> > Z = depth_md_[k] * 0.001; // from mm in meters!
>
> > I hope this helps you,
>
> > Suat
>
> > On Fri, 2010-12-10 at 18:58 -0800, alantrrs wrote:
> > > Hi there,
> > > Im wondering how to get the depth of every pixel in meters using
> > > OpenNI?
> > > With libfreenect I used this formulas:
> > > float dist =100/(-0.0030711016*rawdisparity+ 3.3309495161begin_of_the_skype_highlighting            + 3.3309495161      end_of_the_skype_highlighting); //ros

tamirb

unread,
Dec 11, 2010, 7:52:59 AM12/11/10
to OpenNI
I'm not near my computer, but I'm pretty sure this is supported 'out
of the box'. Search for realworld (convert2realworld) or real world
transform in the documentation of openni or NITE and you should find a
function that takes an (x,y,z) coordinate of (pixel, pixel, mm) and
converts it to (mm,mm,mm) whereas the sensor is at (0,0,0)

Ill try to get a better answer when I'm next to a computer (I'm from
my mobile)

Radu Bogdan Rusu

unread,
Dec 12, 2010, 1:46:28 PM12/12/10
to openn...@googlegroups.com, tamirb

On 12/11/2010 04:52 AM, tamirb wrote:
> I'm not near my computer, but I'm pretty sure this is supported 'out
> of the box'. Search for realworld (convert2realworld) or real world
> transform in the documentation of openni or NITE and you should find a
> function that takes an (x,y,z) coordinate of (pixel, pixel, mm) and
> converts it to (mm,mm,mm) whereas the sensor is at (0,0,0)
>
> Ill try to get a better answer when I'm next to a computer (I'm from
> my mobile)

Tamir,

If you can shows us a code sample that uses that (I looked at it, but the documentation doesn't specify what the input
is), we can take a look at it to see if it's more efficient than the current way we do it in the ROS drivers. It would
be awesome to take that part of the driver out and replace it with OpenNI calls. :)

Thanks,
Radu.
--
http://pointclouds.org

Ken Conley

unread,
Dec 12, 2010, 1:51:48 PM12/12/10
to openn...@googlegroups.com

Radu,

I think this may be referring to ConvertRealWorldToProjective (and
vice versa) in openni/include/ni/XnCppWrapper.h? It's used in samples
like Players.

- Ken

Tamir Berliner

unread,
Dec 12, 2010, 1:58:12 PM12/12/10
to openn...@googlegroups.com, openn...@googlegroups.com
Yeap, Ken is right. Thanks!

Sent from a mobile device
--
You received this message because you are subscribed to the Google Groups "OpenNI" group.
To post to this group, send email to openn...@googlegroups.com.
To unsubscribe from this group, send email to openni-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/openni-dev?hl=en.

Radu Bogdan Rusu

unread,
Dec 12, 2010, 2:27:37 PM12/12/10
to openn...@googlegroups.com, Tamir Berliner
Awesome, thanks Ken, Tamir!


On 12/12/2010 10:58 AM, Tamir Berliner wrote:
> Yeap, Ken is right. Thanks!
>
> Sent from a mobile device
>

> On Dec 12, 2010, at 8:52 PM, "Ken Conley" <k...@willowgarage.com <mailto:k...@willowgarage.com>> wrote:
>
>> On Sun, Dec 12, 2010 at 10:46 AM, Radu Bogdan Rusu
>> <ru...@willowgarage.com <mailto:ru...@willowgarage.com>> wrote:
>>>
>>> On 12/11/2010 04:52 AM, tamirb wrote:
>>>>
>>>> I'm not near my computer, but I'm pretty sure this is supported 'out
>>>> of the box'. Search for realworld (convert2realworld) or real world
>>>> transform in the documentation of openni or NITE and you should find a
>>>> function that takes an (x,y,z) coordinate of (pixel, pixel, mm) and
>>>> converts it to (mm,mm,mm) whereas the sensor is at (0,0,0)
>>>>
>>>> Ill try to get a better answer when I'm next to a computer (I'm from
>>>> my mobile)
>>>
>>> Tamir,
>>>
>>> If you can shows us a code sample that uses that (I looked at it, but the
>>> documentation doesn't specify what the input is), we can take a look at it
>>> to see if it's more efficient than the current way we do it in the ROS
>>> drivers. It would be awesome to take that part of the driver out and replace
>>> it with OpenNI calls. :)
>>
>> Radu,
>>
>> I think this may be referring to ConvertRealWorldToProjective (and
>> vice versa) in openni/include/ni/XnCppWrapper.h? It's used in samples
>> like Players.
>>
>> - Ken
>>
>> --
>> You received this message because you are subscribed to the Google Groups "OpenNI" group.

>> To post to this group, send email to openn...@googlegroups.com <mailto:openn...@googlegroups.com>.


>> To unsubscribe from this group, send email to openni-dev+...@googlegroups.com

>> <mailto:openni-dev+...@googlegroups.com>.

Ziv Hendel

unread,
Dec 12, 2010, 4:54:38 PM12/12/10
to OpenNI
Hi Radu!

The conversion between raw disparity values to depth in millimeters
that happens on every frame automatically is located in:
Sensor\Source\XnDDK\XnShiftToDepth.cpp
It uses the internal sensor calibration params that's read off the
sensor flash memory to accurately do the mapping.

On top of that, we also provide a function to convert points from the
projective point of view of the camera to real world coordinates that
can be properly used to measure the distance between points. This is
very important for computer vision purposes!

The code that does that is in the function
xnConvertProjectiveToRealWorld from the file OpenNI\Source\OpenNI
\XnOpenNI.cpp.

Thanks,
Ziv.

Broiler

unread,
Feb 8, 2011, 5:56:44 AM2/8/11
to OpenNI
Hi,

like the old question below, I want to know, if and how it is possible
to get depth values greater than 10 meter using openni. In the first
time I used the iwfreenect library and there, it was possible to get
(ok, not very reliable, but useful) depth values farther away than 10
meter.

I searched the source code from the sensor and openni, but I did not
get it to change the maximum distance.

Does anyone have any ideas?

Thank you in advance!

On Dec 11 2010, 3:58 am, alantrrs <alan.trrs.n...@gmail.com> wrote:
> Hi there,
> Im wondering how to get thedepthof every pixel in meters using

Shay

unread,
Feb 18, 2011, 1:08:04 PM2/18/11
to OpenNI
I've been using an XnVector3D, saving the point and printing it as
floats (printf("%f, %f, %f", var.X, var.Y, var.Z)

This sure looks like it prints in millimeters. Is this inaccurate?

Also, does anyone know what the true location of the origin is? I know
it's at the camera, but I can't measure that on the kinect itself. Can
we possibly get distances (x,y,z) of the origin from the center top of
the kinect, or somewhere easy to measure from?

Thanks,
Shayna

On Feb 8, 4:56 am, Broiler <Autob...@gmx.de> wrote:
> Hi,
>
> like the old question below, I want to know, if and how it is possible
> to getdepthvalues greater than 10 meter using openni. In the first
> time I used the iwfreenect library and there, it was possible to get
> (ok, not very reliable, but useful)depthvalues farther away than 10
Reply all
Reply to author
Forward
0 new messages