# Image segmentation using yolov8 with zed 2i python

**URL:** <https://community.stereolabs.com/t/image-segmentation-using-yolov8-with-zed-2i-python/3565>\
**Category:** Python\
**Created:** [September 25, 2023, 6:29am UTC](https://community.stereolabs.com/t/image-segmentation-using-yolov8-with-zed-2i-python/3565 "2023-09-25T06:29:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ash](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@ash](https://community.stereolabs.com/u/ash)\
**Post date:** [September 25, 2023, 6:29am UTC](https://community.stereolabs.com/t/image-segmentation-using-yolov8-with-zed-2i-python/3565/1 "2023-09-25T06:29:45Z")

</div>

I have a trained model for image segmentation using yolov8. when i used that model with detector.py in zed sdk it gives bounding boxes instead of masks. how to modify the detector.py to display masks?

---

<div class="post-metadata">

**Author:** ![JPlou](https://community.stereolabs.com/user_avatar/community.stereolabs.com/jplou/32/1012_2.png) [@JPlou](https://community.stereolabs.com/u/JPlou)\
**Post date:** [September 25, 2023, 8:42am UTC](https://community.stereolabs.com/t/image-segmentation-using-yolov8-with-zed-2i-python/3565/2 "2023-09-25T08:42:33Z")

</div>

Hi @ash, welcome to the forums

I think you can only make the ZED SDK ingest bounding boxes and not masks, currently.  
So, it’s not really a display issue.

That being said, the masks in the BodyData are 2D arrays with values being either 0 (not mask) or 255 (mask). Their dimensions are the ones of the [`bounding_box_2d`](https://www.stereolabs.com/docs/api/python/classpyzed_1_1sl_1_1BodyData.html#a98fee4c31199a3cafe5528f49b19dad8) attribute. They are located in the frame following the `bounding_box_2d` origin.

You can use the tool you want to display it.  
@Gopi-htic used pyplot here for example: [Mask is inconsistent](https://community.stereolabs.com/t/mask-is-inconsistent/3454)

---

<div class="post-metadata">

**Author:** ![a11s](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@a11s](https://community.stereolabs.com/u/a11s)\
**Post date:** [September 29, 2023, 9:43pm UTC](https://community.stereolabs.com/t/image-segmentation-using-yolov8-with-zed-2i-python/3565/3 "2023-09-29T21:43:55Z")

</div>

Is that true about masks not being supported? I also require masks of detected objects, its’s the entire reason I am using this setup!

If it is not supported, what is this line of code for?

```auto
detection_parameters.enable_segmentation = True # Outputs 2D masks over detected objects

```

---

<div class="post-metadata">

**Author:** ![JPlou](https://community.stereolabs.com/user_avatar/community.stereolabs.com/jplou/32/1012_2.png) [@JPlou](https://community.stereolabs.com/u/JPlou)\
**Post date:** [October 4, 2023, 8:03am UTC](https://community.stereolabs.com/t/image-segmentation-using-yolov8-with-zed-2i-python/3565/4 "2023-10-04T08:03:48Z")

</div>

@a11s @ash

I was not clear, sorry. The masks are supported, however the final output is masks computed by the ZED SDK, it can’t use masks from other detectors.  
It should totally work and that’s exactly what this line is for.

But no we don’t have a method to display them right now.

Sorry again for the mistake.

---

<div class="post-metadata">

**Author:** ![sanjaiiv04](https://community.stereolabs.com/user_avatar/community.stereolabs.com/sanjaiiv04/32/2103_2.png) [@sanjaiiv04](https://community.stereolabs.com/u/sanjaiiv04)\
**Post date:** [November 23, 2023, 5:48am UTC](https://community.stereolabs.com/t/image-segmentation-using-yolov8-with-zed-2i-python/3565/5 "2023-11-23T05:48:59Z")

</div>

@JPlou does it mean we cannot use the mask coordinates to find our region of interest and use some kind of cv method to create segmentations? Surely there must be some kind of a way to do that.

---

<div class="post-metadata">

**Author:** ![JPlou](https://community.stereolabs.com/user_avatar/community.stereolabs.com/jplou/32/1012_2.png) [@JPlou](https://community.stereolabs.com/u/JPlou)\
**Post date:** [November 23, 2023, 8:48am UTC](https://community.stereolabs.com/t/image-segmentation-using-yolov8-with-zed-2i-python/3565/6 "2023-11-23T08:48:54Z")

</div>

@sanjaiiv04

I don’t know of a way to do that, but there may be, yes.  
To clarify, the ZED SDK can ingest bounding boxes from a custom detector, and it is able to infer masks from them. You can then exploit the [mask](https://www.stereolabs.com/docs/api/python/classpyzed_1_1sl_1_1ObjectData.html#aff25fe6cafaf46730a2b278426aaafbb) output from ObjectData in any way you want, it is the result of the SDK segmentation.
