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...
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... | |
Handler & | clear () |
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... | |
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.
MoveDetect::Handler::Handler | ( | ) |
Constructor.
|
virtual |
Destructor.
bool MoveDetect::Handler::empty | ( | ) | const |
Determine if this handler has any images against which to check for movement.
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.
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.
true
if movement is detected, otherwise returns false
.std::map
, so it must not be called simultaneously from multiple threads.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:
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.
std::map
, so it must not be called simultaneously from multiple threads.true
if movement is detected, otherwise returns false
.bool MoveDetect::Handler::movement_detected |
This is the same as the value returne by detect() and indicates whether the last image seen showed movement.
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.
size_t MoveDetect::Handler::next_frame_index |
The index of the next frame expected to be seen by detect().
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.
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.
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
.
double MoveDetect::Handler::psnr_threshold |
The threshold value below which it is assumed that movement has been detected.
Default value is 32.0
.
double MoveDetect::Handler::most_recent_psnr_score |
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.
cv::Size MoveDetect::Handler::thumbnail_size |
The size of the thumbnail that will be generated. Instead of modifying this value, see thumbnail_ratio.
size_t MoveDetect::Handler::frame_index_with_movement |
The most recent frame index where movement was detected.
std::chrono::high_resolution_clock::time_point MoveDetect::Handler::movement_last_detected |
The timestamp when detect() last returned true
.
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.
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
.
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:
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
.
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.
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:
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
.
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.
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:
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
.
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: