Skip to content

Commit 21a062b

Browse files
authored
Added new parameter to Frame object
Allows conversion of numpy array to frame object.
1 parent 88de3ca commit 21a062b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pylibfreenect2/libfreenect2.pyx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ cdef class Frame:
217217
frame_type : int, optional
218218
Underlying frame type. Default is -1. Used by ``asarray`` method.
219219
220+
byte_data : byte_data, optional
221+
Numpy array of depth or ir data in byte format,
222+
that will be converted to a frame class.
223+
Use byte_data = numpy_array.tobytes('C') for conversion to bytes.
224+
Default is None.
220225
See also
221226
--------
222227
@@ -228,7 +233,7 @@ cdef class Frame:
228233
cdef int frame_type
229234

230235
def __cinit__(self, width=None, height=None, bytes_per_pixel=None,
231-
int frame_type=-1):
236+
int frame_type=-1, byte_data=None):
232237
w,h,b = width, height, bytes_per_pixel
233238
all_none = (w is None) and (h is None) and (b is None)
234239
all_not_none = (w is not None) and (h is not None) and (b is not None)
@@ -238,7 +243,11 @@ cdef class Frame:
238243

239244
if all_not_none:
240245
self.take_ownership = True
241-
self.ptr = new libfreenect2.Frame(
246+
if byte_data is not None:
247+
self.ptr = new libfreenect2.Frame(
248+
width, height, bytes_per_pixel, byte_data)
249+
else:
250+
self.ptr = new libfreenect2.Frame(
242251
width, height, bytes_per_pixel, NULL)
243252
else:
244253
self.take_ownership = False

0 commit comments

Comments
 (0)