Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Double event processing for "unzoned: allow" and having zones defined in Frigate #66

Open
freefd opened this issue May 23, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@freefd
Copy link
Contributor

freefd commented May 23, 2024

Description

The system duplicates event processing for zoned and unzoned areas while the configuration has default unzoned: allow.
This bug is floating (heisenbug).

Scene

image

Notification

ZoneA is colored by pink.
Path for ObjectA is colored by green.
image

ZoneA is colored by pink.
Path for ObjectB is colored by blue.
image

Frigate-Notify Version:

v0.2.8

Configuration

frigate:
  server: http://<frigate-instance>:5000
  ignoressl: false

  mqtt:
    enabled: true
    server: <mqtt-instance>
    port: 1883
    clientid: <frigate-notify-clientid>
    username: <frigate-notifiy-username>
    password: <frigate-notifiy-password>

alerts:
  telegram:
    enabled: true
    chatid: <telegram-chatid>
    token: <telegram-token>

Logs

ObjectA path

2024/05/23 12:40:09 Event ID 1716457201.716703-zcul86 - New event received.
2024/05/23 12:40:09 Event ID 1716457201.716703-zcul86 - Camera <camera-name> detected person in zone(s): []
2024/05/23 12:40:09 Event ID 1716457201.716703-zcul86 - Start time: 2024-05-23 12:40:01 +0000 UTC
2024/05/23 12:40:10 Event ID 1716457201.716703-zcul86 - Telegram alert sent
2024/05/23 12:40:12 Event ID 1716457201.716703-zcul86 - Event updated from Frigate.
2024/05/23 12:40:12 Event ID 1716457201.716703-zcul86 - Camera <camera-name> detected person in zone(s): [<zoneA-name>]
2024/05/23 12:40:12 Event ID 1716457201.716703-zcul86 - Start time: 2024-05-23 12:40:01 +0000 UTC
2024/05/23 12:40:12 Event ID 1716457201.716703-zcul86 - Entered new zone: <zoneA-name>
2024/05/23 12:40:13 Event ID 1716457201.716703-zcul86 - Telegram alert sent

ObjectB path

2024/05/27 15:06:23 Event ID 1716811576.873335-lltf2e - New event received.
2024/05/27 15:06:23 Event ID 1716811576.873335-lltf2e - Camera <camera-name> detected person in zone(s): []
2024/05/27 15:06:23 Event ID 1716811576.873335-lltf2e - Start time: 2024-05-27 15:06:16 +0000 UTC
2024/05/27 15:06:24 Event ID 1716811576.873335-lltf2e - Telegram alert sent
2024/05/27 15:06:25 Event ID 1716811576.873335-lltf2e - Event updated from Frigate.
2024/05/27 15:06:25 Event ID 1716811576.873335-lltf2e - Camera <camera-name> detected person in zone(s): [zoneA-name]
2024/05/27 15:06:25 Event ID 1716811576.873335-lltf2e - Start time: 2024-05-27 15:06:16 +0000 UTC
2024/05/27 15:06:25 Event ID 1716811576.873335-lltf2e - Entered new zone: zoneA-name
2024/05/27 15:06:26 Event ID 1716811576.873335-lltf2e - Telegram alert sent

Expected behavior

The system processes a particular event only once and regardless of existing zones if configuration unzoned: allow is set.

@freefd freefd changed the title Bug: Double event processing for "unzoned: allow" Bug: Double event processing for "unzoned: allow" and having zones defined in Frigate May 23, 2024
@0x2142 0x2142 added the bug Something isn't working label Jun 3, 2024
@0x2142
Copy link
Owner

0x2142 commented Jun 3, 2024

Hmm - So based on the logs, it seems like an initial notification is sent out when the object is outside a zone - then a follow up once the object enters the zone. Is the issue that the snapshots are identical between them? It looks like it for me, but I want to confirm since they've been pixelated for the issue upload.

If so, I wonder if this might be an issue of grabbing the snapshot from Frigate too quickly? Maybe Frigate hasn't updated the snapshot yet by the time we grab it for the notification.

@freefd
Copy link
Contributor Author

freefd commented Jun 4, 2024

Hi @0x2142,

Is the issue that the snapshots are identical between them?

That's the thing, they're not identical, but only slightly different, as expected.

It looks like it for me, but I want to confirm since they've been pixelated for the issue upload.

Those snapshots were pixelated intentionally (today's internet is not about privacy at all).

I see the behavior as follows:


  1. ObjectA appears in ZoneA.
  2. Frigate detects ObjectA and sends MQTT message with zone included.
  3. ObjectA has left ZoneA but is still in the camera's FOV.
  4. Frigate detects ObjectA again and sends MQTT message without a zone.

  1. ObjectB appears outside ZoneA.
  2. Frigate detects ObjectB and sends MQTT message without a zone.
  3. ObjectB appears in ZoneA.
  4. Frigate detects ObjectB and sends MQTT message with zone included.

The trouble may be hiding under https://github.com/0x2142/frigate-notify/blob/main/events/mqtt.go#L98-L100 where transitions Zone -> Unzoned and Unzoned -> Zone causing zoneChanged = true and dropping the https://github.com/0x2142/frigate-notify/blob/main/events/mqtt.go#L109 logic due to !zoneChanged didn't happen.

Firstly, good question here: is this Zone <-> Unzoned logic also treated as a zone change or is it just a small design gap, especially since the unzoned: allow parameter is set by default.

Secondly, realizing the difficulty of how to properly calculate zoned and unzoned events that are too close to each other, even if they come as two different event records, I feel that the key answer may be stored in event.After.Region[] coordinates.
Some algorithm for calculating the distance between polygons may be needed here: smaller numbers may mean that the object is simply moving from a zoned region to an unzoned region and vice versa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants