GuardMyPi
Protecting your berries from unauthorised tampering!
guardmypi.h
Go to the documentation of this file.
1 
8 #include <opencv2/core/utility.hpp>
9 #include "opencv2/objdetect/objdetect.hpp"
10 #include <opencv2/tracking.hpp>
11 #include <opencv2/videoio.hpp>
12 #include <opencv2/highgui.hpp>
13 #include <opencv2/imgcodecs.hpp>
14 #include "opencv2/face.hpp"
15 #include <iostream>
16 #include <cstring>
17 #include <unistd.h>
18 #include <thread>
19 #include <ctime>
20 #include <cstdlib>
21 
22 using namespace std;
23 using namespace cv;
24 using namespace cv::face;
25 
31  protected:
32  Mat frame_diff;
33  Mat grayscale;
35  Mat scaled_avg;
36  vector<vector<Point> > cnts;
37  Rect rect;
38  Point pt1;
39  Point pt2;
40 
41  public:
42  Mat avg;
43  Mat ProcessContours(Mat camerafeed); // Motion Detector method
44  int flag = 0;
45 };
46 
52  protected:
53  CascadeClassifier cascade;
54  Mat GrayFrame;
55  Point pt1;
56  Point pt2;
57 
58  public:
59  int flag = -1;
60  int loadcascade(String cascadename); // Method for loading particular Haar cascade file
61  int detect(Mat ReferenceFrame, double scale_factor, int neighbours,clock_t startTime); // Method for detecting the object in frame
62 
63 };
64 
70 class Unlock {
71  protected:
72  Mat gray,thresh, new_avg, diff,GrayFrame;
73  CascadeClassifier hand_cascade;
74  Scalar color = Scalar(255, 0, 0);
75  CascadeClassifier face_cascade;
76  Ptr<LBPHFaceRecognizer> recogniser = LBPHFaceRecognizer::create(1,8,8,8,123);
77  double confidence = 0.0;
78  string name;
79  QRCodeDetector qrDecoder;
80  Mat bbox, rectifiedImage;
81 
82 
83  public:
84  //Flags used to trigger new thread creation
85  int faceflag = 0;
86  int intruderflag = 0;
87  int lockflag = 0;
88  int QRunlockflag = 0;
89  //int QRlockflag = 0;
90  int resetflag = 0;
91  int ID = -1;
92  double secondsPassed = 0.0;
93 
94  int loadcascade(); //Method used to load all necessary cascade files (xml and yml)
95  int face(Mat ReferenceFrame, clock_t startTime); //Method used to for facial recognition
96  int QRUnlock(Mat frame, clock_t startTime); //Method used to unlock system with QR Code
97  int QRLock(Mat frame); //Method used to lock system using QR Code
98  int Deactivate(Mat frame);
99 };
100 
105 class Camera{
106  protected:
110  Mat frame;
111  Mat testframe;
112  VideoCapture video;
113  int hour;
114  int emailflag = 1;
117  clock_t pet_startTime;
119 
120  public:
121 
122  int opencam(int camport); //Method used to open up the systems camera and runs an infinite loop of frame capturing
123  int gettime(); //Used to collect the time in GMT
124  };
Mat scaled_avg
8-bit Absolute value frame
Definition: guardmypi.h:35
Mat grayscale
Grayscaled version of the camera frame.
Definition: guardmypi.h:33
Analyses video feed by using background subtraction with a running average to detect motion changes...
Definition: guardmypi.h:30
QRCodeDetector qrDecoder
Instance of the QR Code detection object.
Definition: guardmypi.h:79
VideoCapture video
Video input capture object.
Definition: guardmypi.h:112
Mat rectifiedImage
Holds the rectified QR Code and position of the QR Code.
Definition: guardmypi.h:80
int pet_timerflag
Timer flag used solely for pet detection.
Definition: guardmypi.h:115
MotionDetector motiondetector
Instance of the Motion Detection.
Definition: guardmypi.h:107
Mat testframe
Empty testframe used to reset the running average frame for the Motion Detector.
Definition: guardmypi.h:111
Interfaces in the main program to open/close the camera and create new threads.
Definition: guardmypi.h:105
Mat frame
Frame that will be assigned to the incoming frames from the VideoCapture object.
Definition: guardmypi.h:110
clock_t recognise_startTime
With no pet detetected then a time stamp is taken before running the appropriate unlock method...
Definition: guardmypi.h:118
CascadeClassifier cascade
cascade classifier object
Definition: guardmypi.h:53
ObjectDetector petdetector
Instance of the object detector that will be accessing the ped detection method.
Definition: guardmypi.h:109
Point pt1
Start point/coordinate for the object rectangle.
Definition: guardmypi.h:55
Point pt2
End point/coordinate for the contour rectangle.
Definition: guardmypi.h:39
Contains various methods to unlock the system.
Definition: guardmypi.h:70
int recognise_timerflag
Human unlocking timer flag used in the unlock methods.
Definition: guardmypi.h:116
Mat GrayFrame
Various members to contain a grayscale, threshold, running average and difference frame...
Definition: guardmypi.h:72
int hour
Hour time in GMT.
Definition: guardmypi.h:113
Mat GrayFrame
grayscale frame for processing
Definition: guardmypi.h:54
Rect rect
Up-right rectangle to highlight detected contours.
Definition: guardmypi.h:37
vector< vector< Point > > cnts
Vector of points of detected contours.
Definition: guardmypi.h:36
clock_t pet_startTime
Used to capture a time stamp whenever motion is detected originally.
Definition: guardmypi.h:117
Point pt1
Start point/coordinate for the contour rectangle.
Definition: guardmypi.h:38
Mat avg
Running average of the camerafeed.
Definition: guardmypi.h:42
Unlock recognise
Instance of the unlock class with uses of facial recognition, QR Detection.
Definition: guardmypi.h:108
Mat frame_thresh
Threshold frame.
Definition: guardmypi.h:34
string name
Name of the recognised resident.
Definition: guardmypi.h:78
CascadeClassifier face_cascade
Instance of the HAAR classifier for facial detection.
Definition: guardmypi.h:75
Mat frame_diff
Difference output between frames.
Definition: guardmypi.h:32
Used to analyse incoming feed from the camera for different objects such as Pets etc...
Definition: guardmypi.h:51
Point pt2
End point/coordinate for the object rectangle.
Definition: guardmypi.h:56
CascadeClassifier hand_cascade
Instance of the HAAR cascade object.
Definition: guardmypi.h:73