CPP_Birdtracker
A C++ object tracking program specifically for lunar bird tracking
Functions
frame_extraction.cpp File Reference
#include "frame_extraction.hpp"
Include dependency graph for frame_extraction.cpp:

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[])
 

Function Documentation

◆ apply_dynamic_mask()

static Mat apply_dynamic_mask ( Mat  in_frame,
vector< Point >  contour,
int  maskwidth 
)
static

This function masks out the edges of the input frame based on the contour. The maskwidth determines how much to mask out.

Parameters
in_frameOpenCV matrix image, 16-bit single depth format
contourOpenCV Point vectors of int-int point contour edges. Use the output from "bigone" here.
maskwidth
Returns
in_frame The modified in_frame from the input params

Definition at line 757 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ box_data()

static int box_data ( Rect  box,
int  framecnt 
)
static
Parameters
in_frameOpenCV matrix image, 16-bit single depth format
framecntint of nth frame retrieved by program
Returns
status

Definition at line 845 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ box_finder()

static int box_finder ( Mat  in_frame,
bool  do_thresh 
)
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.

Parameters
in_frameOpenCV matrix image, 16-bit single depth format
Returns
status

Definition at line 808 of file frame_extraction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ concat_tiers()

static int concat_tiers ( )
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

Returns
status

Definition at line 1774 of file frame_extraction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ contours_only()

static vector<vector<Point> > contours_only ( Mat  in_frame)
static

This function returns the contours from an image. It really only needs to exist because repeatedly declaring the unused hierarchy is tedious.

Parameters
in_frameOpenCV matrix image, 16-bit single depth format
Returns
vector of int-int OpenCV Point vectors for each contour detected in the in_frame

Definition at line 794 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ corner_matching()

static Mat corner_matching ( Mat  in_frame,
vector< Point >  contour,
int  plusx,
int  plusy 
)
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.

Parameters
in_frameOpenCV matrix image, 16-bit single depth format
contourOpenCV contour, a vector of int int points
plusxhorizontal deviation of contour in pixels
plusyvertical deviation of contour in pixels
Returns
in_frame The modified in_frame from the input params

Definition at line 101 of file frame_extraction.cpp.

Here is the call graph for this function:

◆ edge_height()

static vector<int> edge_height ( vector< Point >  contour)
static

This function determines the length of the extreme left and right edges of the moon contour.

Parameters
contourOpenCV contour, a vector of int int points
Returns
local_vec integer vector of the left and right edge length of the moon

Definition at line 279 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ edge_width()

static vector<int> edge_width ( vector< Point >  contour)
static

This function determines the length of the extreme top and bottom edges of the moon contour.

Parameters
contourOpenCV contour, a vector of int int points
Returns
local_vec integer vector of the top and bottom edge length of the moon

Definition at line 249 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ edit_contours_for_crop()

static int edit_contours_for_crop ( )
static

Definition at line 1539 of file frame_extraction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ first_frame()

static int first_frame ( Mat  in_frame,
int  framecnt 
)
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.

Parameters
in_frameOpenCV matrix image, 16-bit single depth format
framecntint of nth frame retrieved by program
Returns
in_frame The modified in_frame from the input params

Definition at line 490 of file frame_extraction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_slideshow()

static int generate_slideshow ( )
static

Definition at line 1705 of file frame_extraction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_max_ellipse_params()

static int get_max_ellipse_params ( )
static

Determines the maximum width and height of the moon bounding box encountered in the video.

Returns
out_vec a vector of ints including the maximum width and height of the moon.

Definition at line 1652 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ halo_noise_and_center()

static int halo_noise_and_center ( Mat  in_frame,
int  framecnt 
)
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

Parameters
in_frameOpenCV matrix image, 16-bit single depth format
framecntint of nth frame retrieved by program
Returns
status

Definition at line 646 of file frame_extraction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initial_crop()

static int initial_crop ( Mat  in_frame,
int  framecnt 
)
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.

Parameters
in_frameOpenCV matrix image, 16-bit single depth format
framecntint of nth frame retrieved by program
Returns
status

Definition at line 313 of file frame_extraction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ largest_contour()

static int largest_contour ( vector< vector< Point >>  contours)
static

This function returns the index of the largest contour in a list of contours so it can be accessed in future functions.

Parameters
contoursvector of OpenCV vectors of int-int point contour edges
Returns
largest_contour_index integer index of the largest contour in a vector of contour vectors

Definition at line 771 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main loop

Parameters
argcnumber of input arguments
argvcontents of input arguments
Returns
status

Definition at line 2056 of file frame_extraction.cpp.

Here is the call graph for this function:

◆ min_square_dim()

static int min_square_dim ( Mat  in_frame)
static

This function stores the BOXSIZE variable globally. BOXSIZE is the shortest side of the input image dimensions.

Parameters
in_frameOpenCV matrix image, 16-bit single depth format
Returns
status

Definition at line 233 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ off_screen_ellipse()

static int off_screen_ellipse ( )
static

Simplifies the ellipse.csv file to only report frames where the ellispe goes off screen. Creates a new file offscreen_moon.csv

Returns
status

Definition at line 1899 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ out_frame_gen()

static std::string out_frame_gen ( int  framecnt)
static

This helper function assembles the output location for frames stored by the script.

Parameters
framecntint of nth frame retrieved by program
Returns
outstring the constructed path string of where to store the nth frame

Definition at line 1513 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ parse_checklist()

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.

Parameters
nameString obtained while parsing the settings.cfg file
valueThe value associated with name from settings.cfg file
Returns
status

Definition at line 1328 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ post_processing()

static int post_processing ( )
static

Holder function for processes which run after the bulk of main completes

Returns
status

Definition at line 1989 of file frame_extraction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ qhe_bigone()

static vector<Point> qhe_bigone ( Mat  in_frame)
static

Finds the largest contour within the frame after masking. Called from main thread to prevent waste of CPU time for each tier.

Parameters
in_frameOpenCV matrix image, 16-bit single depth format
Returns
bigone vector of cv Points representing the largest frame in the image

Definition at line 891 of file frame_extraction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ quiet_halo_elim()

static vector<vector<Point> > quiet_halo_elim ( vector< vector< Point >>  contours,
vector< Point >  bigone 
)
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.

Parameters
contoursvector of OpenCV vectors of int-int point contour edges
bigonevector of Opencv Points representing the largest contour from qhe_bigone
Returns
out_contours vector of OpenCV int-int Point vectors representing valid contours

Definition at line 921 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ shift_frame()

static Mat shift_frame ( Mat  in_frame,
int  shiftx,
int  shifty 
)
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.

Parameters
in_frameOpenCV matrix image, 16-bit single depth format
shiftxnumber of pixels the cropped image should be shifted in the horizontal direction
shiftynumber of pixels the cropped image should be shifted in the vertical direction
Returns
in_frame The modified in_frame from the input params

Definition at line 38 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ show_usage()

static int show_usage ( string  name)
static

This is a helper function called using -h in terminal.

Parameters
name
Returns
status

Definition at line 872 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ signal_callback_handler()

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.

Parameters
signumsignal number passed to this function. Only handles 2.

Definition at line 738 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ space_space()

std::string space_space ( std::string  instring)

This helper function handles spaces in user paths.

Parameters
instringthe input string
Returns
outstring the corrected string

Definition at line 1526 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ tail()

std::string tail ( std::string const &  source,
size_t const  length 
)

Get the last n characters of a string. Handles incorrectly sized searches.

Parameters
sourceInput string
lengthNumber of characters from the back to return

Definition at line 2042 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ test_edges()

static vector<int> test_edges ( Mat  in_frame,
vector< Point >  contour,
int  te_ret 
)
static

This function tests the moon contour to determine the degree of shift required to center it in a frame.

Parameters
in_frameOpenCV matrix image, 16-bit single depth format
contourOpenCV contour, a vector of int int points
Returns
outplus integer vector of horizontal and vertical deviation of the primary contour

Definition at line 177 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ tier_four()

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.

Parameters
framecntint of nth frame retrieved by program
in_frameOpenCV matrix image, 16-bit single depth format
old_frameOpenCV matrix image, 16-bit single depth format, stored from previous cycle
bigonevector of Opencv Points representing the largest contour from qhe_bigone
Returns
status

Definition at line 1229 of file frame_extraction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tier_one()

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".

Parameters
framecntint of nth frame retrieved by program
in_frameOpenCV matrix image, 16-bit single depth format
bigonevector of Opencv Points representing the largest contour from qhe_bigone
Returns
status

Definition at line 964 of file frame_extraction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tier_three()

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.

Parameters
framecntint of nth frame retrieved by program
in_frameOpenCV matrix image, 16-bit single depth format
old_frameOpenCV matrix image, 16-bit single depth format, stored from previous cycle
bigonevector of Opencv Points representing the largest contour from qhe_bigone
Returns
status

Definition at line 1122 of file frame_extraction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tier_two()

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.

Parameters
framecntint of nth frame retrieved by program
in_frameOpenCV matrix image, 16-bit single depth format
bigonevector of Opencv Points representing the largest contour from qhe_bigone
Returns
status

Definition at line 1042 of file frame_extraction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ touching_edges()

static int touching_edges ( Mat  in_frame,
vector< Point >  contour 
)
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:

  • -1 : error status
  • 0 : no edge touching
  • 1 : touching left edge only
  • 2 : touching right edge only
  • 3 : touching top and left edge
  • 4 : touching bottom and left edge
  • 5 : touching top and right edge
  • 6 : touching bottom and right edge
Parameters
in_frameOpenCV matrix image, 16-bit single depth format
contourOpenCV contour, a vector of int int points
Returns
touching_status an integer value representing if and which edge of the frame is touched by the contour. Returns negative status values if something went wrong.

Definition at line 422 of file frame_extraction.cpp.

Here is the caller graph for this function:

◆ traditional_centering()

static Mat traditional_centering ( Mat  in_frame,
vector< vector< Point >>  contours,
int  largest,
Rect  box 
)
static

Definition at line 456 of file frame_extraction.cpp.

Here is the caller graph for this function: