12 images_in = robotsio.BufferedPortYarpImageOfMonoFloat()
13 images_in.open(
'/hyperpcr/depth:i')
18 depth_buffer = bytearray(numpy.zeros((height, width, 1), dtype = numpy.float32))
19 depth_image = yarp.ImageFloat()
20 depth_image.resize(width, height)
21 depth_image.setExternal(depth_buffer, width, height)
23 mask_buffer = bytearray(numpy.zeros((height, width, 1), dtype = numpy.uint8))
24 mask_image = yarp.ImageMono()
25 mask_image.resize(width, height)
26 mask_image.setExternal(mask_buffer, width, height)
29 while images_data
is None:
30 images_data = images_in.read(
False)
32 if images_data
is not None:
33 mask_image.copy(images_data.image_mono)
34 depth_image.copy(images_data.image_float)
36 depth_frame = numpy.frombuffer(depth_buffer, dtype=numpy.float32).reshape(height, width)
37 mask_frame = numpy.frombuffer(mask_buffer, dtype=numpy.uint8).reshape(height, width)
40 cv2.imwrite(
'./mask.png', mask_frame)
42 depth_file = open(
'depth.float',
"wb")
43 depth_file.write(struct.pack(
'=Q', width))
44 depth_file.write(struct.pack(
'=Q', height))
45 depth_file.write(depth_frame.astype(
'float32', order=
'C').tobytes())
52if __name__ ==
'__main__':