MoveDetect  v0.0.1
C++ library to detect movement in video frames
All Classes Namespaces Functions Variables Typedefs Pages
MoveDetect::Handler Class Reference

This class is used to store some image thumbnails, configuration settings, and also contains the detect() method which is used to determine if a video frame has movement. More...

Collaboration diagram for MoveDetect::Handler:

Public Member Functions

 Handler ()
 Constructor. More...
 
virtual ~Handler ()
 Destructor. More...
 
bool empty () const
 Determine if this handler has any images against which to check for movement. More...
 
Handlerclear ()
 Clear out the object and get it ready to be reused. More...
 
bool detect (cv::Mat &next_image)
 Detect whether there is any movement in this next image. More...
 
bool detect (const size_t frame_index, cv::Mat &image)
 Detect whether there is any movement in an arbritrary image frame. More...
 

Public Attributes

bool movement_detected
 This is the same as the value returne by detect() and indicates whether the last image seen showed movement. More...
 
bool transition_detected
 When movement_detected is toggled between true and false, the transition_detected variable will be set to true. More...
 
size_t next_frame_index
 The index of the next frame expected to be seen by detect(). More...
 
size_t next_key_frame
 The next index when this library will store a thumbnail in the control object. More...
 
size_t key_frame_frequency
 This determines how often new frames are inserted into control. More...
 
size_t number_of_control_frames
 The number of frames to which we want to hold on to in control. More...
 
double psnr_threshold
 The threshold value below which it is assumed that movement has been detected. More...
 
double most_recent_psnr_score
 The PSNR value received from the most recent call to detect(). More...
 
double thumbnail_ratio
 How much the image will be reduced to generate the thumbnails. More...
 
cv::Size thumbnail_size
 The size of the thumbnail that will be generated. Instead of modifying this value, see thumbnail_ratio. More...
 
size_t frame_index_with_movement
 The most recent frame index where movement was detected. More...
 
std::chrono::high_resolution_clock::time_point movement_last_detected
 The timestamp when detect() last returned true. More...
 
ControlMap control
 All of the key control thumbnail images are stored in this map. More...
 
bool mask_enabled
 Set to true to get the library to create a mask showing where movement was detected. More...
 
cv::Mat mask
 When mask_enabled is enabled, the result is saved to mask. More...
 
cv::LineTypes line_type
 The type of line type drawing OpenCV will use if contours_enabled or bbox_enabled have been set. More...
 
bool contours_enabled
 Set to true to get the library to draw the mask contours onto the output image. More...
 
int contours_size
 The width of the line to use when drawing contours. More...
 
bool bbox_enabled
 Set to true to get the library to draw a bounding box around any detected movement. More...
 
int bbox_size
 The width of the line to use when drawing the bounding box. More...
 
cv::Mat output
 When either contours_enabled or bbox_enabled is enabled, the resulting image is stored in output. More...
 

Detailed Description

This class is used to store some image thumbnails, configuration settings, and also contains the detect() method which is used to determine if a video frame has movement.

See also
Summary

Constructor & Destructor Documentation

◆ Handler()

MoveDetect::Handler::Handler ( )

Constructor.

Here is the call graph for this function:

◆ ~Handler()

MoveDetect::Handler::~Handler ( )
virtual

Destructor.

Member Function Documentation

◆ empty()

bool MoveDetect::Handler::empty ( ) const

Determine if this handler has any images against which to check for movement.

◆ clear()

MoveDetect::Handler & MoveDetect::Handler::clear ( )

Clear out the object and get it ready to be reused.

This will reset all the configuration settings to their default values.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ detect() [1/2]

bool MoveDetect::Handler::detect ( cv::Mat &  next_image)

Detect whether there is any movement in this next image.

This assumes the images or frames are sequential. If the image provided is not the next sequential image, then use the other detect() where a frame index is provided.

Returns
true if movement is detected, otherwise returns false.
Warning
This method adds and removes image thumbnails from a std::map, so it must not be called simultaneously from multiple threads.
See also
movement_detected
transition_detected

Given this video frame of someone walking across a parking lot:

When contours_enabled and/or bbox_enabled have been enabled, in addition to returning true to indicate that movement was detected, the output will be similar to this:

◆ detect() [2/2]

bool MoveDetect::Handler::detect ( const size_t  frame_index,
cv::Mat &  image 
)

Detect whether there is any movement in an arbritrary image frame.

The frame index must be greater than or equal to next_frame_index.

Warning
This method adds and removes image thumbnails from a std::map, so it must not be called simultaneously from multiple threads.
Returns
true if movement is detected, otherwise returns false.
See also
movement_detected
transition_detected
Here is the call graph for this function:

Member Data Documentation

◆ movement_detected

bool MoveDetect::Handler::movement_detected

This is the same as the value returne by detect() and indicates whether the last image seen showed movement.

◆ transition_detected

bool MoveDetect::Handler::transition_detected

When movement_detected is toggled between true and false, the transition_detected variable will be set to true.

Callers can use this to determine when a video experiences a significant state change.

◆ next_frame_index

size_t MoveDetect::Handler::next_frame_index

The index of the next frame expected to be seen by detect().

◆ next_key_frame

size_t MoveDetect::Handler::next_key_frame

The next index when this library will store a thumbnail in the control object.

This is handled internally, and users of the library shouldn't have to modify or reference this value.

See also
key_frame_frequency

◆ key_frame_frequency

size_t MoveDetect::Handler::key_frame_frequency

This determines how often new frames are inserted into control.

Default value is 10, which for videos recorded at 30 FPS means 3 key frames per second. If masking is enabled (mask_enabled) and the mask is displayed or used to show bounding boxes, then this value should be small to record many key frames per second. If masking is disabled, then this value may be set to a much higher value, such as the same as the original FPS.

See also
number_of_control_frames

◆ number_of_control_frames

size_t MoveDetect::Handler::number_of_control_frames

The number of frames to which we want to hold on to in control.

Images will be compared against all these control frames to determine if there was any movement, so you'll want to keep it short. Default value is 4.

◆ psnr_threshold

double MoveDetect::Handler::psnr_threshold

The threshold value below which it is assumed that movement has been detected.

Default value is 32.0.

See also
psnr()

◆ most_recent_psnr_score

double MoveDetect::Handler::most_recent_psnr_score

The PSNR value received from the most recent call to detect().

See also
psnr()

◆ thumbnail_ratio

double MoveDetect::Handler::thumbnail_ratio

How much the image will be reduced to generate the thumbnails.

The larger the thumbnail, the more precise the detection, but the more processing needs to be done for every frame. And if it is made too large, the library will pick up image artifacts or subtle tiny changes and think that movement was detected. Default value is 0.05, meaning the width and height will be reduced to 5% of the original image size.

◆ thumbnail_size

cv::Size MoveDetect::Handler::thumbnail_size

The size of the thumbnail that will be generated. Instead of modifying this value, see thumbnail_ratio.

◆ frame_index_with_movement

size_t MoveDetect::Handler::frame_index_with_movement

The most recent frame index where movement was detected.

See also
movement_last_detected

◆ movement_last_detected

std::chrono::high_resolution_clock::time_point MoveDetect::Handler::movement_last_detected

The timestamp when detect() last returned true.

◆ control

ControlMap MoveDetect::Handler::control

All of the key control thumbnail images are stored in this map.

When calling detect(), the images are compared against the thumbnails stored within.

◆ mask_enabled

bool MoveDetect::Handler::mask_enabled

Set to true to get the library to create a mask showing where movement was detected.

The default value for mask_enabled is false.

See also
mask

◆ mask

cv::Mat MoveDetect::Handler::mask

When mask_enabled is enabled, the result is saved to mask.

This is a binary 1-channel image, OpenCV type CV_8UC1, where 0 is the background and 1 is where movement is detected.

Given this video frame of someone walking across a parking lot:

When mask_enabled has been set, in addition to detect() returning true when movement is detected the mask will look similar to this:

◆ line_type

cv::LineTypes MoveDetect::Handler::line_type

The type of line type drawing OpenCV will use if contours_enabled or bbox_enabled have been set.

Set this to cv::LINE_AA to get prettier anti-alised lines. Default is cv::LINE_4.

◆ contours_enabled

bool MoveDetect::Handler::contours_enabled

Set to true to get the library to draw the mask contours onto the output image.

If enabled, this will also enable mask_enabled as it requires the mask.

See also
output

Given this video frame of someone walking across a parking lot:

When contours_enabled has been set, in addition to detect() returning true when movement is detected the output image will look similar to this:

◆ contours_size

int MoveDetect::Handler::contours_size

The width of the line to use when drawing contours.

This is only used when contours_enabled has been set. The default contours size is 1.

See also
output

◆ bbox_enabled

bool MoveDetect::Handler::bbox_enabled

Set to true to get the library to draw a bounding box around any detected movement.

If enabled, this will also enable mask_enabled as it requires the mask.

See also
output

Given this video frame of someone walking across a parking lot:

When bbox_enabled has been set, in addition to detect() returning true when movement is detected the output image will look similar to this:

◆ bbox_size

int MoveDetect::Handler::bbox_size

The width of the line to use when drawing the bounding box.

This is only used when bbox_enabled has been set. The default line size is 1.

See also
output

◆ output

cv::Mat MoveDetect::Handler::output

When either contours_enabled or bbox_enabled is enabled, the resulting image is stored in output.

Given this video frame of someone walking across a parking lot:

When both contours_enabled and bbox_enabled have been set, in addition to detect() returning true when movement is detected the output image will look similar to this:


The documentation for this class was generated from the following files: