big ::Analyze logic cleanup. Also implement close continuous event before starting motion event in MOCORD

pull/2681/head
Isaac Connor 2019-06-13 15:48:41 -04:00
parent b073505146
commit 695bdfc1c6
1 changed files with 36 additions and 79 deletions

View File

@ -1378,6 +1378,7 @@ bool Monitor::Analyse() {
if ( trigger_data->trigger_state == TRIGGER_ON ) { if ( trigger_data->trigger_state == TRIGGER_ON ) {
score += trigger_data->trigger_score; score += trigger_data->trigger_score;
if ( !event ) { if ( !event ) {
// How could it have a length already?
if ( cause.length() ) if ( cause.length() )
cause += ", "; cause += ", ";
cause += trigger_data->trigger_cause; cause += trigger_data->trigger_cause;
@ -1405,40 +1406,41 @@ bool Monitor::Analyse() {
cause += SIGNAL_CAUSE; cause += SIGNAL_CAUSE;
} }
Event::StringSet noteSet; Event::StringSet noteSet;
noteSet.insert( signalText ); noteSet.insert(signalText);
noteSetMap[SIGNAL_CAUSE] = noteSet; noteSetMap[SIGNAL_CAUSE] = noteSet;
shared_data->state = state = IDLE; shared_data->state = state = IDLE;
shared_data->active = signal; shared_data->active = signal;
ref_image = *snap_image; ref_image = *snap_image;
} else if ( signal && Active() && (function == MODECT || function == MOCORD) ) { } else if ( signal ) {
Event::StringSet zoneSet; if ( Active() && (function == MODECT || function == MOCORD) ) {
if ( (!motion_frame_skip) || !(image_count % (motion_frame_skip+1) ) ) { // All is good, so add motion detection score.
// Get new score. Event::StringSet zoneSet;
int new_motion_score = DetectMotion(*snap_image, zoneSet); if ( (!motion_frame_skip) || !(image_count % (motion_frame_skip+1) ) ) {
// Get new score.
int new_motion_score = DetectMotion(*snap_image, zoneSet);
Debug(3, Debug(3,
"After motion detection, last_motion_score(%d), new motion score(%d)", "After motion detection, last_motion_score(%d), new motion score(%d)",
last_motion_score, new_motion_score last_motion_score, new_motion_score
); );
last_motion_score = new_motion_score; last_motion_score = new_motion_score;
}
if ( last_motion_score ) {
if ( !event ) {
score += last_motion_score;
if ( cause.length() )
cause += ", ";
cause += MOTION_CAUSE;
} else {
score += last_motion_score;
} }
noteSetMap[MOTION_CAUSE] = zoneSet; if ( last_motion_score ) {
} // end if motion_score score += last_motion_score;
shared_data->active = signal; if ( !event ) {
} // end if signal change if ( cause.length() )
cause += ", ";
cause += MOTION_CAUSE;
}
noteSetMap[MOTION_CAUSE] = zoneSet;
} // end if motion_score
//shared_data->active = signal; // unneccessary active gets set on signal change
} // end if active and doing motion detection
if ( (!signal_change) && signal) { // Check to see if linked monitors are triggering.
if ( n_linked_monitors > 0 ) { if ( n_linked_monitors > 0 ) {
// FIXME improve logic here
bool first_link = true; bool first_link = true;
Event::StringSet noteSet; Event::StringSet noteSet;
for ( int i = 0; i < n_linked_monitors; i++ ) { for ( int i = 0; i < n_linked_monitors; i++ ) {
@ -1499,62 +1501,20 @@ bool Monitor::Analyse() {
shared_data->state = state = TAPE; shared_data->state = state = TAPE;
} }
//if ( config.overlap_timed_events )
if ( false ) {
int pre_index;
int pre_event_images = pre_event_count;
if ( analysis_fps ) {
// If analysis fps is set,
// compute the index for pre event images in the dedicated buffer
pre_index = pre_event_buffer_count ? image_count%pre_event_buffer_count : 0;
// Seek forward the next filled slot in to the buffer (oldest data)
// from the current position
while ( pre_event_images && !pre_event_buffer[pre_index].timestamp->tv_sec ) {
pre_index = (pre_index + 1)%pre_event_buffer_count;
// Slot is empty, removing image from counter
pre_event_images--;
}
} else {
// If analysis fps is not set (analysis performed at capturing framerate),
// compute the index for pre event images in the capturing buffer
pre_index = ((index + image_buffer_count) - pre_event_count)%image_buffer_count;
// Seek forward the next filled slot in to the buffer (oldest data)
// from the current position
while ( pre_event_images && !image_buffer[pre_index].timestamp->tv_sec ) {
pre_index = (pre_index + 1)%image_buffer_count;
// Slot is empty, removing image from counter
pre_event_images--;
}
}
if ( pre_event_images ) {
if ( analysis_fps ) {
for ( int i = 0; i < pre_event_images; i++ ) {
timestamps[i] = pre_event_buffer[pre_index].timestamp;
images[i] = pre_event_buffer[pre_index].image;
pre_index = (pre_index + 1)%pre_event_buffer_count;
}
} else {
for ( int i = 0; i < pre_event_images; i++ ) {
timestamps[i] = image_buffer[pre_index].timestamp;
images[i] = image_buffer[pre_index].image;
pre_index = (pre_index + 1)%image_buffer_count;
}
}
event->AddFrames( pre_event_images, images, timestamps );
}
} // end if false or config.overlap_timed_events
} // end if ! event } // end if ! event
} // end if function == RECORD || function == MOCORD) } // end if function == RECORD || function == MOCORD)
} // end if !signal_change && signal } // end if !signal_change && signal
if ( score ) { if ( score ) {
if ( state == IDLE || state == TAPE || state == PREALARM ) { if ( state == IDLE || state == TAPE || state == PREALARM ) {
// This is so if we need more than 1 alarm frame before going into alarm, so it is basically if we have enough alarm frames
if ( (!pre_event_count) || (Event::PreAlarmCount() >= alarm_frame_count) ) { if ( (!pre_event_count) || (Event::PreAlarmCount() >= alarm_frame_count) ) {
// If we should end then previous continuous event and start a new non-continuous event
if ( event && event->Frames() && !event->AlarmFrames() ) {
Info("%s: %03d - Closing event %" PRIu64 ", continuous end, alarm begins",
name, image_count, event->Id());
closeEvent();
}
shared_data->state = state = ALARM; shared_data->state = state = ALARM;
// lets construct alarm cause. It will contain cause + names of zones alarmed // lets construct alarm cause. It will contain cause + names of zones alarmed
std::string alarm_cause = ""; std::string alarm_cause = "";
@ -1568,14 +1528,11 @@ bool Monitor::Analyse() {
strncpy(shared_data->alarm_cause,alarm_cause.c_str(), sizeof(shared_data->alarm_cause)-1); strncpy(shared_data->alarm_cause,alarm_cause.c_str(), sizeof(shared_data->alarm_cause)-1);
Info("%s: %03d - Gone into alarm state PreAlarmCount: %u > AlarmFrameCount:%u Cause:%s", Info("%s: %03d - Gone into alarm state PreAlarmCount: %u > AlarmFrameCount:%u Cause:%s",
name, image_count, Event::PreAlarmCount(), alarm_frame_count, shared_data->alarm_cause); name, image_count, Event::PreAlarmCount(), alarm_frame_count, shared_data->alarm_cause);
if ( signal_change || (function != MOCORD && state != ALERT) ) {
if ( !event ) {
int pre_index; int pre_index;
int pre_event_images = pre_event_count; int pre_event_images = pre_event_count;
if ( event ) {
// Shouldn't be able to happen because
Error("Creating new event when one exists");
}
if ( analysis_fps && pre_event_count ) { if ( analysis_fps && pre_event_count ) {
// If analysis fps is set, // If analysis fps is set,
// compute the index for pre event images in the dedicated buffer // compute the index for pre event images in the dedicated buffer