CPP_Birdtracker
A C++ object tracking program specifically for lunar bird tracking
|
#include <algorithm>
#include <ctime>
#include <errno.h>
#include <tgmath.h>
#include <fcntl.h>
#include <fstream>
#include <iostream>
#include <numeric>
#include <pthread.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <tuple>
#include <unistd.h>
#include <typeinfo>
#include <regex>
#include <string>
#include <experimental/filesystem>
#include <vector>
#include "opencv2/opencv.hpp"
#include "opencv2/ximgproc.hpp"
Go to the source code of this file.
Functions | |
static Mat | shift_frame (Mat in_frame, int shiftx, int shifty) |
static Mat | corner_matching (Mat in_frame, vector< Point > contour, int plusx, int plusy) |
static vector< int > | test_edges (Mat in_frame, vector< Point > contour, int te_ret) |
static int | min_square_dim (Mat in_frame) |
static vector< int > | edge_width (vector< Point > contour) |
static vector< int > | edge_height (vector< Point > contour) |
static int | initial_crop (Mat in_frame, int framecnt) |
static int | touching_edges (Mat in_frame, vector< Point > contour) |
static Mat | traditional_centering (Mat in_frame, vector< vector< Point >> contours, int largest, Rect box) |
static int | first_frame (Mat in_frame, int framecnt) |
static int | halo_noise_and_center (Mat in_frame, int framecnt) |
static void | signal_callback_handler (int signum) |
static Mat | apply_dynamic_mask (Mat in_frame, vector< vector< Point >> contours, int maskwidth) |
static int | largest_contour (vector< vector< Point >> contours) |
static vector< vector< Point > > | contours_only (Mat in_frame) |
static int | box_finder (Mat in_frame, bool do_thresh) |
static int | box_data (Rect box, int framecnt) |
static int | show_usage (string name) |
static vector< Point > | qhe_bigone (Mat in_frame) |
static vector< vector< Point > > | quiet_halo_elim (vector< vector< Point >> contours, vector< Point > bigone) |
static int | tier_one (int cnt, Mat in_frame, vector< Point > bigone) |
static int | tier_two (int cnt, Mat in_frame, vector< Point > bigone) |
static int | tier_three (int cnt, Mat in_frame, Mat old_frame, vector< Point > bigone) |
static int | tier_four (int cnt, Mat in_frame, Mat old_frame, vector< Point > bigone) |
static int | parse_checklist (std::string name, std::string value) |
static std::string | out_frame_gen (int framecnt) |
std::string | space_space (std::string instring) |
static int | generate_slideshow () |
static int | concat_tiers () |
static int | off_screen_ellipse () |
static int | post_processing () |
int | main (int argc, char *argv[]) |
Variables | |
int | MAJOR_VERSION = 0 |
int | MINOR_VERSION = 3 |
std::string | ALPHA_BETA = "-alpha" |
int | SIG_ALERT = 0 |
double | ORIG_AREA |
double | ORIG_PERI |
int | ORIG_VERT |
int | ORIG_HORZ |
int | BOXSIZE |
Point | ORIG_TL |
Point | ORIG_BR |
std::string | LOGOUT |
std::ofstream | LOGGING |
std::string | TIER1FILE |
std::string | TIER2FILE |
std::string | TIER3FILE |
std::string | TIER4FILE |
std::string | ELLIPSEDATA |
std::string | BOXDATA |
std::string | METADATA |
int | TC_W |
int | TC_H |
bool | CAUGHT_EMPTY = false |
bool | DEBUG_FRAMES = false |
bool | DEBUG_COUT = false |
bool | OUTPUT_FRAMES = false |
bool | EMPTY_FRAMES = true |
bool | GEN_SLIDESHOW = true |
bool | SIMP_ELL = true |
bool | CONCAT_TIERS = true |
bool | TIGHT_CROP = true |
std::string | OSFPROJECT = "" |
std::string | OUTPUTDIR = "Birdtracker_Output/" |
int | EDGETHRESH = 10 |
int | QHE_WIDTH = 10 |
int | BLACKOUT_THRESH = 51 |
int | CONVERT_FPS = 30 |
int | NON_ZERO_START = 0 |
int | QHE_GB_KERNEL_X = 15 |
int | QHE_GB_KERNEL_Y = 15 |
double | QHE_GB_SIGMA_X = 1 |
double | QHE_GB_SIGMA_Y = 1 |
double | T1_AT_MAX = 255 |
int | T1_AT_BLOCKSIZE = 65 |
double | T1_AT_CONSTANT = 35 |
int | T1_DYMASK = 25 |
double | T2_AT_MAX = 255 |
int | T2_AT_BLOCKSIZE = 65 |
double | T2_AT_CONSTANT = 20 |
int | T2_DYMASK = 25 |
int | T3_LAP_KERNEL = 11 |
double | T3_LAP_SCALE = 0.0001 |
double | T3_LAP_DELTA = 0 |
int | T3_GB_KERNEL_X = 11 |
int | T3_GB_KERNEL_Y = 11 |
double | T3_GB_SIGMA_X = 1 |
double | T3_GB_SIGMA_Y = 1 |
int | T3_CUTOFF_THRESH = 40 |
int | T3_DYMASK = 45 |
double | T4_AT_MAX = 255 |
int | T4_AT_BLOCKSIZE = 65 |
double | T4_AT_CONSTANT = 20 |
double | T4_POWER = 2 |
int | T4_GB_KERNEL_X = 11 |
int | T4_GB_KERNEL_Y = 11 |
double | T4_GB_SIGMA_X = 1 |
double | T4_GB_SIGMA_Y = 1 |
int | T4_THINNING = 0 |
int | T4_DYMASK = 45 |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
int main | ( | int | argc, |
char * | argv[] | ||
) |
Main loop
argc | number of input arguments |
argv | contents of input arguments |
Definition at line 2056 of file frame_extraction.cpp.
|
static |
|
static |
|
static |
|
static |
This function handles the strings and values parsed from the settings.cfg file and assigns them to the global values.
name | String obtained while parsing the settings.cfg file |
value | The value associated with name from settings.cfg file |
Definition at line 1328 of file frame_extraction.cpp.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
This is a helper function to handle terminal signals. This shuts down the various forks properly when an interrupt is caught.
signum | signal number passed to this function. Only handles 2. |
Definition at line 738 of file frame_extraction.cpp.
std::string space_space | ( | std::string | instring | ) |
This helper function handles spaces in user paths.
instring | the input string |
Definition at line 1526 of file frame_extraction.cpp.
|
static |
|
static |
This is the fourth pass to detect valid contours in a frame. The parameters of the function are set in the T4 section of settings.cfg. This is the UnCanny method for detecting motion. The steps are essentially the backward operation of the steps taken during Canny filtering. The current frame is subtracted from the previous frame, and this output is threholded. The thresholded image is then passed through directional Sobel filters to separate the x and y components. These components are squared, added to each other, and square rooted. The output is rescaled to match the input value ranges, and a Gaussian blur is applied. Since this output is messy, the blurry image is processed using Zhang-Suen thinning to get distinct edges. Any details lost between the blurring and thinning steps reduce noise. Contours are then detected in the normal way.
framecnt | int of nth frame retrieved by program |
in_frame | OpenCV matrix image, 16-bit single depth format |
old_frame | OpenCV matrix image, 16-bit single depth format, stored from previous cycle |
bigone | vector of Opencv Points representing the largest contour from qhe_bigone |
Definition at line 1229 of file frame_extraction.cpp.
|
static |
This is the first pass to detect valid contours in a frame. The parameters of the function are set in the T1 section of settings.cfg. Contours are detected based on a relatively strict OpenCV adaptiveThreshold function. These should be gauranteed "hits".
framecnt | int of nth frame retrieved by program |
in_frame | OpenCV matrix image, 16-bit single depth format |
bigone | vector of Opencv Points representing the largest contour from qhe_bigone |
Definition at line 964 of file frame_extraction.cpp.
|
static |
This is the third pass to detect valid contours in a frame. The parameters of the function are set in the T3 section of settings.cfg. The detector performs an isotropic Laplacian on the current frame and the previous frame (settings.cfg can be modified for anisotropic Laplacian). The outputs are blurred and recombined. Values passing a cutoff threshold are retained and the contours are detected.
framecnt | int of nth frame retrieved by program |
in_frame | OpenCV matrix image, 16-bit single depth format |
old_frame | OpenCV matrix image, 16-bit single depth format, stored from previous cycle |
bigone | vector of Opencv Points representing the largest contour from qhe_bigone |
Definition at line 1122 of file frame_extraction.cpp.
|
static |
This is the second pass to detect valid contours in a frame. The parameters of the function are set in the T2 section of settings.cfg. Contours are detected based on a relatively loose OpenCV adaptiveThreshold function.
framecnt | int of nth frame retrieved by program |
in_frame | OpenCV matrix image, 16-bit single depth format |
bigone | vector of Opencv Points representing the largest contour from qhe_bigone |
Definition at line 1042 of file frame_extraction.cpp.
|
static |
|
static |
std::string ALPHA_BETA = "-alpha" |
Add-on version number for alpha/beta/release desgination
Definition at line 71 of file frame_extraction.hpp.
int BLACKOUT_THRESH = 51 |
Threshold value for a TOZERO OpenCV thresholding operation. This is used to mask any haze around the moon, making sure the 'night sky' remains black, and prevents a hazy moon from doing strange things to the perceived size of the moon by the dumb algorithm. When finding the the size of the moon halo, all pixels below this value (of max 255) become 0. If you set it too high for your video, you may lose some moon size in the process, but this will not break your bird tracking. User configurable from settings.cfg
Definition at line 249 of file frame_extraction.hpp.
std::string BOXDATA |
Holder for the location of the box data output CSV
Definition at line 138 of file frame_extraction.hpp.
int BOXSIZE |
Minimum dimension of the raw input frame from the video. Set by min_square_dim() e.g. for a 1920x1080 video this will be 1080.
Definition at line 96 of file frame_extraction.hpp.
bool CAUGHT_EMPTY = false |
Yet another abort error code value. This reports if the box_finder was unable to find a suitable large frame, indicating the moon has vanished.
Definition at line 155 of file frame_extraction.hpp.
bool CONCAT_TIERS = true |
Should the program concatenate the Tiered data into a single file? User configurable from settings.cfg
Definition at line 213 of file frame_extraction.hpp.
int CONVERT_FPS = 30 |
If you convert a video from h264 to mp4 using this program, you must set the framerate here. Different versions of the hardware use different framerates. The latest version (as of winter 2020) are 30 fps, while older versions may have 25 fps. This ONLY supports integer inputs. User configurable from settings.cfg
Definition at line 257 of file frame_extraction.hpp.
bool DEBUG_COUT = false |
Run frame_extraction with OpenCV window for debugging purposes User configurable from settings.cfg
Definition at line 186 of file frame_extraction.hpp.
bool DEBUG_FRAMES = false |
Run frame_extraction with debugging output (prints everything verbose) User configurable from settings.cfg
Definition at line 181 of file frame_extraction.hpp.
int EDGETHRESH = 10 |
Number of Pixels touching the edge of the image to count as "off screen" User configurable from settings.cfg
Definition at line 235 of file frame_extraction.hpp.
std::string ELLIPSEDATA |
Holder for the location of the ellipse data output CSV
Definition at line 134 of file frame_extraction.hpp.
bool EMPTY_FRAMES = true |
Should the program cleanup the generated frame png images on exit? This is ignored if OUTPUT_FRAMES = false User configurable from settings.cfg
Definition at line 197 of file frame_extraction.hpp.
bool GEN_SLIDESHOW = true |
Should the program concatenate the exported frames into a video at the end? This is ignored if OUTPUT_FRAMES = false User configurable from settings.cfg
Definition at line 203 of file frame_extraction.hpp.
std::ofstream LOGGING |
Holder for the output stream created by DEBUG_COUT functions.
Definition at line 114 of file frame_extraction.hpp.
std::string LOGOUT |
Holder for the location of the log file created by DEBUG_COUT functions.
Definition at line 110 of file frame_extraction.hpp.
int MAJOR_VERSION = 0 |
Major version number
Definition at line 63 of file frame_extraction.hpp.
std::string METADATA |
Holder for the location of the metadata file
Definition at line 142 of file frame_extraction.hpp.
int MINOR_VERSION = 3 |
Minor version number
Definition at line 67 of file frame_extraction.hpp.
int NON_ZERO_START = 0 |
Sets the processor to start at a specific frame User configurable from settings.cfg
Definition at line 262 of file frame_extraction.hpp.
double ORIG_AREA |
Area of the largest contour in the first "good" frame, determined by first_frame()
Definition at line 79 of file frame_extraction.hpp.
Point ORIG_BR |
xy coorindates of the bottom right corner of the moon in the first "good" frame, determined by first_frame()
Definition at line 106 of file frame_extraction.hpp.
int ORIG_HORZ |
Width of the largest contour in the first "good" frame, determined by first_frame()
Definition at line 91 of file frame_extraction.hpp.
double ORIG_PERI |
Perimeter of the largest contour in the first "good" frame, determined by first_frame()
Definition at line 83 of file frame_extraction.hpp.
Point ORIG_TL |
xy coorindates of the top left corner of the moon in the first "good" frame, determined by first_frame()
Definition at line 101 of file frame_extraction.hpp.
int ORIG_VERT |
Height of the largest contour in the first "good" frame, determined by first_frame()
Definition at line 87 of file frame_extraction.hpp.
std::string OSFPROJECT = "" |
The project code for the project on OSF (optional) User configurable from settings.cfg
Definition at line 224 of file frame_extraction.hpp.
bool OUTPUT_FRAMES = false |
Should the frame extractor output every frame with detected contours? User configurable from settings.cfg
Definition at line 191 of file frame_extraction.hpp.
std::string OUTPUTDIR = "Birdtracker_Output/" |
The directory where the output data should be put. Default creates a new directory. No quotation marks. Requires a leading slash and trailing slash (e.g. /test/) User configurable from settings.cfg
Definition at line 230 of file frame_extraction.hpp.
int QHE_GB_KERNEL_X = 15 |
Gaussian Blur X kernel size for QHE Bigone. User configurable from settings.cfg
Definition at line 269 of file frame_extraction.hpp.
int QHE_GB_KERNEL_Y = 15 |
Gaussian Blur Y kernel size for QHE Bigone. User configurable from settings.cfg
Definition at line 274 of file frame_extraction.hpp.
double QHE_GB_SIGMA_X = 1 |
Gaussian Blur sigma x value for QHE Bigone. User configurable from settings.cfg
Definition at line 279 of file frame_extraction.hpp.
double QHE_GB_SIGMA_Y = 1 |
Gaussian Blur sigma y value for QHE Bigone. User configurable from settings.cfg
Definition at line 284 of file frame_extraction.hpp.
int QHE_WIDTH = 10 |
Quiet Halo Elimination mask width. How many pixels around the moon halo can be ignored? User configurable from settings.cfg
Definition at line 240 of file frame_extraction.hpp.
int SIG_ALERT = 0 |
Magic number of the ctrl+c interrupt signal in Linux
Definition at line 75 of file frame_extraction.hpp.
bool SIMP_ELL = true |
Should the program attempt to created a simplified file of frames where the edge is off screen? User configurable from settings.cfg
Definition at line 208 of file frame_extraction.hpp.
int T1_AT_BLOCKSIZE = 65 |
Blocksize for adaptive threshold for Tier 1. User configurable from settings.cfg
Definition at line 297 of file frame_extraction.hpp.
double T1_AT_CONSTANT = 35 |
Subtracted constant for adaptive threshold for Tier 1. User configurable from settings.cfg
Definition at line 302 of file frame_extraction.hpp.
double T1_AT_MAX = 255 |
Max value for adaptive threshold for Tier 1. User configurable from settings.cfg
Definition at line 292 of file frame_extraction.hpp.
int T1_DYMASK = 25 |
Width of the dynamic mask around the edge of the moon for Tier 1. User configurable from settings.cfg
Definition at line 307 of file frame_extraction.hpp.
int T2_AT_BLOCKSIZE = 65 |
Blocksize for adaptive threshold for Tier 2. User configurable from settings.cfg
Definition at line 319 of file frame_extraction.hpp.
double T2_AT_CONSTANT = 20 |
Subtracted constant for adaptive threshold for Tier 2. User configurable from settings.cfg
Definition at line 324 of file frame_extraction.hpp.
double T2_AT_MAX = 255 |
Max value for adaptive threshold for Tier 2. User configurable from settings.cfg
Definition at line 314 of file frame_extraction.hpp.
int T2_DYMASK = 25 |
Width of the dynamic mask around the edge of the moon for Tier 2. User configurable from settings.cfg
Definition at line 329 of file frame_extraction.hpp.
int T3_CUTOFF_THRESH = 40 |
Thresholding value unique to Tier 3. Removes items less than the threshold User configurable from settings.cfg
Definition at line 371 of file frame_extraction.hpp.
int T3_DYMASK = 45 |
Width of the dynamic mask application for Tier 3. User configurable from settings.cfg
Definition at line 376 of file frame_extraction.hpp.
int T3_GB_KERNEL_X = 11 |
Gaussian Blur X kernel size for Tier 3. User configurable from settings.cfg
Definition at line 351 of file frame_extraction.hpp.
int T3_GB_KERNEL_Y = 11 |
Gaussian Blur Y kernel size for Tier 3. User configurable from settings.cfg
Definition at line 356 of file frame_extraction.hpp.
double T3_GB_SIGMA_X = 1 |
Gaussian Blur sigma x value for Tier 3. User configurable from settings.cfg
Definition at line 361 of file frame_extraction.hpp.
double T3_GB_SIGMA_Y = 1 |
Gaussian Blur sigma y value for Tier 3. User configurable from settings.cfg
Definition at line 366 of file frame_extraction.hpp.
double T3_LAP_DELTA = 0 |
Delta value of laplacian transform for Tier 3. User configurable from settings.cfg
Definition at line 346 of file frame_extraction.hpp.
int T3_LAP_KERNEL = 11 |
Kernel size of laplacian transform for Tier 3. User configurable from settings.cfg
Definition at line 336 of file frame_extraction.hpp.
double T3_LAP_SCALE = 0.0001 |
Scaling value of laplacian transform for Tier 3. User configurable from settings.cfg
Definition at line 341 of file frame_extraction.hpp.
int T4_AT_BLOCKSIZE = 65 |
Blocksize for adaptive threshold for Tier 4. User configurable from settings.cfg
Definition at line 388 of file frame_extraction.hpp.
double T4_AT_CONSTANT = 20 |
Subtracted constant for adaptive threshold for Tier 4. User configurable from settings.cfg
Definition at line 393 of file frame_extraction.hpp.
double T4_AT_MAX = 255 |
Max value for adaptive threshold for Tier 4. User configurable from settings.cfg
Definition at line 383 of file frame_extraction.hpp.
int T4_DYMASK = 45 |
Width of the dynamic mask application for Tier 4. User configurable from settings.cfg
Definition at line 428 of file frame_extraction.hpp.
int T4_GB_KERNEL_X = 11 |
Gaussian Blur X kernel size for Tier 4. User configurable from settings.cfg
Definition at line 403 of file frame_extraction.hpp.
int T4_GB_KERNEL_Y = 11 |
Gaussian Blur Y kernel size for Tier 4. User configurable from settings.cfg
Definition at line 408 of file frame_extraction.hpp.
double T4_GB_SIGMA_X = 1 |
Gaussian Blur sigma x value for Tier 4. User configurable from settings.cfg
Definition at line 413 of file frame_extraction.hpp.
double T4_GB_SIGMA_Y = 1 |
Gaussian Blur sigma y value for Tier 4. User configurable from settings.cfg
Definition at line 418 of file frame_extraction.hpp.
double T4_POWER = 2 |
"UnCanny" script raises values to this power for Tier 4. User configurable from settings.cfg
Definition at line 398 of file frame_extraction.hpp.
int T4_THINNING = 0 |
Contour Thinning type (see ximgproc::thinning) for Tier 4. User configurable from settings.cfg
Definition at line 423 of file frame_extraction.hpp.
int TC_H |
Calculated height to use for tight cropping
Definition at line 150 of file frame_extraction.hpp.
int TC_W |
Calcualted width to use for tight cropping
Definition at line 146 of file frame_extraction.hpp.
std::string TIER1FILE |
Holder for the location of the Tier 1 data output CSV
Definition at line 118 of file frame_extraction.hpp.
std::string TIER2FILE |
Holder for the location of the Tier 2 data output CSV
Definition at line 122 of file frame_extraction.hpp.
std::string TIER3FILE |
Holder for the location of the Tier 3 data output CSV
Definition at line 126 of file frame_extraction.hpp.
std::string TIER4FILE |
Holder for the location of the Tier 4 data output CSV
Definition at line 130 of file frame_extraction.hpp.
bool TIGHT_CROP = true |
Tight crop the output frames when generating the slideshow? This is ignored if OUTPUT_FRAMES = false User configurable from settings.cfg
Definition at line 219 of file frame_extraction.hpp.