CPP_Birdtracker
A C++ object tracking program specifically for lunar bird tracking
frame_extraction.hpp
Go to the documentation of this file.
1 
2 /*
3  * CPP_Birdtracker/frame_extraction.hpp - Primary header LunAero birdtracker.
4  * Copyright (C) <2020> <Wesley T. Honeycutt>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef FRAME_EXTRACTION_H
21 #define FRAME_EXTRACTION_H
22 
23 // Includes
24 #include <algorithm>
25 #include <ctime> // for NULL
26 #include <errno.h>
27 #include <tgmath.h> // for sin, cos, etc.
28 #include <fcntl.h>
29 #include <fstream>
30 #include <iostream>
31 #include <numeric> // for accumulate
32 #include <pthread.h>
33 #include <signal.h>
34 #include <stdlib.h> // for exit
35 #include <sys/ipc.h> // for IPC_CREAT, key_t
36 #include <sys/shm.h> // for shmat
37 #include <sys/mman.h> // for MAP_ANONYMOUS, MAP_SHARED
38 #include <sys/wait.h>
39 #include <tuple>
40 #include <unistd.h> // for fork, sleep, usleep
41 #include <typeinfo>
42 #include <regex>
43 
44 #include <string> // for string
45 using std::string;
46 
47 #include <experimental/filesystem>
48 namespace fs = std::experimental::filesystem;
49 
50 #include <vector> // for vector
51 using std::vector;
52 
53 #include "opencv2/opencv.hpp"
54 #include "opencv2/ximgproc.hpp"
55 using namespace cv;
56 
57 // std::map<std::string, std::string> options;
58 
59 // Global Variables
63 int MAJOR_VERSION = 0;
67 int MINOR_VERSION = 3;
71 std::string ALPHA_BETA = "-alpha";
75 int SIG_ALERT = 0;
79 double ORIG_AREA;
83 double ORIG_PERI;
96 int BOXSIZE;
101 Point ORIG_TL;
106 Point ORIG_BR;
110 std::string LOGOUT;
114 std::ofstream LOGGING;
118 std::string TIER1FILE;
122 std::string TIER2FILE;
126 std::string TIER3FILE;
130 std::string TIER4FILE;
134 std::string ELLIPSEDATA;
138 std::string BOXDATA;
142 std::string METADATA;
146 int TC_W;
150 int TC_H;
155 bool CAUGHT_EMPTY = false;
156 
157 
158 
159 
160 // Globals that Doxygen doesn't need to see
161 #ifndef DOXYGEN_SHOULD_SKIP_THIS
162 //
163 Mat HNC_FRAME;
164 
165 //
166 Mat IC_FRAME;
167 
168 //
169 Rect BF_BOX;
170 
171 #endif
172 
173 
174 
175 
176 // Global Variables declared in settings.cfg
181 bool DEBUG_FRAMES = false;
186 bool DEBUG_COUT = false;
191 bool OUTPUT_FRAMES = false;
197 bool EMPTY_FRAMES = true;
203 bool GEN_SLIDESHOW = true;
208 bool SIMP_ELL = true;
213 bool CONCAT_TIERS = true;
219 bool TIGHT_CROP = true;
224 std::string OSFPROJECT = "";
230 std::string OUTPUTDIR = "Birdtracker_Output/";
235 int EDGETHRESH = 10;
240 int QHE_WIDTH = 10;
250 
257 int CONVERT_FPS = 30;
263 
264 
279 double QHE_GB_SIGMA_X = 1;
284 double QHE_GB_SIGMA_Y = 1;
285 
286 
287 
292 double T1_AT_MAX = 255;
302 double T1_AT_CONSTANT = 35;
307 int T1_DYMASK = 25;
308 
309 
314 double T2_AT_MAX = 255;
324 double T2_AT_CONSTANT = 20;
329 int T2_DYMASK = 25;
330 
331 
336 int T3_LAP_KERNEL = 11;
341 double T3_LAP_SCALE = 0.0001;
346 double T3_LAP_DELTA = 0;
351 int T3_GB_KERNEL_X = 11;
356 int T3_GB_KERNEL_Y = 11;
361 double T3_GB_SIGMA_X = 1;
366 double T3_GB_SIGMA_Y = 1;
376 int T3_DYMASK = 45;
377 
378 
383 double T4_AT_MAX = 255;
393 double T4_AT_CONSTANT = 20;
398 double T4_POWER = 2;
403 int T4_GB_KERNEL_X = 11;
408 int T4_GB_KERNEL_Y = 11;
413 double T4_GB_SIGMA_X = 1;
418 double T4_GB_SIGMA_Y = 1;
423 int T4_THINNING = 0;
428 int T4_DYMASK = 45;
429 
430 
431 // Declared functions/prototypes
432 static Mat shift_frame(Mat in_frame, int shiftx, int shifty);
433 static Mat corner_matching(Mat in_frame, vector<Point> contour, int plusx, int plusy);
434 static vector <int> test_edges(Mat in_frame, vector<Point> contour, int te_ret);
435 static int min_square_dim(Mat in_frame);
436 static vector <int> edge_width(vector<Point> contour);
437 static vector <int> edge_height(vector<Point> contour);
438 static int initial_crop(Mat in_frame, int framecnt);
439 static int touching_edges(Mat in_frame, vector<Point> contour);
440 static Mat traditional_centering(Mat in_frame, vector <vector<Point>> contours, int largest, Rect box);
441 static int first_frame(Mat in_frame, int framecnt);
442 static int halo_noise_and_center(Mat in_frame, int framecnt);
443 static void signal_callback_handler(int signum);
444 static Mat apply_dynamic_mask(Mat in_frame, vector<vector<Point>> contours, int maskwidth);
445 static int largest_contour(vector <vector<Point>> contours);
446 static vector <vector<Point>> contours_only(Mat in_frame);
447 static int box_finder(Mat in_frame, bool do_thresh);
448 static int box_data(Rect box, int framecnt);
449 static int show_usage(string name);
450 static vector <Point> qhe_bigone(Mat in_frame);
451 static vector <vector<Point>> quiet_halo_elim(vector <vector<Point>> contours, vector <Point> bigone);
452 static int tier_one(int cnt, Mat in_frame, vector <Point> bigone);
453 static int tier_two(int cnt, Mat in_frame, vector <Point> bigone);
454 static int tier_three(int cnt, Mat in_frame, Mat old_frame, vector <Point> bigone);
455 static int tier_four(int cnt, Mat in_frame, Mat old_frame, vector <Point> bigone);
456 static int parse_checklist(std::string name, std::string value);
457 static std::string out_frame_gen(int framecnt);
458 std::string space_space(std::string instring);
459 static int generate_slideshow();
460 static int concat_tiers();
461 static int off_screen_ellipse();
462 static int post_processing();
463 int main(int argc, char* argv[]);
464 
465 #endif
static int tier_one(int cnt, Mat in_frame, vector< Point > bigone)
static int box_data(Rect box, int framecnt)
bool OUTPUT_FRAMES
std::string TIER3FILE
double T4_AT_MAX
int T2_DYMASK
std::string OSFPROJECT
static Mat apply_dynamic_mask(Mat in_frame, vector< vector< Point >> contours, int maskwidth)
int SIG_ALERT
static int show_usage(string name)
double T4_AT_CONSTANT
std::string METADATA
std::string TIER2FILE
double QHE_GB_SIGMA_Y
int T4_THINNING
std::ofstream LOGGING
int T4_GB_KERNEL_Y
int T4_GB_KERNEL_X
double ORIG_PERI
int T3_GB_KERNEL_X
double T1_AT_CONSTANT
static int off_screen_ellipse()
int T4_AT_BLOCKSIZE
int CONVERT_FPS
Point ORIG_BR
int T4_DYMASK
std::string ELLIPSEDATA
double T1_AT_MAX
bool DEBUG_FRAMES
double T3_LAP_DELTA
static vector< vector< Point > > quiet_halo_elim(vector< vector< Point >> contours, vector< Point > bigone)
static vector< Point > qhe_bigone(Mat in_frame)
int MINOR_VERSION
std::string space_space(std::string instring)
std::string OUTPUTDIR
int EDGETHRESH
int T3_DYMASK
static int box_finder(Mat in_frame, bool do_thresh)
int QHE_GB_KERNEL_X
int QHE_WIDTH
int T3_GB_KERNEL_Y
static int generate_slideshow()
int NON_ZERO_START
static int post_processing()
std::string ALPHA_BETA
double T3_GB_SIGMA_Y
int BLACKOUT_THRESH
Point ORIG_TL
static int first_frame(Mat in_frame, int framecnt)
double T4_POWER
static int parse_checklist(std::string name, std::string value)
int T3_LAP_KERNEL
bool GEN_SLIDESHOW
double ORIG_AREA
static int halo_noise_and_center(Mat in_frame, int framecnt)
std::string BOXDATA
bool CONCAT_TIERS
int BOXSIZE
static int tier_four(int cnt, Mat in_frame, Mat old_frame, vector< Point > bigone)
int ORIG_HORZ
double T2_AT_CONSTANT
bool SIMP_ELL
bool CAUGHT_EMPTY
static Mat shift_frame(Mat in_frame, int shiftx, int shifty)
bool EMPTY_FRAMES
static int tier_two(int cnt, Mat in_frame, vector< Point > bigone)
double QHE_GB_SIGMA_X
std::string TIER4FILE
static Mat traditional_centering(Mat in_frame, vector< vector< Point >> contours, int largest, Rect box)
double T4_GB_SIGMA_X
static std::string out_frame_gen(int framecnt)
static int tier_three(int cnt, Mat in_frame, Mat old_frame, vector< Point > bigone)
static vector< vector< Point > > contours_only(Mat in_frame)
bool DEBUG_COUT
int T1_DYMASK
static int concat_tiers()
int TC_H
int ORIG_VERT
static int min_square_dim(Mat in_frame)
static vector< int > test_edges(Mat in_frame, vector< Point > contour, int te_ret)
int MAJOR_VERSION
double T4_GB_SIGMA_Y
static int touching_edges(Mat in_frame, vector< Point > contour)
double T3_GB_SIGMA_X
static void signal_callback_handler(int signum)
int T2_AT_BLOCKSIZE
int TC_W
std::string LOGOUT
int T3_CUTOFF_THRESH
double T3_LAP_SCALE
int QHE_GB_KERNEL_Y
int main(int argc, char *argv[])
static vector< int > edge_height(vector< Point > contour)
static int initial_crop(Mat in_frame, int framecnt)
std::string TIER1FILE
static int largest_contour(vector< vector< Point >> contours)
int T1_AT_BLOCKSIZE
static Mat corner_matching(Mat in_frame, vector< Point > contour, int plusx, int plusy)
static vector< int > edge_width(vector< Point > contour)
bool TIGHT_CROP
double T2_AT_MAX