Aircraft Detection 1.0
Loading...
Searching...
No Matches
pipeline.cpp File Reference
#include "pipeline.h"
#include "hog_features_extraction.h"
#include "utils.h"
#include "template_matching.h"
#include "kmeans.h"
#include "eigenplanes.h"
#include "python_script.h"
#include "svm_training.h"
#include "straight_airplanes_extraction.h"

Functions

void performKMeansBySize ()
 Performs K-Means clustering on extracted templates based on their size and saves the clustered images.
 
void performKMeansByIntensity ()
 Performs K-Means clustering on images based on their intensity and saves the clustered images.
 
void resizeImgsSingleCluster (const std::string &cluster_input_path, const std::filesystem::path &output_base_path, size_t cluster_index)
 Resizes images within a single cluster to the same dimensions and saves them.
 
void resizeImagesAcrossClusters ()
 Resizes images across multiple clusters to the same dimensions and saves them.
 
void generateEigenplanes ()
 Generates average planes (eigenplanes) for clustered images and saves them.
 
void evaluatePerformance ()
 Evaluates the performance of the SVM model.
 
void createCompletionFile (const std::string &step)
 Creates a completion file for a specified step.
 
void checkPreviousStep (const std::string &current_step)
 Checks if the previous step required for the current step has been executed.
 
void parseArguments (int argc, char **argv, std::vector< std::string > &steps)
 Parses command-line arguments to extract the list of steps to be executed.
 
void executeStep (const std::string &step)
 Executes the specified step if it is defined in the step functions map.
 
void printHelp ()
 Prints the help message for the Aircraft Detection Project.
 

Variables

const std::filesystem::path stepStatePath = std::filesystem::path(SRC_DIR_PATH)/ "steps_completed"
 
const std::unordered_map< std::string, std::string > stepDependencies
 Defines the dependencies between steps.
 
std::unordered_map< std::string, std::function< void()> > stepFunctions
 Maps step names to their corresponding functions.
 

Function Documentation

◆ checkPreviousStep()

void checkPreviousStep ( const std::string & current_step)

Checks if the previous step required for the current step has been executed.

This function verifies if the step that the current step depends on has been executed by checking for the existence of a corresponding ".done" file. If the previous step has not been executed, it throws a runtime error.

Parameters
[in]current_stepThe name of the current step to be executed.
Exceptions
std::runtime_errorIf the previous step required for the current step has not been executed.

◆ createCompletionFile()

void createCompletionFile ( const std::string & step)

Creates a completion file for a specified step.

This function creates a directory for step state files if it does not exist, and then creates an empty file named "<step>.done" to indicate the completion of the specified step.

Parameters
[in]stepThe name of the step for which to create the completion file.

◆ evaluatePerformance()

void evaluatePerformance ( )

Evaluates the performance of the SVM model.

This function runs a Python script to evaluate the performance of the SVM model. The script calculates various performance metrics and displays the results.

See also
configureAndRunPythonScript

◆ executeStep()

void executeStep ( const std::string & step)

Executes the specified step if it is defined in the step functions map.

This function looks up the specified step in the map of step functions and executes the corresponding function if it is found. If the step is not found, it prints an error message and displays the help information.

Parameters
[in]stepThe name of the step to be executed.
See also
printHelp

◆ generateEigenplanes()

void generateEigenplanes ( )

Generates average planes (eigenplanes) for clustered images and saves them.

This function reads images from resized cluster directories, computes the average plane for each cluster using PCA, and saves the resulting average planes into a specified directory.

The steps are as follows:

  1. Lists the directories containing resized clusters.
  2. For each resized cluster: a. Reads the images in grayscale. b. Computes the average plane (eigenplane) using PCA. c. Saves the average plane image into the avg_airplanes directory.
Note
This function assumes that the directory SRC_DIR_PATH/resized_clusters exists and contains the images that have been resized and clustered.
See also
readImages
eigenPlanes
calculateAvgDims
createDirectory
cv::glob
cv::imwrite

◆ parseArguments()

void parseArguments ( int argc,
char ** argv,
std::vector< std::string > & steps )

Parses command-line arguments to extract the list of steps to be executed.

This function reads command-line arguments and stores them in a vector of steps.

Parameters
[in]argcThe number of command-line arguments.
[in]argvThe array of command-line argument strings.
[out]stepsA vector of strings where the parsed steps will be stored.

◆ performKMeansByIntensity()

void performKMeansByIntensity ( )

Performs K-Means clustering on images based on their intensity and saves the clustered images.

This function reads images that have been previously clustered by size, performs K-Means clustering based on the intensity of the images, and saves the clustered images into corresponding directories.

The steps are as follows:

  1. Creates a directory for saving the intensity-based clusters.
  2. Lists the directories of size-based clusters.
  3. For each size-based cluster: a. Reads the images in grayscale. b. Performs K-Means clustering based on the intensity of the images. c. Creates directories for each intensity-based cluster within the current size-based cluster. d. Saves the intensity-clustered images into the respective directories.
Note
This function assumes that the directory SRC_DIR_PATH/kmeans_by_size exists and contains the images that have been previously clustered by size.
The number of intensity-based clusters is set to 6.
See also
listDirectories
globFiles
readImages
kmeansByIntensity
createDirectory
saveClusteredImages

◆ performKMeansBySize()

void performKMeansBySize ( )

Performs K-Means clustering on extracted templates based on their size and saves the clustered images.

This function reads images from a specified directory, performs K-Means clustering based on the dimensions of the images, and saves the clustered images into corresponding directories.

The steps are as follows:

  1. Reads image file paths from the specified directory.
  2. Loads the images into a vector of cv::Mat.
  3. Performs K-Means clustering based on the size of the images.
  4. Creates directories for each cluster.
  5. Saves the clustered images into the respective directories.
Note
This function assumes that the directory SRC_DIR_PATH/straight_airplanes exists and contains the images to be clustered.
The number of clusters is set to 5.
See also
globFiles
readImages
kmeansBySize
createDirectory
saveClusteredImages

◆ printHelp()

void printHelp ( )

Prints the help message for the Aircraft Detection Project.

This function displays a detailed help message that includes usage instructions, descriptions of the various steps in the project, and available options.

◆ resizeImagesAcrossClusters()

void resizeImagesAcrossClusters ( )

Resizes images across multiple clusters to the same dimensions and saves them.

This function lists the directories of intensity-based clusters, resizes images within each cluster to the same dimensions, and saves the resized images into corresponding directories within a base output directory.

The steps are as follows:

  1. Creates the base output directory for resized clusters.
  2. Lists the directories containing intensity-based clusters.
  3. For each intensity-based cluster, resizes the images and saves them to the output directory.
Note
This function assumes that the directory SRC_DIR_PATH/kmeans_by_intensity exists and contains the images clustered by intensity.
See also
listDirectories
resizeImgsSingleCluster
createDirectory

◆ resizeImgsSingleCluster()

void resizeImgsSingleCluster ( const std::string & cluster_input_path,
const std::filesystem::path & output_base_path,
size_t cluster_index )

Resizes images within a single cluster to the same dimensions and saves them.

This function reads images from a specified input cluster directory, resizes them to the same dimensions based on the average dimensions of the images, and saves the resized images into a specified output directory.

Parameters
[in]cluster_input_pathThe path to the input directory containing the cluster images.
[in]output_base_pathThe base path to the output directory where resized images will be saved.
[in]cluster_indexThe index of the current cluster, used to name the output directory.
Note
This function assumes that the input directory contains images in .png format.
See also
globFiles
readImages
reshape2sameDim
calculateAvgDims
createDirectory
cv::imwrite

Variable Documentation

◆ stepDependencies

const std::unordered_map<std::string, std::string> stepDependencies
Initial value:
= {
{"KMeansBySize", "extractStraightAirplanes"},
{"KMeansByIntensity", "KMeansBySize"},
{"resizeImagesInClusters", "KMeansByIntensity"},
{"generateEigenplanes", "resizeImagesInClusters"},
{"extract_SVM_Training_Data", "generateEigenplanes"},
{"Performance_evaluation", "extract_SVM_Training_Data"}
}

Defines the dependencies between steps.

This unordered map defines the dependencies between different steps in the process. Each entry maps a step to its required preceding step.

◆ stepFunctions

std::unordered_map<std::string, std::function<void()> > stepFunctions

Maps step names to their corresponding functions.

This unordered map defines the relationship between step names and the functions that implement those steps. Each entry maps a step name to a function that performs the step and creates a completion file upon successful execution.

◆ stepStatePath

const std::filesystem::path stepStatePath = std::filesystem::path(SRC_DIR_PATH)/ "steps_completed"