Skip to content

Commit cc7f08f

Browse files
committed
re-jig {color,ir}_camera_params attributes
Make it explicit that camera calibration is only available after device start.
1 parent ddaa978 commit cc7f08f

File tree

3 files changed

+106
-18
lines changed

3 files changed

+106
-18
lines changed

binding/freenect2-c.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,17 @@ static void freenect2_registration_dispose(Freenect2RegistrationRef reg_ref)
307307
static void freenect2_registration_apply(
308308
Freenect2RegistrationRef reg_ref, Freenect2FrameRef rgb_ref,
309309
Freenect2FrameRef depth_ref, Freenect2FrameRef undistorted_ref,
310-
Freenect2FrameRef registered_ref, int enable_filter)
310+
Freenect2FrameRef registered_ref, int enable_filter,
311+
Freenect2FrameRef big_depth_ref)
311312
{
312313
Registration* reg = reinterpret_cast<Registration*>(reg_ref);
313314
Frame* rgb = reinterpret_cast<Frame*>(rgb_ref);
314315
Frame* depth = reinterpret_cast<Frame*>(depth_ref);
315316
Frame* undistorted = reinterpret_cast<Frame*>(undistorted_ref);
316317
Frame* registered = reinterpret_cast<Frame*>(registered_ref);
318+
Frame* big_depth = reinterpret_cast<Frame*>(big_depth_ref);
317319
reg->apply(rgb, depth, undistorted, registered,
318-
(enable_filter != 0) ? true : false);
320+
(enable_filter != 0) ? true : false, big_depth);
319321
}
320322

321323
static void freenect2_registration_get_points_xyz(

binding/freenect2_build.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
4040
typedef struct {
4141
float fx, fy, cx, cy, k1, k2, k3, p1, p2;
42+
...;
4243
} IrCameraParams;
4344
4445
typedef struct {
@@ -65,6 +66,7 @@
6566
float my_x1y0; // x
6667
float my_x0y1; // y
6768
float my_x0y0; // 1
69+
...;
6870
} ColorCameraParams;
6971
7072
Freenect2Ref freenect2_create(void);
@@ -131,7 +133,8 @@
131133
void freenect2_registration_apply(
132134
Freenect2RegistrationRef reg_ref, Freenect2FrameRef rgb_ref,
133135
Freenect2FrameRef depth_ref, Freenect2FrameRef undistorted_ref,
134-
Freenect2FrameRef registered_ref, int enable_filter);
136+
Freenect2FrameRef registered_ref, int enable_filter,
137+
Freenect2FrameRef big_depth_ref);
135138
void freenect2_registration_get_points_xyz(
136139
Freenect2RegistrationRef reg_ref, Freenect2FrameRef undistorted_ref,
137140
const int32_t* rows, const int32_t* cols, size_t n_points,

freenect2/__init__.py

Lines changed: 98 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,65 @@
1+
"""
2+
.. py:class:: ColorCameraParams
3+
4+
Color camera intrinsic calibration.
5+
6+
.. py:attribute:: fx
7+
8+
Focal length for x-axis (pixels)
9+
10+
.. py:attribute:: fy
11+
12+
Focal length for y-axis (pixels)
13+
14+
.. py:attribute:: cx
15+
16+
Principal point for x-axis (pixels)
17+
18+
.. py:attribute:: cy
19+
20+
Principal point for y-axis (pixels)
21+
22+
.. py:class:: IrCameraParams
23+
24+
IR/depth camera intrinsic calibration.
25+
26+
.. py:attribute:: fx
27+
28+
Focal length for x-axis (pixels)
29+
30+
.. py:attribute:: fy
31+
32+
Focal length for y-axis (pixels)
33+
34+
.. py:attribute:: cx
35+
36+
Principal point for x-axis (pixels)
37+
38+
.. py:attribute:: cy
39+
40+
Principal point for y-axis (pixels)
41+
42+
.. py:attribute:: k1
43+
44+
Radial distortion co-efficient, 1st-order
45+
46+
.. py:attribute:: k2
47+
48+
Radial distortion co-efficient, 2nd-order
49+
50+
.. py:attribute:: k3
51+
52+
Radial distortion co-efficient, 3rd-order
53+
54+
.. py:attribute:: p1
55+
56+
Tangential distortion co-efficient
57+
58+
.. py:attribute:: p2
59+
60+
Tangential distortion co-efficient
61+
62+
"""
163
from __future__ import print_function
264

365
from contextlib import contextmanager
@@ -106,6 +168,18 @@ class Device(object):
106168
Raises:
107169
:py:class:`.NoDeviceError` if there is no default device to open.
108170
171+
.. py:attribute:: color_camera_params
172+
173+
(:py:class:`.ColorCameraParams` or None) A structure describing the RGB
174+
camera factory calibration. Before the :py:func:`.start` is called, this
175+
is *None* since the device only reports calibration when capture begins.
176+
177+
.. py:attribute:: ir_camera_params
178+
179+
(:py:class:`.IrCameraParams` or None) A structure describing the IR
180+
camera factory calibration. Before the :py:func:`.start` is called, this
181+
is *None* since the device only reports calibration when capture begins.
182+
109183
"""
110184

111185
def __init__(self, c_object=None):
@@ -121,6 +195,9 @@ def __init__(self, c_object=None):
121195
self.color_frame_listener = self._default_listener
122196
self.ir_and_depth_frame_listener = self._default_listener
123197

198+
self.color_camera_params = None
199+
self.ir_camera_params = None
200+
124201
def start(self, frame_listener=None):
125202
"""Start depth, IR and RGB streams.
126203
@@ -136,6 +213,9 @@ def start(self, frame_listener=None):
136213
self.ir_and_depth_frame_listener = frame_listener
137214
lib.freenect2_device_start(self._c_object)
138215

216+
self.color_camera_params = lib.freenect2_device_get_color_camera_params(self._c_object)
217+
self.ir_camera_params = lib.freenect2_device_get_ir_camera_params(self._c_object)
218+
139219
def stop(self):
140220
"""Stop any running streams."""
141221
lib.freenect2_device_stop(self._c_object)
@@ -182,18 +262,6 @@ def registration(self):
182262
self.ir_camera_params, self.color_camera_params)
183263
return self._registration
184264

185-
@property
186-
def ir_camera_params(self):
187-
"""A structure describing the factory calibrated parameters of the IR
188-
camera. See the libfreenect2 documentation."""
189-
return lib.freenect2_device_get_ir_camera_params(self._c_object)
190-
191-
@property
192-
def color_camera_params(self):
193-
"""A structure describing the factory calibrated parameters of the RGB
194-
camera. See the libfreenect2 documentation."""
195-
return lib.freenect2_device_get_color_camera_params(self._c_object)
196-
197265
@property
198266
def color_frame_listener(self):
199267
"""A callable called whenever a new color frame arrives from the
@@ -434,7 +502,7 @@ def __init__(self, depth_p, rgb_p):
434502
lib.freenect2_registration_create(depth_p, rgb_p),
435503
lib.freenect2_registration_dispose)
436504

437-
def apply(self, rgb, depth, enable_filter=True):
505+
def apply(self, rgb, depth, enable_filter=True, with_big_depth=False):
438506
"""Take an RGB and Depth image and return tuple with the undistorted
439507
depth image and color image rectified onto depth.
440508
@@ -443,6 +511,8 @@ def apply(self, rgb, depth, enable_filter=True):
443511
depth (:py:class:`.Frame`): Depth frame received from device
444512
enable_filter (bool): If true, filter out pixels not visible in
445513
both cameras.
514+
with_big_depth (bool): If true, also return a 1920x1082 mapping of
515+
depth onto the color map. The top and bottom rows are blank.
446516
447517
Returns:
448518
A :py:class:`Frame` pair representing the undistorted depth and
@@ -453,12 +523,25 @@ def apply(self, rgb, depth, enable_filter=True):
453523
undistorted.format = depth.format
454524
registered = Frame.create(512, 424, 4)
455525
registered.format = rgb.format
526+
527+
big_depth, big_depth_ref = None, ffi.NULL
528+
if with_big_depth:
529+
big_depth = Frame.create(1920, 1082, 4)
530+
big_depth.format = depth.format
531+
big_depth_ref = big_depth._c_object
532+
456533
lib.freenect2_registration_apply(
457534
self._c_object,
458535
rgb._c_object, depth._c_object, undistorted._c_object,
459-
registered._c_object, 1 if enable_filter else 0
536+
registered._c_object, 1 if enable_filter else 0,
537+
big_depth_ref
460538
)
461-
return undistorted, registered
539+
540+
rvs = [undistorted, registered]
541+
if with_big_depth:
542+
rvs.append(big_depth)
543+
544+
return tuple(rvs)
462545

463546
def get_points_xyz(self, undistorted, rows, cols):
464547
"""Retrieve real-world co-ordinates corresponding to points in the

0 commit comments

Comments
 (0)