# setRegionOfInterest() not working with object or body tracking? SDK 4.0

**URL:** <https://community.stereolabs.com/t/setregionofinterest-not-working-with-object-or-body-tracking-sdk-4-0/2742>\
**Category:** C++\
**Created:** [June 6, 2023, 6:09am UTC](https://community.stereolabs.com/t/setregionofinterest-not-working-with-object-or-body-tracking-sdk-4-0/2742 "2023-06-06T06:09:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![trent](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/t/f05b48/32.png) [@trent](https://community.stereolabs.com/u/trent)\
**Post date:** [June 6, 2023, 6:09am UTC](https://community.stereolabs.com/t/setregionofinterest-not-working-with-object-or-body-tracking-sdk-4-0/2742/1 "2023-06-06T06:09:10Z")

</div>

I have been following this example which shows how to generate a region of interest mask: [zed-sdk/main.cpp at master · stereolabs/zed-sdk · GitHub](https://github.com/stereolabs/zed-sdk/blob/master/depth%20sensing/region%20of%20interest/cpp/src/main.cpp)

The mask appears properly in the output (essentially just combining the mask pixels with the cvImage), but this line does nothing: zed.setRegionOfInterest(slROI);

I assumed the camera input would limit the tracking to only whats visible in the mask. But after adding in either object or body tracking, it’s still detecting objects outside the mask?

Including a screenshot which demonstrates the issue- the yellow boxes in the top left image show tracked people, but they are outside the masked area (blue outline):

 ![Screen Shot 2023-06-06 at 4.24.16 pm](https://community.stereolabs.com/uploads/default/original/2X/9/994f16fe6eb67ae946af52de999313f45c5427ac.png)

Minimal code sample:

```auto
cv::Mat ROI;
ROI = cv::Mat(720, 1280, CV_8UC1);
ROI.setTo(0);
cv::Rect selection_rect;
selection_rect.x = 900;
selection_rect.y = 0;
selection_rect.width = 600;
selection_rect.height = 600;
cv::rectangle(ROI, selection_rect, cv::Scalar(250), -1);
auto resolution = camera.getCameraInformation().camera_configuration.resolution;
sl::Mat slROI(resolution, MAT_TYPE::U8_C1, ROI.data, ROI.step); 	
camera.setRegionOfInterest(slROI);

```

---

<div class="post-metadata">

**Author:** ![alassagne](https://community.stereolabs.com/user_avatar/community.stereolabs.com/alassagne/32/2428_2.png) [@alassagne](https://community.stereolabs.com/u/alassagne)\
**Post date:** [June 6, 2023, 12:04pm UTC](https://community.stereolabs.com/t/setregionofinterest-not-working-with-object-or-body-tracking-sdk-4-0/2742/2 "2023-06-06T12:04:56Z")

</div>

Hi,

It seems like a bug. Currently the mask is only applied to the depth information and not on image. The Object Detection module only outputs 2D detection, and it’s only merged with the depth later.

---

<div class="post-metadata">

**Author:** ![trent](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/t/f05b48/32.png) [@trent](https://community.stereolabs.com/u/trent)\
**Post date:** [June 6, 2023, 11:23pm UTC](https://community.stereolabs.com/t/setregionofinterest-not-working-with-object-or-body-tracking-sdk-4-0/2742/3 "2023-06-06T23:23:18Z")

</div>

Thanks for the response @alassagne. If the mask is only applied to the depth- the code comments are misleading: ‘Defines a region of interest to focus on for all the SDK, discarding other parts’.

Is there any workaround for object or body tracking to limit the tracking area, or do I need to wait until the bug is fixed in a new release?

---

<div class="post-metadata">

**Author:** ![alassagne](https://community.stereolabs.com/user_avatar/community.stereolabs.com/alassagne/32/2428_2.png) [@alassagne](https://community.stereolabs.com/u/alassagne)\
**Post date:** [June 8, 2023, 1:18pm UTC](https://community.stereolabs.com/t/setregionofinterest-not-working-with-object-or-body-tracking-sdk-4-0/2742/4 "2023-06-08T13:18:57Z")

</div>

You can manually remove the object / bodies outside of the zone, but indeed a fix is required to do this properly.
