# TOF Depth Image Encoding changed from 32FC1 to mono8

Source: https://forum.modalai.com/topic/548/tof-depth-image-encoding-changed-from-32fc1-to-mono8
Category: General Questions (https://forum.modalai.com/category/2/general-questions)
Posted: 2021-11-08 22:49:13 UTC by jaredjohansen
Replies: 2 · Views: 782

## jaredjohansen · 2021-11-08 22:49:13 UTC

I have a TOF sensor.

A little while ago, to see the depth image, I would `rostopic echo /tof/depth`.  When I did that, the ROS message would be of the type `sensor_imgs/Image` and its encoding would be `32FC1`.

Today, with the latest code, I need to use `rostopic echo /mpa/tof_depth` to get the depth image.  When I do that, the ROS message is still of the type `sensor_imgs/Image` but its encoding is `mono8`.

Historically, if I wanted to process the depth image in ROS, I would setup a subscriber and use code like that shown below to ingest the data as a depth image.  I could then access individual pixels to get the depth (in meters).

I'm now sure how to process a depth image of encoding `mono8`.  It seems like it would have too few bits to represent the resolution of depths possible.

Is the `mono8` encoding intentional (with the conversion to the latest mpa_to_ros)?  Or is it a bug?

If it's intentional, can you help me understand how to process this new data encoding and extract the distances of individual pixels (similar to the code posted below)?

```
        # get the depth image
        dep_frame = np.fromstring(tof_depth.data, dtype=np.single)
        dep_frame = dep_frame.reshape(172, 224) 

        # Get closest value in bounding box
        object_depth_map = dep_frame[top:bottom,left:right]
        object_depth_map[object_depth_map == 0] = 9999.00
        object_depth = np.min(object_depth_map)
```

## Reply by Guest · 2021-11-08 23:27:53 UTC

MPA_to_ROS was recently updated to a new architecture, the depth image that we publish was meant to be more of a debug tool where the z value of the pointcloud is [scaled from 0-255 for 0-1 meter distance](https://gitlab.com/voxl-public/modal-pipe-architecture/voxl-camera-server/-/blob/master/src/api_interface/hal3/hal3_camera_mgr_tof.cpp#L565), but it looks like the old mpa to ros instead published the z value of the sensor, which is floating point. To get the same old value that you were looking at, you should access the pointcloud tof message and look at the z value.

## Reply by jaredjohansen · 2021-11-09 00:37:41 UTC

For anyone who runs into this same issue, I changed my subscriber to listen to `/map/tof_pc` (which has the `PointCloud2` type).  My code (to extract the z value) is this:
```
# get the depth image
        dep_frame = np.fromstring(data.data, dtype=np.single) # get numpy array
        dep_frame = dep_frame.reshape(172, 224, 3)[:,:,2]
```
