# Issue Encountered with Code "How to Detect and Count Objects in Polygon Zone"

**URL:** <https://discuss.roboflow.com/t/issue-encountered-with-code-how-to-detect-and-count-objects-in-polygon-zone/5785>\
**Category:** 🤝  Community Help\
**Tags:** bugs\
**Created:** [May 13, 2024, 3:21pm UTC](https://discuss.roboflow.com/t/issue-encountered-with-code-how-to-detect-and-count-objects-in-polygon-zone/5785 "2024-05-13T15:21:03Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahin\_amini](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/shahin_amini/32/4559_2.png) [@shahin\_amini](https://discuss.roboflow.com/u/shahin_amini)\
**Post date:** [May 13, 2024, 3:21pm UTC](https://discuss.roboflow.com/t/issue-encountered-with-code-how-to-detect-and-count-objects-in-polygon-zone/5785/1 "2024-05-13T15:21:03Z")

</div>

Hello,

I hope this message finds you well. I’m writing to inform you about an error I encountered while working on the code example titled “How to Detect and Count Objects in Polygon Zone.”

I came across the following error:

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/2X/7/77f4c46f79418b44bf340592974e253e0a3611ce.png)

I would greatly appreciate it if you could assist me in resolving this issue. Your help in fixing this error would be invaluable to me.

Best regards

---

<div class="post-metadata">

**Author:** ![linas](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/linas/32/4519_2.png) [@linas](https://discuss.roboflow.com/u/linas)\
**Post date:** [May 13, 2024, 3:48pm UTC](https://discuss.roboflow.com/t/issue-encountered-with-code-how-to-detect-and-count-objects-in-polygon-zone/5785/2 "2024-05-13T15:48:55Z")

</div>

Hey @shahin_amini 👋

Welcome to the community - good to see you trying out Roboflow!

What would help is seeing what the error says. Can you post it here, please? 🙂

At the same time, I see you’re using some functions only found in older `supervision` versions. Could you change to `sv.Detections.from_ultralytics`, instead of `from_yolov8`?

---

<div class="post-metadata">

**Author:** ![Nathan\_Yan](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/nathan_yan/32/4447_2.png) [@Nathan\_Yan](https://discuss.roboflow.com/u/Nathan_Yan)\
**Post date:** [May 13, 2024, 4:12pm UTC](https://discuss.roboflow.com/t/issue-encountered-with-code-how-to-detect-and-count-objects-in-polygon-zone/5785/3 "2024-05-13T16:12:53Z")

</div>

Hi! Found the same issue. The tutorial @shahin_amini is using is [this](https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-detect-and-count-objects-in-polygon-zone.ipynb)

The error got from running the code above was this. Hope this helps with fixing the issue 👍

 ![Screenshot 2567-05-13 at 12.12.16](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/2X/1/194e453fa94ccd05dfe40b708d0f66f876b59673.png)

---

<div class="post-metadata">

**Author:** ![shahin\_amini](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/shahin_amini/32/4559_2.png) [@shahin\_amini](https://discuss.roboflow.com/u/shahin_amini)\
**Post date:** [May 14, 2024, 7:15am UTC](https://discuss.roboflow.com/t/issue-encountered-with-code-how-to-detect-and-count-objects-in-polygon-zone/5785/4 "2024-05-14T07:15:24Z")

</div>

did not work

---

<div class="post-metadata">

**Author:** ![shahin\_amini](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/shahin_amini/32/4559_2.png) [@shahin\_amini](https://discuss.roboflow.com/u/shahin_amini)\
**Post date:** [May 14, 2024, 7:16am UTC](https://discuss.roboflow.com/t/issue-encountered-with-code-how-to-detect-and-count-objects-in-polygon-zone/5785/5 "2024-05-14T07:16:14Z")

</div>

exactly!  
and i don’t know how to fix it.

---

<div class="post-metadata">

**Author:** ![linas](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/linas/32/4519_2.png) [@linas](https://discuss.roboflow.com/u/linas)\
**Post date:** [May 14, 2024, 7:46am UTC](https://discuss.roboflow.com/t/issue-encountered-with-code-how-to-detect-and-count-objects-in-polygon-zone/5785/6 "2024-05-14T07:46:29Z")

</div>

Thanks @Nathan_Yan, that’s very useful info.

I feel like I’ve seen this issue before - looking into it right now.

---

<div class="post-metadata">

**Author:** ![linas](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/linas/32/4519_2.png) [@linas](https://discuss.roboflow.com/u/linas)\
**Post date:** [May 14, 2024, 8:01am UTC](https://discuss.roboflow.com/t/issue-encountered-with-code-how-to-detect-and-count-objects-in-polygon-zone/5785/7 "2024-05-14T08:01:08Z")

</div>

Hi @shahin_amini, @Nathan_Yan,

I found what’s causing the issue. Turns out - our tutorial is a bit old. I’ll make sure it’s updated soon.

In the mean time, would this solve your problem?

> **[How to Count Objects in a Zone](https://blog.roboflow.com/how-to-count-objects-in-a-zone/)**
>
> In this guide, we show how to count objects in a zone using YOLOv8 and supervision.

Note that I see 2 slightly-old parts in this too:

1. We’re using `sv.Color.WHITE` instead of `sv.Color.white()`
2. We’ve changed `sv.Detections.from_yolov8` to `sv.Detections.from_ultralytics`

Let me know if that solves your problem!

---

<div class="post-metadata">

**Author:** ![shahin\_amini](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/shahin_amini/32/4559_2.png) [@shahin\_amini](https://discuss.roboflow.com/u/shahin_amini)\
**Post date:** [May 14, 2024, 9:53am UTC](https://discuss.roboflow.com/t/issue-encountered-with-code-how-to-detect-and-count-objects-in-polygon-zone/5785/8 "2024-05-14T09:53:31Z")

</div>

Didn’t work yet  
R U sure it works?

---

<div class="post-metadata">

**Author:** ![linas](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/linas/32/4519_2.png) [@linas](https://discuss.roboflow.com/u/linas)\
**Post date:** [May 14, 2024, 10:18am UTC](https://discuss.roboflow.com/t/issue-encountered-with-code-how-to-detect-and-count-objects-in-polygon-zone/5785/9 "2024-05-14T10:18:42Z")

</div>

Indeed, I found one issue in this blog too. Following updates this year, the iterators are missing an extra `_` in the results.

I did get it working here: [Google Colab](https://colab.research.google.com/drive/1VaCe3AkaRcVW6CipktxwsxyTb2GcUgdf?usp=sharing)

---

<div class="post-metadata">

**Author:** ![shahin\_amini](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/shahin_amini/32/4559_2.png) [@shahin\_amini](https://discuss.roboflow.com/u/shahin_amini)\
**Post date:** [May 18, 2024, 1:53pm UTC](https://discuss.roboflow.com/t/issue-encountered-with-code-how-to-detect-and-count-objects-in-polygon-zone/5785/10 "2024-05-18T13:53:13Z")

</div>

it seems it works  
thanks a lot!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/1X/bb6edbfa56d0cf2ee603f061e9e09103502cc8cc.png) [@system](https://discuss.roboflow.com/u/system)\
**Post date:** [June 8, 2024, 1:53pm UTC](https://discuss.roboflow.com/t/issue-encountered-with-code-how-to-detect-and-count-objects-in-polygon-zone/5785/11 "2024-06-08T13:53:42Z")

</div>

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
