@@ -217,10 +217,9 @@ cdef class Frame:
217
217
frame_type : int, optional
218
218
Underlying frame type. Default is -1. Used by ``asarray`` method.
219
219
220
- byte_data : byte_data , optional
221
- Numpy array of depth or ir data in byte format ,
220
+ numpy_array : numpy.ndarray , optional
221
+ Numpy array of depth or ir data with ndim=2 ,
222
222
that will be converted to a frame class.
223
- Use byte_data = numpy_array.tobytes('C') for conversion to bytes.
224
223
Default is None.
225
224
See also
226
225
--------
@@ -233,7 +232,7 @@ cdef class Frame:
233
232
cdef int frame_type
234
233
235
234
def __cinit__ (self , width = None , height = None , bytes_per_pixel = None ,
236
- int frame_type = - 1 , byte_data = None ):
235
+ int frame_type = - 1 , np.ndarray[np. float32_t , ndim = 2 , mode = " c " ] numpy_array = None ):
237
236
w,h,b = width, height, bytes_per_pixel
238
237
all_none = (w is None ) and (h is None ) and (b is None )
239
238
all_not_none = (w is not None ) and (h is not None ) and (b is not None )
@@ -243,15 +242,21 @@ cdef class Frame:
243
242
244
243
if all_not_none:
245
244
self .take_ownership = True
246
- if byte_data is not None :
245
+ if numpy_array is None :
247
246
self .ptr = new libfreenect2.Frame(
248
- width, height, bytes_per_pixel, byte_data )
247
+ width, height, bytes_per_pixel, NULL )
249
248
else :
250
- self .ptr = new libfreenect2.Frame (
251
- width, height, bytes_per_pixel, NULL )
249
+ self .__instantiate_frame_with_bytes (
250
+ width, height, bytes_per_pixel, numpy_array.reshape( - 1 ) )
252
251
else :
253
252
self .take_ownership = False
254
253
254
+ cdef __instantiate_frame_with_bytes(self , int width, int height,
255
+ int bytes_per_pixel, np.ndarray[np.float32_t, ndim= 1 , mode= " c" ] numpy_array):
256
+ cdef uint8_t* bytes_ptr = reinterpret_cast[uint8_pt](& numpy_array[0 ])
257
+ self .ptr = new libfreenect2.Frame(
258
+ width, height, bytes_per_pixel, bytes_ptr)
259
+
255
260
def __dealloc__ (self ):
256
261
if self .take_ownership and self .ptr is not NULL :
257
262
del self .ptr
0 commit comments