Using Motion Detection To Determine Object Movement Direction
-
- Posts: 19
- Joined: Thu Jul 06, 2017 1:35 am
Using Motion Detection To Determine Object Movement Direction
With this post I'm *not* asking for very specific instructions on how to do what I describe. I would be interested, however, in people's opinions on overall approach and whether I'm looking at this as the right way to solve my problem.
I have one camera - trained on a railroad track. My goal is to capture the event of a train going by, as well as determining what direction the train is traveling (i.e. is the train going left-to-right or right-to-left?).
I've set up two monitor (Exclusive) zones - both defined on the track. For the sake of this post - let's say Zone1 is on the left of the frame and Zone2 is on the right of the frame. These zones do not overlap at all. I think I'm learning that *which* zone triggers an alarm is placed in the logs - not in the Alarm that is documented in the browser UI. So I'm assuming / figuring I need to scrape the logs and figure out which Zone triggered first, and then that would give me my answer of train direction. E.g......If Zone1 alarms before Zone2 then I can conclude the train is going left to right.
Is this the best approach to determine direction of movement.....looking at this info in the logs? Or is there some easier way configuring motion detection zones that could figure this out?
Thanks.
Jim
I have one camera - trained on a railroad track. My goal is to capture the event of a train going by, as well as determining what direction the train is traveling (i.e. is the train going left-to-right or right-to-left?).
I've set up two monitor (Exclusive) zones - both defined on the track. For the sake of this post - let's say Zone1 is on the left of the frame and Zone2 is on the right of the frame. These zones do not overlap at all. I think I'm learning that *which* zone triggers an alarm is placed in the logs - not in the Alarm that is documented in the browser UI. So I'm assuming / figuring I need to scrape the logs and figure out which Zone triggered first, and then that would give me my answer of train direction. E.g......If Zone1 alarms before Zone2 then I can conclude the train is going left to right.
Is this the best approach to determine direction of movement.....looking at this info in the logs? Or is there some easier way configuring motion detection zones that could figure this out?
Thanks.
Jim
Re: Using Motion Detection To Determine Object Movement Direction
interesting. I would think that locating the function that deals with the actual alarm generation and using that to determine the order of alarm. Not using the logs at all but a more direct method. There is the possibility of using (for example) an Exclusive Zone and an Active Zone....one left one right. Perhaps the combination of these can determine the direction. Since the Exclusive Zone if active first will cancel the Active Zone.
This is a pretty good problem to solve and I look forward to seeing the different solutions!!
This is a pretty good problem to solve and I look forward to seeing the different solutions!!
Re: Using Motion Detection To Determine Object Movement Direction
Just an idea:
Two monitors with same source:
Monitor 1 with Exclusive and Active Zone and Preclusive Zone, side by side, detecting train from the left
Monitor 2 with Preclusive Zone and Active Zone and Exclusive Zone, detecting train from the right
Regards,
Ulrich
Edit: added Preclusive Zones, changed left/right
Two monitors with same source:
Monitor 1 with Exclusive and Active Zone and Preclusive Zone, side by side, detecting train from the left
Monitor 2 with Preclusive Zone and Active Zone and Exclusive Zone, detecting train from the right
Regards,
Ulrich
Edit: added Preclusive Zones, changed left/right
-
- Posts: 19
- Joined: Thu Jul 06, 2017 1:35 am
Re: Using Motion Detection To Determine Object Movement Direction
Thanks for the ideas.
I think I'm concluding (I'm new to ZM) that when an alarm occurs for a camera there is nothing in the alarm data itself that identifies *which* zone triggered the alarm, correct? I guess another way to ask that question: When an alarm occurs all we know is that an alarm occurred for that camera. Of all the myriads and types of zones that can be set up on a camera, when those conditions are satisfied an alarm is generated, with really no detailed data as to why the alarm was generated. Is that the case?
I'll definitely look into the suggestions above. But my lazy side is wondering if I shouldn't just go get another camera. LOL. I'd have one trained on one end of the tracks and the other on the other. Then I could just compare alarm times. But....my geeky / automation side of my brain wants to figure out how to do this with one camera.
Thanks.
Jim
I think I'm concluding (I'm new to ZM) that when an alarm occurs for a camera there is nothing in the alarm data itself that identifies *which* zone triggered the alarm, correct? I guess another way to ask that question: When an alarm occurs all we know is that an alarm occurred for that camera. Of all the myriads and types of zones that can be set up on a camera, when those conditions are satisfied an alarm is generated, with really no detailed data as to why the alarm was generated. Is that the case?
I'll definitely look into the suggestions above. But my lazy side is wondering if I shouldn't just go get another camera. LOL. I'd have one trained on one end of the tracks and the other on the other. Then I could just compare alarm times. But....my geeky / automation side of my brain wants to figure out how to do this with one camera.
Thanks.
Jim
Re: Using Motion Detection To Determine Object Movement Direction
each zone set up is named. this is for debug purposes. But could possibly be used to see which zone alarmed in what order by the zone names. The first zone is always called "All" for example.
- knight-of-ni
- Posts: 2406
- Joined: Thu Oct 18, 2007 1:55 pm
- Location: Shiloh, IL
Re: Using Motion Detection To Determine Object Movement Direction
Open an event list, click on the Cause for any given event (mine says "Motion"), and there in the Notes field you will see the name of the zone which triggered the alarm.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
All of these can be found at https://zoneminder.blogspot.com/
Re: Using Motion Detection To Determine Object Movement Direction
there is a PERL script that I think can be modified to run as a daemon and can do this. the script is called zm-alarm.pl
I have modified this to check for zero events by individual cameras as well as other things.
easy to create a daemon from this and I have some examples shown in other threads in this forum.
viewtopic.php?p=99818#p99818
Code: Select all
#!/usr/bin/env perl
# While this script is running, it will print out the state of each alarm on the system.
# This script is an example of calling external scripts in reaction to a
# monitor changing state. Simply replace the print() commands with system(),
# for example, to call external scripts.
use strict;
use warnings;
use ZoneMinder;
use Switch;
$| = 1;
my @monitors;
my $dbh = zmDbConnect();
my $sql = "SELECT * FROM Monitors";
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or die( "Can't execute '$sql': ".$sth->errstr() );
while ( my $monitor = $sth->fetchrow_hashref() ) {
push( @monitors, $monitor );
}
while (1) {
foreach my $monitor (@monitors) {
my $monitorState = zmGetMonitorState($monitor);
printState($monitor->{Id}, $monitor->{Name}, $monitorState);
}
sleep 1;
}
sub printState {
my ($monitor_id, $monitor_name, $state) = @_;
my $time = localtime();
switch ($state) {
case 0 { print "$time - $monitor_name:\t Idle!\n" }
case 1 { print "$time - $monitor_name:\t Prealarm!\n" }
case 2 { print "$time - $monitor_name:\t Alarm!\n" }
case 3 { print "$time - $monitor_name:\t Alert!\n" }
}
}
easy to create a daemon from this and I have some examples shown in other threads in this forum.
viewtopic.php?p=99818#p99818
Re: Using Motion Detection To Determine Object Movement Direction
This is helpful!Open an event list, click on the Cause for any given event (mine says "Motion"), and there in the Notes field you will see the name of the zone which triggered the alarm.
-
- Posts: 19
- Joined: Thu Jul 06, 2017 1:35 am
Re: Using Motion Detection To Determine Object Movement Direction
Awesome. Thanks.knnniggett wrote: ↑Fri Jul 07, 2017 1:59 pm Open an event list, click on the Cause for any given event (mine says "Motion"), and there in the Notes field you will see the name of the zone which triggered the alarm.
-
- Posts: 19
- Joined: Thu Jul 06, 2017 1:35 am
Re: Using Motion Detection To Determine Object Movement Direction
A quick follow-up:
I appear to be WELL on my way to solving this problem using both suknil's and rockedge's responses.
I've set up two monitors on the one camera. One has an active area prior to a preclusive, and the other the other way around.
And I'm using rockedge's perl script to continuously monitor both monitors.
The only testing I've been able to do is passing my hand in front of the camera in either direction to see if one stays Idle while the other Alerts. It seems to be working correctly. Now I need some real trains to come by to see if it's REALLY working.
Thanks so much for all the help! It is invaluable!
Jim
I appear to be WELL on my way to solving this problem using both suknil's and rockedge's responses.
I've set up two monitors on the one camera. One has an active area prior to a preclusive, and the other the other way around.
And I'm using rockedge's perl script to continuously monitor both monitors.
The only testing I've been able to do is passing my hand in front of the camera in either direction to see if one stays Idle while the other Alerts. It seems to be working correctly. Now I need some real trains to come by to see if it's REALLY working.
Thanks so much for all the help! It is invaluable!
Jim
Re: Using Motion Detection To Determine Object Movement Direction
Nice!
any trains come by yet?
any trains come by yet?
-
- Posts: 19
- Joined: Thu Jul 06, 2017 1:35 am
Re: Using Motion Detection To Determine Object Movement Direction
Of all the times/weekends to have a reduced train schedule - this appears to be it. I think I've had two, maybe three, come by since my post above - which was 24 hours ago. (Normally we get 6-8 trains a day.)
I'm definitely in the "get the sensitivity settings right" mode. I had a bunch of false positives (lots of wind yesterday....for some reason blowing grass is a train. ROFL) so I made things less sensitive. Most recently I've had a false negative. So I've got to figure out the optimum settings.
Hopefully what will work well (I think I'm lucky in that regard) is that where the train (motion) goes is extremely predictable.
Jim
I'm definitely in the "get the sensitivity settings right" mode. I had a bunch of false positives (lots of wind yesterday....for some reason blowing grass is a train. ROFL) so I made things less sensitive. Most recently I've had a false negative. So I've got to figure out the optimum settings.
Hopefully what will work well (I think I'm lucky in that regard) is that where the train (motion) goes is extremely predictable.
Jim
-
- Posts: 19
- Joined: Thu Jul 06, 2017 1:35 am
Re: Using Motion Detection To Determine Object Movement Direction
OK....I'd like to keep digging into this....the next level of understanding, if you will.
I just had a train go by. It generated 14 Alerts. But I believe most significantly, the *first* event of the 14 was raised by the correct sensor detecting which way the train was going. But out of the total of 14 Alerts both sensors were tripped.
My sensors are labeled SB (Southbound) and NB (Northbound). I had a SB train...and the first Alert was by the SB sensor. So far so good.
I've included a screen grab of my SB motion detection setup. (This camera is looking east - so southbound is left-to-right.) The red zone is an active zone. And the blue zone is a Preclusive zone. The NB sensor is set up exactly opposite of the SB configuration.
I get that for a southbound train it'll enter the red area first of the SB sensor- which will cause an alarm. That's perfect. But how does that SB sensor behave when it shows motion in BOTH the Active and Preclusive zones? Obviously trains are long.....so I'll be having motion in both for the sensor as the train goes by.
Since for the NB sensor it did not raise an alarm as the southbound train came down the tracks, but as the train went by I was getting NB alerts. I can ignore these as long as I know the *first* alert is by the correct sensor. But I am interesting in understanding how things are handled when motion occurs in Active and Preclusive zones for the same frame.
Thanks.
Jim
I just had a train go by. It generated 14 Alerts. But I believe most significantly, the *first* event of the 14 was raised by the correct sensor detecting which way the train was going. But out of the total of 14 Alerts both sensors were tripped.
My sensors are labeled SB (Southbound) and NB (Northbound). I had a SB train...and the first Alert was by the SB sensor. So far so good.
I've included a screen grab of my SB motion detection setup. (This camera is looking east - so southbound is left-to-right.) The red zone is an active zone. And the blue zone is a Preclusive zone. The NB sensor is set up exactly opposite of the SB configuration.
I get that for a southbound train it'll enter the red area first of the SB sensor- which will cause an alarm. That's perfect. But how does that SB sensor behave when it shows motion in BOTH the Active and Preclusive zones? Obviously trains are long.....so I'll be having motion in both for the sensor as the train goes by.
Since for the NB sensor it did not raise an alarm as the southbound train came down the tracks, but as the train went by I was getting NB alerts. I can ignore these as long as I know the *first* alert is by the correct sensor. But I am interesting in understanding how things are handled when motion occurs in Active and Preclusive zones for the same frame.
Thanks.
Jim
Re: Using Motion Detection To Determine Object Movement Direction
Interesting scenario. I am not sure yet what happens but I assume the Preclusive zone takes precedents. there needs to be some sort of timeout after the initial triggering of the Active zone....to allow for the length of the train. So when 1 Active zone is triggered no other zone in either monitor setup can go into an Alert. I am not sure this is at the moment possible but it will be interesting to find out what occurs when motion in a frame is spread out over multiple zones. It must happen other setups as well.
Re: Using Motion Detection To Determine Object Movement Direction
I would shrink the zones in order to minimize false alarms. Try to find an area without grass and bushes.
Regards,
Ulrich
Regards,
Ulrich