HandWashing/COVID-19 PoC used to detect when people are washing their hands correctly. More...
#include <HW.hpp>
Public Member Functions | |
HW () | |
Empty (default) constructor. Caller must use init() if this constructor is used. More... | |
HW (const std::string &filename) | |
Constructor. The specified input video file or device must exist. More... | |
virtual | ~HW () |
Destructor. More... | |
virtual HW & | false_start_timer_reset () |
Classes that inherit from HW can override this method to be told when the timer has been reset due to too many frames since the last time "wash" was detected. More... | |
virtual HW & | hand_washing_completed () |
Classes that inherit from HW can override this method to be told when handwashing has reached the desired number of seconds. More... | |
virtual HW & | hand_washing_ended_too_early () |
Classes that inherit from HW can override this method to be told when handwashing has finished prior to the full number of seconds. More... | |
virtual HW & | hand_washing_finished () |
Classes that inherit from HW can override this method to be told when handwashing has finished, meaning the hands are now completely out of view or the video stream has ended. More... | |
virtual HW & | hand_washing_started () |
Classes that inherit from HW can override this method to be told when handwashing is first detected. More... | |
virtual HW & | init (const std::string &filename) |
Initialize (or re-initialize) the HW object using the specified video file. More... | |
virtual HW & | init (const int idx, const int request_width=1024, const int request_height=768, const int request_fps=30) |
Initialize (or re-initialize) the HW object using the specified web cam. More... | |
virtual HW & | load_neural_network () |
Load the neural network files from disk. More... | |
virtual HW & | process_stream () |
Process the specified video stream. You must call init() (or use the constructor with the filename) prior to this call. More... | |
virtual HW & | reset () |
Reset the HW object. More... | |
virtual HW & | stream_has_ended () |
Classes that inherit from HW can override this method to be told when the video stream has ended. More... | |
virtual std::string | to_string () |
Format information on the HW object as a multi-line text string. More... | |
std::string | version () const |
Get the HW library version number. E.g., "1.0.0-2956" . More... | |
Public Attributes | |
std::string | base_filename |
The base filename. This is the input_filename without any path and with no extension. More... | |
double | blend_ratio |
The amount of blending between the counter circle's black background and the original frame image. More... | |
cv::VideoCapture | cap |
OpenCV video capturing device. More... | |
size_t | current_frame_index |
Starts at zero and increments up for every frame processed in the video stream. More... | |
size_t | current_session_index |
Starts at zero and increments up for every hand washing session that is started. More... | |
cv::Mat | current_video_frame_annotated |
The most recent video frame. This is after all annotations have been applied. More... | |
cv::Mat | current_video_frame_original |
The most recent video frame. This is the original image, prior to resizing and annotations. More... | |
cv::Mat | current_video_frame_resized |
The most recent video frame. This is after it has been resized. More... | |
double | current_wash_session_length |
In seconds the length of time the current (or most recent) hand washing session has lasted. More... | |
DarkHelp | darkhelp |
Neural network library. More... | |
int | desired_fps |
If a video capture device is used (e.g., "webcam") versus a recorded video stream, then the desired FPS, width, and height can be specified. More... | |
int | desired_frame_height |
Video frame will be resized to this height before processing by the neural network. More... | |
int | desired_frame_width |
Video frame will be resized to this width before processing by the neural network. More... | |
bool | display_frame_information |
Display some frame details at the bottom left corner, including FPS, frame index, and timestamp. More... | |
double | duration_of_frame |
The length (in seconds) of a single video stream based on the fps. More... | |
double | fps |
The number of frames-per-second in the video stream. More... | |
const int | HAND = 1 |
Class used by the neural network to indicate detection of a hand. More... | |
bool | in_handwashing_session |
Is set to true when a handwashing session has started. More... | |
std::string | input_filename |
The name of the input file or input device which was originally opened. More... | |
size_t | last_empty_frame |
The frame index of the last time we saw a frame that was empty (no hands). More... | |
size_t | last_hand_frame |
The frame index of the last time we saw a frame with a single hand. More... | |
size_t | last_session_frame |
The frame index of the most recent frame that was part of a session. More... | |
size_t | last_washing_frame |
The frame index of the last time we saw a frame with washing hands. More... | |
double | length_of_time_users_must_wash_hands |
In seconds, the length of time users must wash hands. More... | |
DarkHelp::PredictionResults | predictions |
Predictions returned by the neural network. More... | |
bool | save_output_video |
When set to true , the processed video stream will be saved as a .mp4 output video. More... | |
const int | WASHING = 0 |
Class used by the neural network to indicate detection of handwashing. More... | |
const int | WATER = 2 |
Class used by the neural network to indicate detection of water from a faucet. More... | |
HandWashing/COVID-19 PoC used to detect when people are washing their hands correctly.
This class will inspect the given video stream and determine if users are washing their hands with the help of the trained neural network.
There are two ways to use this class:
HW
and override the methods such as hand_washing_started() and hand_washing_completed() prior to calling the usual methods HW::init() and HW::process_stream().If using a class that derives from HW
, these are some of the methods you may want to override:
|
virtual |
Destructor.
CCR::HW::HW | ( | ) |
Empty (default) constructor. Caller must use init() if this constructor is used.
CCR::HW::HW | ( | const std::string & | filename | ) |
Constructor. The specified input video file or device must exist.
|
virtual |
Classes that inherit from HW
can override this method to be told when the timer has been reset due to too many frames since the last time "wash" was detected.
This is only called at the start of the session when there is barely any time logged on the timer.
|
virtual |
Classes that inherit from HW
can override this method to be told when handwashing has reached the desired number of seconds.
|
virtual |
Classes that inherit from HW
can override this method to be told when handwashing has finished prior to the full number of seconds.
|
virtual |
Classes that inherit from HW
can override this method to be told when handwashing has finished, meaning the hands are now completely out of view or the video stream has ended.
This is only called once per session.
|
virtual |
Classes that inherit from HW
can override this method to be told when handwashing is first detected.
This is only called once per session.
|
virtual |
Initialize (or re-initialize) the HW
object using the specified video file.
This automatically calls reset().
If you want to customize the look-and-feel of either the neural network annotations or how CCR::HW behaves, the right place to make those changes is immediately after the call to init(). For example:
To get further insight into what can be customized, see the members defined in CCR::HW, look at the code in CCR::HW::reset(), or in CCR::HW::load_neural_network().
std::invalid_argument | if the specified file cannot be opened |
|
virtual |
Initialize (or re-initialize) the HW object using the specified web cam.
The first camera is index zero, the next camera is index one, etc. These correspond to /dev/video0
, /dev/video1
, ... This automatically calls reset().
std::invalid_argument | if the specified camera index cannot be opened |
|
virtual |
Load the neural network files from disk.
The neural network files are automatically installed during installation. This is automatically called by init().
|
virtual |
Process the specified video stream. You must call init() (or use the constructor with the filename) prior to this call.
std::runtime_error | if the output video cannot be created |
|
virtual |
|
virtual |
Classes that inherit from HW
can override this method to be told when the video stream has ended.
|
virtual |
Format information on the HW object as a multi-line text string.
Mostly for debugging purposes.
For example:
std::string CCR::HW::version | ( | ) | const |
Get the HW library version number. E.g., "1.0.0-2956"
.
std::string CCR::HW::base_filename |
The base filename. This is the input_filename without any path and with no extension.
double CCR::HW::blend_ratio |
The amount of blending between the counter circle's black background and the original frame image.
Range is 0.0 to 1.0. At zero, the overlay is fully transparent and the background image is copied through. At 1.0 the overlay is opaque and the background image is hidden.
Default value is 0.75
, which means the black background is 3/4 opaque and only 25% of the background image frame is shown.
cv::VideoCapture CCR::HW::cap |
OpenCV video capturing device.
size_t CCR::HW::current_frame_index |
Starts at zero and increments up for every frame processed in the video stream.
size_t CCR::HW::current_session_index |
Starts at zero and increments up for every hand washing session that is started.
cv::Mat CCR::HW::current_video_frame_annotated |
The most recent video frame. This is after all annotations have been applied.
cv::Mat CCR::HW::current_video_frame_original |
The most recent video frame. This is the original image, prior to resizing and annotations.
cv::Mat CCR::HW::current_video_frame_resized |
The most recent video frame. This is after it has been resized.
double CCR::HW::current_wash_session_length |
In seconds the length of time the current (or most recent) hand washing session has lasted.
DarkHelp CCR::HW::darkhelp |
Neural network library.
int CCR::HW::desired_fps |
If a video capture device is used (e.g., "webcam") versus a recorded video stream, then the desired FPS, width, and height can be specified.
This does not guarantee these values will be used, as not all combinations of width, height, and FPS are valid. Default is 1024x768 @ 30 FPS.
int CCR::HW::desired_frame_height |
Video frame will be resized to this height before processing by the neural network.
Note that image resizing retains the aspect ratio of the original frame size, so the final dimensions used may not be exactly the size specified using desired_frame_width and desired_frame_height. Default for height is 768
.
int CCR::HW::desired_frame_width |
Video frame will be resized to this width before processing by the neural network.
Note that image resizing retains the aspect ratio of the original frame size, so the final dimensions used may not be exactly the size specified using desired_frame_width and desired_frame_height. Default for width is 1024
.
bool CCR::HW::display_frame_information |
Display some frame details at the bottom left corner, including FPS, frame index, and timestamp.
double CCR::HW::duration_of_frame |
The length (in seconds) of a single video stream based on the fps.
double CCR::HW::fps |
The number of frames-per-second in the video stream.
const int CCR::HW::HAND = 1 |
Class used by the neural network to indicate detection of a hand.
This is defined at the time the neural network was trained and cannot be changed.
bool CCR::HW::in_handwashing_session |
Is set to true
when a handwashing session has started.
std::string CCR::HW::input_filename |
The name of the input file or input device which was originally opened.
For example, could be "myvideo.mp4"
or "/dev/video0"
. The name provided by the user may be relative or absolute.
size_t CCR::HW::last_empty_frame |
The frame index of the last time we saw a frame that was empty (no hands).
size_t CCR::HW::last_hand_frame |
The frame index of the last time we saw a frame with a single hand.
size_t CCR::HW::last_session_frame |
The frame index of the most recent frame that was part of a session.
size_t CCR::HW::last_washing_frame |
The frame index of the last time we saw a frame with washing hands.
double CCR::HW::length_of_time_users_must_wash_hands |
In seconds, the length of time users must wash hands.
Default is 20 seconds. If the neural network reaches this length in time, then a green checkmark is shown. Otherwise, a red X
is shown.
DarkHelp::PredictionResults CCR::HW::predictions |
Predictions returned by the neural network.
bool CCR::HW::save_output_video |
When set to true
, the processed video stream will be saved as a .mp4 output video.
const int CCR::HW::WASHING = 0 |
Class used by the neural network to indicate detection of handwashing.
This is defined at the time the neural network was trained and cannot be changed.
const int CCR::HW::WATER = 2 |
Class used by the neural network to indicate detection of water from a faucet.
This is defined at the time the neural network was trained and cannot be changed.