CPP_Birdtracker
A C++ object tracking program specifically for lunar bird tracking
|
#include "frame_extraction.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) |
void | signal_callback_handler (int signum) |
static Mat | apply_dynamic_mask (Mat in_frame, vector< Point > contour, 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) |
int | tier_one (int framecnt, Mat in_frame, vector< Point > bigone) |
int | tier_two (int framecnt, Mat in_frame, vector< Point > bigone) |
int | tier_three (int framecnt, Mat in_frame, Mat old_frame, vector< Point > bigone) |
int | tier_four (int framecnt, Mat in_frame, Mat old_frame, vector< Point > bigone) |
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 | edit_contours_for_crop () |
static int | get_max_ellipse_params () |
static int | generate_slideshow () |
static int | concat_tiers () |
static int | off_screen_ellipse () |
static int | post_processing () |
std::string | tail (std::string const &source, size_t const length) |
int | main (int argc, char *argv[]) |
|
static |
This function masks out the edges of the input frame based on the contour. The maskwidth determines how much to mask out.
in_frame | OpenCV matrix image, 16-bit single depth format |
contour | OpenCV Point vectors of int-int point contour edges. Use the output from "bigone" here. |
maskwidth |
Definition at line 757 of file frame_extraction.cpp.
|
static |
in_frame | OpenCV matrix image, 16-bit single depth format |
framecnt | int of nth frame retrieved by program |
Definition at line 845 of file frame_extraction.cpp.
|
static |
This function finds the bounding box for the largest contour and reports on its properties. Stores OpenCV Rect object bounding the largest contour (presumably the moon) to global BF_BOX.
in_frame | OpenCV matrix image, 16-bit single depth format |
Definition at line 808 of file frame_extraction.cpp.
|
static |
Concatenates the Tiered data files into a single file called mixed_tiers.csv This requires the linux sort function to run because sorting csv in C++ ab initio is painful
Definition at line 1774 of file frame_extraction.cpp.
|
static |
This function returns the contours from an image. It really only needs to exist because repeatedly declaring the unused hierarchy is tedious.
in_frame | OpenCV matrix image, 16-bit single depth format |
Definition at line 794 of file frame_extraction.cpp.
|
static |
If the moon cannot be centered properly using moment methods, this function is called. Here, the corner of the bounding box around the moon in the input frame is matched to the corners detected in the first frame. If the first frame of the video was centered properly, this will produce an output frame which deviates less from the intended centering function. This helps to reduce noise in when the contours are detected across all tiers. Corner matching is determined by comparison against the maximum allowable edge length declared by EDGETHRESH from settings.cfg. If this threshold is violated, corner matching will occur. Otherwise, traditional centering will occur.
in_frame | OpenCV matrix image, 16-bit single depth format |
contour | OpenCV contour, a vector of int int points |
plusx | horizontal deviation of contour in pixels |
plusy | vertical deviation of contour in pixels |
Definition at line 101 of file frame_extraction.cpp.
|
static |
This function determines the length of the extreme left and right edges of the moon contour.
contour | OpenCV contour, a vector of int int points |
Definition at line 279 of file frame_extraction.cpp.
|
static |
This function determines the length of the extreme top and bottom edges of the moon contour.
contour | OpenCV contour, a vector of int int points |
Definition at line 249 of file frame_extraction.cpp.
|
static |
Definition at line 1539 of file frame_extraction.cpp.
|
static |
This function is a special case of the frame preparation steps. It outputs many of the initial values which are used later (globals that start with the ORIG_ template) and omits some of the masking steps not possible on the first frame.
in_frame | OpenCV matrix image, 16-bit single depth format |
framecnt | int of nth frame retrieved by program |
Definition at line 490 of file frame_extraction.cpp.
|
static |
Definition at line 1705 of file frame_extraction.cpp.
|
static |
Determines the maximum width and height of the moon bounding box encountered in the video.
Definition at line 1652 of file frame_extraction.cpp.
|
static |
This function finds the largest contour (presumably the edge of the moon) and attempts to center the cropped image based on the centroid of the contour. It calls corner_matching in cases where the centroid is not an appropriate method for centering. Data from this ellipse are stored in the ellipse.csv file. A small portion of the edge of the moon contour is removed to keep out the noisest portions. Stores modified in_frame to HNC_FRAME global
in_frame | OpenCV matrix image, 16-bit single depth format |
framecnt | int of nth frame retrieved by program |
Definition at line 646 of file frame_extraction.cpp.
|
static |
Performs an initial rough crop on the frame. This constructs a cropped frame which contains the largest contour, but does not necessarily center the contour within the frame. That is handled by halo_noise_and_center by determing whether the centering should use the corner_matching regime or simple centroid to centroid shifting. Stores the cropped in_frame to IC_FRAME global.
in_frame | OpenCV matrix image, 16-bit single depth format |
framecnt | int of nth frame retrieved by program |
Definition at line 313 of file frame_extraction.cpp.
|
static |
This function returns the index of the largest contour in a list of contours so it can be accessed in future functions.
contours | vector of OpenCV vectors of int-int point contour edges |
Definition at line 771 of file frame_extraction.cpp.
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 |
This function stores the BOXSIZE variable globally. BOXSIZE is the shortest side of the input image dimensions.
in_frame | OpenCV matrix image, 16-bit single depth format |
Definition at line 233 of file frame_extraction.cpp.
|
static |
Simplifies the ellipse.csv file to only report frames where the ellispe goes off screen. Creates a new file offscreen_moon.csv
Definition at line 1899 of file frame_extraction.cpp.
|
static |
This helper function assembles the output location for frames stored by the script.
framecnt | int of nth frame retrieved by program |
Definition at line 1513 of file frame_extraction.cpp.
int parse_checklist | ( | std::string | name, |
std::string | value | ||
) |
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 |
Holder function for processes which run after the bulk of main completes
Definition at line 1989 of file frame_extraction.cpp.
|
static |
Finds the largest contour within the frame after masking. Called from main thread to prevent waste of CPU time for each tier.
in_frame | OpenCV matrix image, 16-bit single depth format |
Definition at line 891 of file frame_extraction.cpp.
|
static |
This function removes contours which are near to the edge of the moon halo. This is a quiet kind of masking which does not alter the image, rather it quietly makes contours in violation `disappear'. The distance from the moon edge which is to be masked is determined by QHE_WIDTH from settings.cfg.
contours | vector of OpenCV vectors of int-int point contour edges |
bigone | vector of Opencv Points representing the largest contour from qhe_bigone |
Definition at line 921 of file frame_extraction.cpp.
|
static |
This function performs a shifting crop of the input image based on the values shiftx and shifty. The output image will always have BOXOUT dimensions determined from the size of the original image's shortest side.
in_frame | OpenCV matrix image, 16-bit single depth format |
shiftx | number of pixels the cropped image should be shifted in the horizontal direction |
shifty | number of pixels the cropped image should be shifted in the vertical direction |
Definition at line 38 of file frame_extraction.cpp.
|
static |
This is a helper function called using -h in terminal.
name |
Definition at line 872 of file frame_extraction.cpp.
void signal_callback_handler | ( | int | signum | ) |
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.
std::string tail | ( | std::string const & | source, |
size_t const | length | ||
) |
Get the last n characters of a string. Handles incorrectly sized searches.
source | Input string |
length | Number of characters from the back to return |
Definition at line 2042 of file frame_extraction.cpp.
|
static |
This function tests the moon contour to determine the degree of shift required to center it in a frame.
in_frame | OpenCV matrix image, 16-bit single depth format |
contour | OpenCV contour, a vector of int int points |
Definition at line 177 of file frame_extraction.cpp.
int tier_four | ( | int | framecnt, |
Mat | in_frame, | ||
Mat | old_frame, | ||
vector< Point > | bigone | ||
) |
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.
int tier_one | ( | int | framecnt, |
Mat | in_frame, | ||
vector< Point > | bigone | ||
) |
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.
int tier_three | ( | int | framecnt, |
Mat | in_frame, | ||
Mat | old_frame, | ||
vector< Point > | bigone | ||
) |
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.
int tier_two | ( | int | framecnt, |
Mat | in_frame, | ||
vector< Point > | bigone | ||
) |
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 |
This function tests the input contour boundaries against the boundaries of the frame. It returns a integer value representing the edge(s) which is/are touched by the contour. If no edges are touched, this function returns zero. A negative return value indicates error. Here is a table of potential return values:
in_frame | OpenCV matrix image, 16-bit single depth format |
contour | OpenCV contour, a vector of int int points |
Definition at line 422 of file frame_extraction.cpp.
|
static |