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