23 #include <plugins/openni/utils/conversions.h> 51 world2projection(xn::DepthGenerator *depthgen,
52 unsigned int num_points,
const XnPoint3D *world, XnPoint3D *proj,
53 unsigned int width,
unsigned int height)
55 if (width == 0 || height == 0) {
56 xn::DepthMetaData depth_md;
57 depthgen->GetMetaData(depth_md);
58 width = depth_md.XRes();
59 height = depth_md.YRes();
64 if ((st = depthgen->GetFieldOfView(fov)) != XN_STATUS_OK) {
65 throw Exception(
"Failed to get field of view, ignoring. (%s)",
66 xnGetStatusString(st));
69 float world_x_to_z = tan(fov.fHFOV / 2) * 2;;
70 float world_y_to_z = tan(fov.fVFOV / 2) * 2;
72 XnFloat coeff_x = width / world_x_to_z;
73 XnFloat coeff_y = height / world_y_to_z;
75 XnUInt32 half_res_x = width / 2;
76 XnUInt32 half_res_y = height / 2;
78 for (
unsigned int i = 0; i < num_points; ++i) {
79 proj[i].X = coeff_x * world[i].X / world[i].Z + half_res_x;
80 proj[i].Y = half_res_y - coeff_y * world[i].Y / world[i].Z;
81 proj[i].Z = world[i].Z;
Fawkes library namespace.