-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMotionDetector.h
83 lines (55 loc) · 1.56 KB
/
MotionDetector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef MOTION_DETECTOR_H
#define MOTION_DETECTOR_H
#include "MailPhotoSender.h"
#include <opencv2/opencv.hpp>
#include <string>
#include <fstream>
using cv::VideoCapture;
using cv::Mat;
using std::string;
using std::ofstream;
enum ErrorType {
NO_ERRORS,
CAPTURE_INIT_ERROR
};
struct MotionDetector {
MotionDetector(int capture_device_id, int threshold, int width = 640, int height = 480);
void set_video_writer_filename(const string & video_file_name) { this->video_writer = new ofstream(video_file_name.c_str(), ofstream::binary); }
void set_standard_deviation(const int standart_deviation) { this->standard_deviation = standard_deviation; }
void set_save_filename(const string & save_filename) { this->save_filename = save_filename; }
void set_mail_sender(MailPhotoSender * const mail_sender) { this->mail_sender = mail_sender; send_mail = true; }
bool is_opened() { return error == NO_ERRORS; }
void detect_motion();
private:
static const size_t NO_MOTION_FRAMES = 10;
VideoCapture cap;
Mat current_frame;
Mat previous_frame;
Mat result;
Mat diff;
struct MotionPhotoFrame {
size_t motion_square;
Mat photo_frame;
MotionPhotoFrame():
motion_square(0)
{}
} motion_photo_frame;
ofstream * video_writer;
ErrorType error;
int standard_deviation;
int threshold_;
struct Rectangle {
int min_x;
int min_y;
int max_x;
int max_y;
} bound_motion;
string save_filename;
MailPhotoSender * mail_sender;
bool send_mail;
bool is_motion_real();
size_t get_number_of_changes();
void clear_bound_rectangle();
void make_bounds();
};
#endif