zmeventnotification make it to analyze not only snapshot and bestmatch

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
ranger21
Posts: 16
Joined: Fri Dec 04, 2020 4:55 am

zmeventnotification make it to analyze not only snapshot and bestmatch

Post by ranger21 »

Hello everyone!
Sorry if that's not related to zoneminder, but to zmeventnotification. Is there any easy way to make zmeventnotification to proceed all frames of video on certain monitors? Or maybe at least on all monitors ? I'm missing some events due to snapshot or alarm frames being (i've already wait 60 seconds after event ends to get all frames) without objects, but on video\all frames there is almost always desired object to catch.

I have Ryzen 3900x with 8 cores dedicated to VM with zoneminder and 14 cameras with modect feeds with saving all jpeg frames, and im willing to get videocard for object-detection for all frames, if performance would be bad for analyzing all frames. Although i don't care about real-time performance, even 10 minute delay for getting proper object detection is important for me.

Reason why i don't want to analyse all frames on all monitors because in snow or rain YOLOV4(and V3) sometimes randomly detects fake objects. I don't want false positives on certain monitors.

I would accept even any hacky solution with settings right in python script, but im too stupid to rewrite zm_detect.py by myself and related scripts.
Maybe someone already has such solution?
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: zmeventnotification make it to analyze not only snapshot and bestmatch

Post by asker »

Short hack:
See https://github.com/pliablepixels/zmeven ... issues/313

The longer term/better performant/more options way:
Feel free to follow the work going on here
pyzm is the core part that does all this.

I am currently running a version of the detection framework that is doing what you want. It's bleeding edge, and its checked into a script called 'zm_detect2' here which will eventually replace zm_detect.py. It is currently hardcoded with several options (see here but if you like tinkering replace your startscript with zm_detect2.py and experiment. However, I'm not going to be able to answer usage questions for now, so tinker only if you are comfortable.
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
ranger21
Posts: 16
Joined: Fri Dec 04, 2020 4:55 am

Re: zmeventnotification make it to analyze not only snapshot and bestmatch

Post by ranger21 »

asker wrote: Fri Dec 04, 2020 10:16 am Short hack:
See https://github.com/pliablepixels/zmeven ... issues/313

The longer term/better performant/more options way:
Feel free to follow the work going on here
pyzm is the core part that does all this.

I am currently running a version of the detection framework that is doing what you want. It's bleeding edge, and its checked into a script called 'zm_detect2' here which will eventually replace zm_detect.py. It is currently hardcoded with several options (see here but if you like tinkering replace your startscript with zm_detect2.py and experiment. However, I'm not going to be able to answer usage questions for now, so tinker only if you are comfortable.
Thank you! That's exactly what I was looking for. I'll for now use hacky solution with shell script with tuning. And when I have time i'll setup ML server for zm_detect2 script.
ranger21
Posts: 16
Joined: Fri Dec 04, 2020 4:55 am

Re: zmeventnotification make it to analyze not only snapshot and bestmatch

Post by ranger21 »

I've made small adjustment for hacky solution to divide event for 10 analysable frames depending on maximum frame count:
It's very ugly and i don't encourage anyone to use it, but it works for me for now. Maybe will be useful for someone who's also lazy (don't have time?)to setup MLAPI server. It really increases detection rate for me up to 20%!

zm_event_start_custom.sh

#!/bin/bash

CONFIG_FILE="/etc/zm/objectconfig.ini"
ALT_CONFIG_FILE="/dev/shm/objectconfig.ini-${RANDOM}"
EVENT_PATH="$5"
REASON="$4"

DETECTION_SCRIPT=(/var/lib/zmeventnotification/bin/zm_detect.py --monitorid $2 --eventid $1 --config "${CONFIG_FILE}" --eventpath "${EVENT_PATH}" --reason "${REASON}" )

RESULTS=$("${DETECTION_SCRIPT[@]}" | grep "detected:")

curl -s -XPOST -d "user=YOURSLOGIN&pass=YOURPASSWORD&stateful=1" -L -c cookies.txt http://localhost/zm/api/host/login.json > /dev/null
#Dunno why, but getting straight to event doesn't work if i don't call monitors
curl -s -b cookies.txt -L -XGET http://localhost/zm/api/monitors.json > dev/null
MAX_FRAMES=$(curl -s -b cookies.txt http://localhost/zm/api/events/$1.json | python -c "import sys, json; print json.load(sys.stdin)['event']['Event']['Frames']")

i=0
FPS=$(expr $MAX_FRAMES / 10)
if [ -z "${$MAX_FRAMES}" ]; then
FPS=10
fi

while [[ -z "${RESULTS}" && $i -lt 9 ]]; do
FRAME_ID=$((FPS+i*FPS))
sed "s/frame_id=bestmatch/frame_id=${FRAME_ID}/" $CONFIG_FILE > $ALT_CONFIG_FILE
DETECTION_SCRIPT=(/var/lib/zmeventnotification/bin/zm_detect.py --monitorid $2 --eventid $1 --config "${ALT_CONFIG_FILE}" --eventpath "${EVENT_PATH}" --reason "${REASON}" )
RESULTS=$("${DETECTION_SCRIPT[@]}" | grep "detected:")
i=$((i+1))
done

rm -f $ALT_CONFIG_FILE

_RETVAL=1
# The script needs to return a 0 for success ( detected) or 1 for failure (not detected)
if [[ ! -z "${RESULTS}" ]]; then
_RETVAL=0
fi
echo ${RESULTS}
exit ${_RETVAL}
ranger21
Posts: 16
Joined: Fri Dec 04, 2020 4:55 am

Re: zmeventnotification make it to analyze not only snapshot and bestmatch

Post by ranger21 »

asker wrote: Fri Dec 04, 2020 10:16 am Short hack:
See https://github.com/pliablepixels/zmeven ... issues/313

The longer term/better performant/more options way:
Feel free to follow the work going on here
pyzm is the core part that does all this.

I am currently running a version of the detection framework that is doing what you want. It's bleeding edge, and its checked into a script called 'zm_detect2' here which will eventually replace zm_detect.py. It is currently hardcoded with several options (see here but if you like tinkering replace your startscript with zm_detect2.py and experiment. However, I'm not going to be able to answer usage questions for now, so tinker only if you are comfortable.
i've setup mlapi server and tried previous zm_detect2 version, but still no luck to run with video stream.
Could you atleast give minor example of congirutaion how to run it with video stream (skipping frames, etc)? I saw yesterday were made commits to pyzm and zm_detect2 for moving most of configuration outside of zm_detect2
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: zmeventnotification make it to analyze not only snapshot and bestmatch

Post by asker »

Mlapi doesn’t work with zmdetect2. It’s only for local detection so far. Sorry if I did Not mention that above. The examples are all in pyzm - see stream.py. The links I provided above also give you the he examples you are looking for.
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
ranger21
Posts: 16
Joined: Fri Dec 04, 2020 4:55 am

Re: zmeventnotification make it to analyze not only snapshot and bestmatch

Post by ranger21 »

Oh, that comment in code got me confused
# This uses mlapi (https://github.com/pliablepixels/mlapi) to run inferencing and converts format to what is required by the rest of the code.


So in example i need to just comment out frame_set and uncomment video related settings?

stream_options = {
'frame_skip':2,
'start_frame': 1,
'max_frames':10,
'strategy': 'most_models',
#'strategy': 'first',
'api': zmapi,
'download': False,
#'frame_set': 'snapshot,alarm',
'resize': 800
}

welp, i need to upgrade pyzm to master version... and probably zmeventnotification to master too?

Probably i'll just wait when everything comes to stable version and into docker version of zoneminder from dlandon. Hacky solution with dividing and analyzing to 20 frames based on maximum amount of frames in event works for me now.
ranger21
Posts: 16
Joined: Fri Dec 04, 2020 4:55 am

Re: zmeventnotification make it to analyze not only snapshot and bestmatch

Post by ranger21 »

I've made new version of script for EventNotification server 6.1.0
It will now add to regular 'frame_set': 'snapshot,alarm' 20 frames divided from max amount of frames from event. On event start it will now truly wait until MAX_FRAME is settled (so event stops writing) for event. Old script worked with wait= section of monitor and if event was very long it wouldn't analyse from real max frame.

Hope that this script helps someone. It really increases detection rate of cars at night when lights trigger alarm first and not only that...
Attachments
zm_event_start_custom.rar
(917 Bytes) Downloaded 340 times
Post Reply