Add LInked Event Trigger Id and Object Score to Events

Anything you want added or changed in future versions of ZoneMinder? Post here and there's a chance it will get in! Search to make sure it hasn't already been requested.
Post Reply
russell_i_brown
Posts: 42
Joined: Wed Mar 18, 2009 9:46 am
Location: Peterborough, England
Contact:

Add LInked Event Trigger Id and Object Score to Events

Post by russell_i_brown » Mon Feb 03, 2020 12:03 pm

I'm using Asker's most excellent zmeventnotification Object Detection stuff with the end goal of removing all events that did not have an object detected so that I'm not looking at endless events triggered by Bats'n'Bugs :) For the record, I'm also recording the high-res streams without detection as a fallback.

Asker's Object Detection adds a detected string to the Events Notes field so that one ends up with something like "[a] detected;car:87% Motion: Gate Closeup".

This works very well for single Monitors as I can, albeit inefficiently from the Db perspective searching for strings in text fields :| , delete all events that do not have "detected:" in the Notes.

However, this goes horribly wrong for linked Monitors.

I have Monitor A which is a closeup of the entrance gate linked to Monitors B & C which give a wider angle view.

When Monitor A gets a motion trigger, Monitors B&C trigger and get a cause of "Linked" and "Linked: House Gate" in the Notes field but there is no mechanism for determining which event Id on Monitor A was the trigger. Asker's Objection Detection runs on Monitor A and, if an object is found, changes the Notes field appropriately for the triggering event but obviously not for the linked events on B&C - because it can't determine which ones they are.

This means that my filter on "detected:" will delete the events on Monitors B&C thereby negating the purpose of having the linkage :(

What I'm proposing is that Events gets a couple more fields like so:

Code: Select all

alter table Events add column LinkedId bigint(20) unsigned default 0 after SecondaryStorageId;
alter table Events add column ObjectScore tinyint(3) unsigned NOT NULL DEFAULT '0' after MaxScore;
create index Events_LinkedId_idx on Events(LinkedId);
create index Events_ObjectScore_idx on Events(ObjectScore);
Asker's Object Detection code could then simply do something like:

Code: Select all

update Events set Notes=CONCAT(Notes,<detect string>) where LinkedId=<ThisEventId>
I'm also suggesting adding an ObjectScore field (like the existing MaxScore, TotScore etc) so that Asker's code could record the detection confidence percentage for the event. This would allow filters to be based on the Object Score. The sql in Asker's code would then become:

Code: Select all

update Events set Notes=CONCAT(Notes,<detect string>), ObjectScore=<objectscore> where LinkedId=<ThisEventId>
I have raised this with Asker and he suggested putting it as an enhancement request... so I am :)

FWIW, I have looked at monitor.cpp where it sets LINKED_CAUSE for the linked monitor's events but my understanding of the code structure is zero so I'm not confident enough to propose a patch but I'm more than happy to contribute with testing code written by someone who does know what they're doing :)

User avatar
iconnor
Posts: 1195
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: Add LInked Event Trigger Id and Object Score to Events

Post by iconnor » Mon Feb 03, 2020 4:31 pm

Mostly looks ok to me,

One thing, don't add an index on ObjectScore.. adding indexes adds more work for the db to do on every insert and update, and we are likely to be filtering on something else that is already indexed, like StartTime.

russell_i_brown
Posts: 42
Joined: Wed Mar 18, 2009 9:46 am
Location: Peterborough, England
Contact:

Re: Add LInked Event Trigger Id and Object Score to Events

Post by russell_i_brown » Mon Feb 03, 2020 6:14 pm

I was suggesting an index on ObjectScore so that one could run a filter more efficiently for events that do not have an object detected. Yes I realise this would mean extending the filters to include ObjectScore.

Code: Select all

Select Id from Events where ObjectScore > 10;
where ObjectScore is indexed seems a lot kinder on the Db than

Code: Select all

Select Id from Events where Notes like "%detected:%";
where the Db has to do a sequential read of each row and a strstr on Notes.

Yup a quick extension of the fields as suggested and I get this on my little test rig:

Code: Select all

MariaDB [zm]> explain select Id from Events where Notes like "%detected:%";
+------+-------------+--------+------+---------------+------+---------+------+------+-------------+
| id   | select_type | table  | type | possible_keys | key  | key_len | ref  | rows | Extra       |
+------+-------------+--------+------+---------------+------+---------+------+------+-------------+
|    1 | SIMPLE      | Events | ALL  | NULL          | NULL | NULL    | NULL | 4022 | Using where |
+------+-------------+--------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)

MariaDB [zm]> explain select Id from Events where ObjectScore > 30;
+------+-------------+--------+-------+------------------------+------------------------+---------+------+------+--------------------------+
| id   | select_type | table  | type  | possible_keys          | key                    | key_len | ref  | rows | Extra                    |
+------+-------------+--------+-------+------------------------+------------------------+---------+------+------+--------------------------+
|    1 | SIMPLE      | Events | range | Events_ObjectScore_idx | Events_ObjectScore_idx | 1       | NULL |    1 | Using where; Using index |
+------+-------------+--------+-------+------------------------+------------------------+---------+------+------+--------------------------+
1 row in set (0.00 sec)
MariaDB [zm]> 
and I'd guess that the index wouldn't be any kind of load if Object Detection isn't being used as there won't be any entries in it.

prplhaz4
Posts: 1
Joined: Fri Mar 13, 2020 7:37 pm

Re: Add LInked Event Trigger Id and Object Score to Events

Post by prplhaz4 » Tue Jul 07, 2020 7:50 pm

Did you get anywhere with this? I'm guessing adding the linked event id might be the first step towards also being able to delete linked events (rather than deleting every event twice - once on Modect cam and once on Nodect cam)...

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests