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

MoveDetect uses the standard image processing library OpenCV. You'll need to link against OpenCV to use MoveDetect.

To detect movement, you instantiate a MoveDetect::Handler object, and then repeatedly call MoveDetect::Handler::detect() when you have frames to be analyzed.

The detect() method will compare the last few frames and return either true or false to indicate whether movement was detected.

Your code would look similar to this:

#include <MoveDetect.hpp>
void process_video()
{
cv::VideoCapture video("movie.m4v");
while (true)
{
cv::Mat frame;
video >> frame;
if (frame.emtpy())
{
break;
}
const bool movement_detected = handler.detect(frame);
if (movement_detected)
{
do_something_movement_detected(frame);
}
else
{
do_something_no_movement(frame);
}
}
}

There are many options, including thresholds for the amount of movement required, as well as generating a mask, bounding boxes, and contours.

Several key options to look into:

Configuration Item Image
MoveDetect::Handler::psnr_threshold  
MoveDetect::Handler::key_frame_frequency  
MoveDetect::Handler::number_of_control_frames  
original video frame
MoveDetect::Handler::mask_enabled
MoveDetect::Handler::mask
MoveDetect::Handler::bbox_enabled
MoveDetect::Handler::output
MoveDetect::Handler::contours_enabled
MoveDetect::Handler::output
MoveDetect::Handler::most_recent_psnr_score
double most_recent_psnr_score
The PSNR value received from the most recent call to detect().
Definition: MoveDetect.hpp:131
MoveDetect::Handler::key_frame_frequency
size_t key_frame_frequency
This determines how often new frames are inserted into control.
Definition: MoveDetect.hpp:118
MoveDetect::Handler::movement_detected
bool movement_detected
This is the same as the value returne by detect() and indicates whether the last image seen showed mo...
Definition: MoveDetect.hpp:96
MoveDetect::Handler::psnr_threshold
double psnr_threshold
The threshold value below which it is assumed that movement has been detected.
Definition: MoveDetect.hpp:128
MoveDetect::Handler::bbox_enabled
bool bbox_enabled
Set to true to get the library to draw a bounding box around any detected movement.
Definition: MoveDetect.hpp:209
MoveDetect::Handler
This class is used to store some image thumbnails, configuration settings, and also contains the dete...
Definition: MoveDetect.hpp:41
MoveDetect::Handler::number_of_control_frames
size_t number_of_control_frames
The number of frames to which we want to hold on to in control.
Definition: MoveDetect.hpp:123
MoveDetect::Handler::next_frame_index
size_t next_frame_index
The index of the next frame expected to be seen by detect().
Definition: MoveDetect.hpp:104
MoveDetect::Handler::contours_size
int contours_size
The width of the line to use when drawing contours.
Definition: MoveDetect.hpp:195
MoveDetect::Handler::thumbnail_size
cv::Size thumbnail_size
The size of the thumbnail that will be generated. Instead of modifying this value,...
Definition: MoveDetect.hpp:141
MoveDetect::Handler::bbox_size
int bbox_size
The width of the line to use when drawing the bounding box.
Definition: MoveDetect.hpp:214
MoveDetect::Handler::thumbnail_ratio
double thumbnail_ratio
How much the image will be reduced to generate the thumbnails.
Definition: MoveDetect.hpp:138
MoveDetect::Handler::next_key_frame
size_t next_key_frame
The next index when this library will store a thumbnail in the control object.
Definition: MoveDetect.hpp:109
MoveDetect::Handler::output
cv::Mat output
When either contours_enabled or bbox_enabled is enabled, the resulting image is stored in output.
Definition: MoveDetect.hpp:227
MoveDetect
Definition: MoveDetect.hpp:12
MoveDetect::Handler::contours_enabled
bool contours_enabled
Set to true to get the library to draw the mask contours onto the output image.
Definition: MoveDetect.hpp:190
MoveDetect::Handler::frame_index_with_movement
size_t frame_index_with_movement
The most recent frame index where movement was detected.
Definition: MoveDetect.hpp:144
MoveDetect::Handler::control
ControlMap control
All of the key control thumbnail images are stored in this map.
Definition: MoveDetect.hpp:152
MoveDetect::simple_colour_balance
cv::Mat simple_colour_balance(const cv::Mat &src)
Simple colour balancing.
Definition: MoveDetect.cpp:42
MoveDetect::Handler::mask_enabled
bool mask_enabled
Set to true to get the library to create a mask showing where movement was detected.
Definition: MoveDetect.hpp:157
MoveDetect::Handler::transition_detected
bool transition_detected
When movement_detected is toggled between true and false, the transition_detected variable will be se...
Definition: MoveDetect.hpp:101
MoveDetect::Handler::line_type
cv::LineTypes line_type
The type of line type drawing OpenCV will use if contours_enabled or bbox_enabled have been set.
Definition: MoveDetect.hpp:176
MoveDetect::ControlMap
std::map< size_t, cv::Mat > ControlMap
We keep several control thumbnail images to compare against.
Definition: MoveDetect.hpp:36
MoveDetect::Handler::movement_last_detected
std::chrono::high_resolution_clock::time_point movement_last_detected
The timestamp when detect() last returned true.
Definition: MoveDetect.hpp:147
MoveDetect::psnr
double psnr(const cv::Mat &src, const cv::Mat &dst)
Peak Signal To Noise is an algorithm which as a side effect can be used to compare two similar images...
Definition: MoveDetect.cpp:9
MoveDetect::Handler::clear
Handler & clear()
Clear out the object and get it ready to be reused.
Definition: MoveDetect.cpp:99
MoveDetect::Handler::~Handler
virtual ~Handler()
Destructor.
Definition: MoveDetect.cpp:87
MoveDetect::Handler::empty
bool empty() const
Determine if this handler has any images against which to check for movement.
Definition: MoveDetect.cpp:93
MoveDetect::Handler::mask
cv::Mat mask
When mask_enabled is enabled, the result is saved to mask.
Definition: MoveDetect.hpp:171
MoveDetect::Handler::Handler
Handler()
Constructor.
Definition: MoveDetect.cpp:79
MoveDetect::Handler::detect
bool detect(cv::Mat &next_image)
Detect whether there is any movement in this next image.
Definition: MoveDetect.cpp:127