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
+ """
1
63
from __future__ import print_function
2
64
3
65
from contextlib import contextmanager
@@ -106,6 +168,18 @@ class Device(object):
106
168
Raises:
107
169
:py:class:`.NoDeviceError` if there is no default device to open.
108
170
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
+
109
183
"""
110
184
111
185
def __init__ (self , c_object = None ):
@@ -121,6 +195,9 @@ def __init__(self, c_object=None):
121
195
self .color_frame_listener = self ._default_listener
122
196
self .ir_and_depth_frame_listener = self ._default_listener
123
197
198
+ self .color_camera_params = None
199
+ self .ir_camera_params = None
200
+
124
201
def start (self , frame_listener = None ):
125
202
"""Start depth, IR and RGB streams.
126
203
@@ -136,6 +213,9 @@ def start(self, frame_listener=None):
136
213
self .ir_and_depth_frame_listener = frame_listener
137
214
lib .freenect2_device_start (self ._c_object )
138
215
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
+
139
219
def stop (self ):
140
220
"""Stop any running streams."""
141
221
lib .freenect2_device_stop (self ._c_object )
@@ -182,18 +262,6 @@ def registration(self):
182
262
self .ir_camera_params , self .color_camera_params )
183
263
return self ._registration
184
264
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
-
197
265
@property
198
266
def color_frame_listener (self ):
199
267
"""A callable called whenever a new color frame arrives from the
@@ -434,7 +502,7 @@ def __init__(self, depth_p, rgb_p):
434
502
lib .freenect2_registration_create (depth_p , rgb_p ),
435
503
lib .freenect2_registration_dispose )
436
504
437
- def apply (self , rgb , depth , enable_filter = True ):
505
+ def apply (self , rgb , depth , enable_filter = True , with_big_depth = False ):
438
506
"""Take an RGB and Depth image and return tuple with the undistorted
439
507
depth image and color image rectified onto depth.
440
508
@@ -443,6 +511,8 @@ def apply(self, rgb, depth, enable_filter=True):
443
511
depth (:py:class:`.Frame`): Depth frame received from device
444
512
enable_filter (bool): If true, filter out pixels not visible in
445
513
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.
446
516
447
517
Returns:
448
518
A :py:class:`Frame` pair representing the undistorted depth and
@@ -453,12 +523,25 @@ def apply(self, rgb, depth, enable_filter=True):
453
523
undistorted .format = depth .format
454
524
registered = Frame .create (512 , 424 , 4 )
455
525
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
+
456
533
lib .freenect2_registration_apply (
457
534
self ._c_object ,
458
535
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
460
538
)
461
- return undistorted , registered
539
+
540
+ rvs = [undistorted , registered ]
541
+ if with_big_depth :
542
+ rvs .append (big_depth )
543
+
544
+ return tuple (rvs )
462
545
463
546
def get_points_xyz (self , undistorted , rows , cols ):
464
547
"""Retrieve real-world co-ordinates corresponding to points in the
0 commit comments