sadmb / ofxKinectNui

Kinect SDK 1.0 or higher addon for openFrameworks
46 stars 31 forks source link

ofxBase3DVideo::getWorldCoordinateFor(..) only supports 640x480 resolution #12

Closed lucieb closed 11 years ago

lucieb commented 12 years ago

The focal length values used in ofVec3f getWorldCoordinateFor(int depthX, int depthY, double depthZ) are only valid if you are using the depth camera in 640x480 resolution. If you're using the depth camera in 320x240, the 3D coordinates are not correct.

To solve this, use a scale variable in the function, like this:

result.x = float((depthX - (float)3.3930780975300314e+02/calibScaleX) * calibScaleX * depthZ * (double)(1.0 / 5.9421434211923247e+02)); result.y = - float((depthY - (float)2.4273913761751615e+02/calibScaleY) * calibScaleY * depthZ * (double)(1.0 / 5.9104053696870778e+02));

where

calibScaleX = (640.0f/width) and calibScaleY = (480.0f/height)

Also note that you can simplify your formula by using the calibration data constants provided by the Kinect SDK.

pt3d.x = (depthX - depthWidth/2.0) * calibScaleX * depthZ * NUI_CAMERA_DEPTH_IMAGE_TO_SKELETON_MULTIPLIER_320x240; pt3d.y = - (depthY - depthHeight/2.0) * calibScaleY * depthZ * NUI_CAMERA_DEPTH_IMAGE_TO_SKELETON_MULTIPLIER_320x240;

if you use these constants, then the scaling values have to be calibScaleX = (320.0f/width) and calibScaleY = (240.0f/height)

sadmb commented 12 years ago

@lucieb Sorry for this late. Thank you for your great help. : ) I have fixed it, will pull ASAP!

sadmb commented 11 years ago

@lucieb Thanks. It works now. ; )