Difference between revisions of "AxisMotionDetection"

From ZoneMinder Wiki
Jump to navigationJump to search
(18 intermediate revisions by 10 users not shown)
Line 1: Line 1:
I had this performance problem while monitoring and event recording for 8-10 IP cameras using the ZM.
I had this performance problem while monitoring and event recording for 8-10 IP cameras using the ZM.
ZM is too good a software to abandon just for performance issues. So I decided I should pay more attention to the motion detection feature of the cameras I have and relieve the ZM server from the task of detecting motion.
ZM is too good a software to abandon just for performance issues. So I decided I should pay more attention to the motion detection feature of the cameras I have and relieve the ZM server from the task of detecting motion.
I've finally managed to use the on-camera motion detection feature of Axis Cams and here are my notes:
I've finally managed to use the on-camera motion detection feature of Axis Cams and here are my notes:


== Cameras ==
I've set my Axis camera as follows:
I've set my Axis camera as follows:


Line 19: Line 19:


The ZM specs tells us that the format of the message can include a "duration" as long as the message is sent as:
The ZM specs tells us that the format of the message can include a "duration" as long as the message is sent as:
"1|on+5|5|cause|text|showtext" bu the problem is the Axis camera cannot or will not save the "+" sign which appears in the message. A CGI parameter conversion problem I presume...
"1|on+5|5|cause|text|showtext" but the problem is the Axis camera cannot or will not save the "+" sign which appears in the message. A CGI parameter conversion problem I presume...
 
 
'''[Update] The Axis M3203 with firmware 5.40.9.2 will save the "+" sign. My guess is that the new firmware has fixed this issue. Try updating your firmware before modifying the zmtrigger.pl file.'''
 


I've taken care of this "+" problem with a small modification in zmtrigger.pl source (see below).
I've taken care of this "+" problem with a small modification in zmtrigger.pl source (see below).
Line 30: Line 34:
The second important setup is the "motion detection" setup on the Axis. I created a window which covers the area of interest; kept the object size as small as possible, pulled the history slider all the way back to zero and left the sensitivity slide somewhere past the %50 value.
The second important setup is the "motion detection" setup on the Axis. I created a window which covers the area of interest; kept the object size as small as possible, pulled the history slider all the way back to zero and left the sensitivity slide somewhere past the %50 value.


== ZM settings ==


Now to the ZM settings...


There is no special setting for the ZM except that I've assigned the "Nodect" function to my camera monitor.
There is no special setting for the ZM except that I've assigned the "Nodect" function to my camera monitor.


[[Image:AxisMDetect5.png]]
[[Image:AxisMDetect5.png]]
'''[Update]Try updating your firmware before modifying the zmtrigger.pl file.'''




Line 43: Line 49:


Code:
Code:
sub handleMessage
        sub handleMessage{
{
         my $connection = shift;
         my $connection = shift;
         my $message = shift;
         my $message = shift;
Line 64: Line 69:


Code:
Code:
use ZoneMinder::Trigger::Channel::Inet;
        use ZoneMinder::Trigger::Channel::Inet;
#CUA use ZoneMinder::Trigger::Channel::Unix;
        #CUA use ZoneMinder::Trigger::Channel::Unix;
#CUA use ZoneMinder::Trigger::Channel::Serial;
        #CUA use ZoneMinder::Trigger::Channel::Serial;
use ZoneMinder::Trigger::Connection;
          use ZoneMinder::Trigger::Connection;


my @connections;
        my @connections;
push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan1", channel=>ZoneMinder::Trigger::Channel::Inet->new( port=>6802 ), mode=>"rw" ) );
        push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan1", channel=>ZoneMinder::Trigger::Channel::Inet->new( port=>6802 ), mode=>"rw" ) );
#CUA push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan2", channel=>ZoneMinder::Trigger::Channel::Unix->new( path=>'/tmp/test.sock' ), mode=>"rw" ) );
        #CUA push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan2", channel=>ZoneMinder::Trigger::Channel::Unix->new( path=>'/tmp/test.sock' ),         mode=>"rw" ) );
#push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan3", channel=>ZoneMinder::Trigger::Channel::File->new( path=>'/tmp/zmtrigger.out' ), mode=>"w" ) );
        #push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan3", channel=>ZoneMinder::Trigger::Channel::File->new( path=>'/tmp/zmtrigger.out' ), mode=>"w" ) );
#CUA push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan4", channel=>ZoneMinder::Trigger::Channel::Serial->new( path=>'/dev/ttyS0' ), mode=>"rw" ) );
        #CUA push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan4", channel=>ZoneMinder::Trigger::Channel::Serial->new( path=>'/dev/ttyS0' ), mode=>"rw" ) );




Line 84: Line 89:


Code:
Code:
"1|on 25|5|cause|text|showtext"
        "1|on 25|5|cause|text|showtext"




Line 90: Line 95:


Code:
Code:
1|on+25|5|cause|text|showtext
        1|on+25|5|cause|text|showtext




and of course, you shouln"t forget to restart zmtrigger.pl; or better still modify the zm startup script so that it starts zmtrigger.pl everytime zm is [re]started.
and of course, you shouln"t forget to restart zmtrigger.pl; or better still modify the zm startup script so that it starts zmtrigger.pl everytime zm is [re]started.
Note: If you plan to use the zmxap interface (to connect ZoneMinder to MisterHouse using xAP), your cause must be "Motion" (without quotes), and your text must be a single word (no spaces); eg: LAWN.  In Misterhouse, the camera name will be the MONITOR name (eg: FRONT_DOOR), and the zone name will be the text (eg: LAWN).  If you don't follow this convention then MisterHouse will not respond to the xAP event messages <span class="plainlinks">[http://www.learn-esm.co.uk/accommodation.php<span style="color:black;font-weight:normal; text-decoration:none!important; background:none!important; text-decoration:none;">Intensive Driving Courses London</span>] properly.


I added the line '/usr/bin/zmtrigger.pl &" in the start section of
I added the line '/usr/bin/zmtrigger.pl &" in the start section of
Line 100: Line 107:
Code:
Code:


start() {
        start() {
         echo -n "Starting $prog: "
         echo -n "Starting $prog: "
         $command start
         $command start
Line 113: Line 120:
         [ $RETVAL = 0 ] && touch /var/lock/zm
         [ $RETVAL = 0 ] && touch /var/lock/zm
         return $RETVAL
         return $RETVAL
}
        }
stop() {
        stop() {
         echo -n $"Stopping $prog: "
         echo -n $"Stopping $prog: "
         #
         #
Line 132: Line 139:


Again; many thanks to those people who developed ZM at the first place and to those who helped it to become a perfect opensource project.
Again; many thanks to those people who developed ZM at the first place and to those who helped it to become a perfect opensource project.
[http://www.zoneminder.com/forums/viewtopic.php?t=10872 Original Thread]
'''DO NOT PM THESE USERS ""just post a question in the forum'
Copied By: KingOfKYA
Created By: cayfer
Edited / Updated By: TheForce

Revision as of 10:59, 22 December 2015

I had this performance problem while monitoring and event recording for 8-10 IP cameras using the ZM. ZM is too good a software to abandon just for performance issues. So I decided I should pay more attention to the motion detection feature of the cameras I have and relieve the ZM server from the task of detecting motion. I've finally managed to use the on-camera motion detection feature of Axis Cams and here are my notes:

Cameras

I've set my Axis camera as follows:

AxisMDetect1.png AxisMDetect2.png


The text "1|on 5|5|cause|text|showtext" means that alarm will be triggered for the monitor which has ID=1, alarm will set recording on alarm will be cleared after 5 seconds. The score of the alarm is 5 ( any score >0 is OK) "text" and "showtext" are just explanatory notes.

The ZM specs tells us that the format of the message can include a "duration" as long as the message is sent as: "1|on+5|5|cause|text|showtext" but the problem is the Axis camera cannot or will not save the "+" sign which appears in the message. A CGI parameter conversion problem I presume...


[Update] The Axis M3203 with firmware 5.40.9.2 will save the "+" sign. My guess is that the new firmware has fixed this issue. Try updating your firmware before modifying the zmtrigger.pl file.


I've taken care of this "+" problem with a small modification in zmtrigger.pl source (see below).

Next, I specified the host IP address of the zm computer and its default zmtrigger port of 6802.

AxisMDetect3.png AxisMDetect4.png

The second important setup is the "motion detection" setup on the Axis. I created a window which covers the area of interest; kept the object size as small as possible, pulled the history slider all the way back to zero and left the sensitivity slide somewhere past the %50 value.

ZM settings

There is no special setting for the ZM except that I've assigned the "Nodect" function to my camera monitor.

AxisMDetect5.png


[Update]Try updating your firmware before modifying the zmtrigger.pl file.


Finally, I modified the zmtrigger.pl file so that the first few lines of the function handleMessage looks like this:

Code:

        sub handleMessage{
       my $connection = shift;
       my $message = shift;
       #
       #  CUA  - Axis camera send the message quoted with"
       #  CUA  - Also Axis camera cannot save the plus sign which
       #  CUA  - possibly exists in the 1|on+20|score|cause|text|showtext formatted msg
       $message=~ s/^\"//g;
       $message=~ s/\"$//g;
       $message=~ s/on /on\+/;
       #  CUA - end of modifications
       my ( $id, $action, $score, $cause, $text, $showtext ) = split( /\|/, $message );


a few other modifications I made in the zmtrigger.pl file are commenting out some unused modules and pushes:

Code:

       use ZoneMinder::Trigger::Channel::Inet;
       #CUA use ZoneMinder::Trigger::Channel::Unix;
       #CUA use ZoneMinder::Trigger::Channel::Serial;
          use ZoneMinder::Trigger::Connection;
        my @connections;
        push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan1", channel=>ZoneMinder::Trigger::Channel::Inet->new( port=>6802 ), mode=>"rw" ) );
        #CUA push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan2", channel=>ZoneMinder::Trigger::Channel::Unix->new( path=>'/tmp/test.sock' ),         mode=>"rw" ) );
       #push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan3", channel=>ZoneMinder::Trigger::Channel::File->new( path=>'/tmp/zmtrigger.out' ), mode=>"w" ) );
        #CUA push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan4", channel=>ZoneMinder::Trigger::Channel::Serial->new( path=>'/dev/ttyS0' ), mode=>"rw" ) );


my modifs are marked with "# CUA"


These three regular expressions remove the quotes sent by Axis which envelope the message string and insert a plus sign if the "on" command is followed by a space). These 3 statements convert an incoming message of the form

Code:

       "1|on 25|5|cause|text|showtext"


to

Code:

       1|on+25|5|cause|text|showtext


and of course, you shouln"t forget to restart zmtrigger.pl; or better still modify the zm startup script so that it starts zmtrigger.pl everytime zm is [re]started.

Note: If you plan to use the zmxap interface (to connect ZoneMinder to MisterHouse using xAP), your cause must be "Motion" (without quotes), and your text must be a single word (no spaces); eg: LAWN. In Misterhouse, the camera name will be the MONITOR name (eg: FRONT_DOOR), and the zone name will be the text (eg: LAWN). If you don't follow this convention then MisterHouse will not respond to the xAP event messages Intensive Driving Courses London properly.

I added the line '/usr/bin/zmtrigger.pl &" in the start section of /etc/init.d/zoneminder and also added the line "pkill zmtrigger.pl" in the stop section.

Code:

       start() {
       echo -n "Starting $prog: "
       $command start
       # CUA
       /usr/bin/zmtrigger.pl &


       RETVAL=$?
       [ $RETVAL = 0 ] && echo success
       [ $RETVAL != 0 ] && echo failure
       echo
       [ $RETVAL = 0 ] && touch /var/lock/zm
       return $RETVAL
       }
       stop() {
       echo -n $"Stopping $prog: "
       #
       # Why is this status check being done?
       # as $command stop returns 1 if zoneminder
       # is stopped, which will result in
       # this returning 1, which will stuff
       # dpkg when it tries to stop zoneminder before
       # uninstalling . . .
       #
       # CUA
       pkill zmtrigger.pl


I just hope that this helps other people trying to implement the on-camera motion detection with ZM.

Again; many thanks to those people who developed ZM at the first place and to those who helped it to become a perfect opensource project.

Original Thread


DO NOT PM THESE USERS ""just post a question in the forum'

Copied By: KingOfKYA

Created By: cayfer

Edited / Updated By: TheForce