Aircraft Detection 1.0
|
Functions | |
void | selectAirplanes (const cv::Mat &img, const std::vector< cv::Rect > &yolo_boxes, std::vector< cv::Rect > &selected_airplanes_yolo_boxes, int &count, const std::string &img_filename, const std::filesystem::path &straight_airplanes_folder) |
Selects and processes airplane images based on user input. | |
void | binarizeAirplanes (const cv::Mat &channel, const std::vector< cv::Rect > &selected_airplanes_yolo_boxes, std::vector< cv::Mat > &bin_airplanes) |
Binarizes regions of interest (ROIs) in an image using adaptive thresholding. | |
void | calculateGeometricMoments (const std::vector< cv::Mat > &bin_airplanes, const std::vector< cv::Rect > &yolo_boxes, std::vector< std::pair< cv::Point2f, double > > &geometric_moments_descriptors) |
Calculates geometric moments for a set of binary airplane images and corresponding YOLO bounding boxes. | |
void | saveStraightAirplanes (const std::vector< cv::Mat > &airplanes, int &count, const std::string &img_filename, const std::filesystem::path &straight_airplanes_folder) |
Displays and optionally saves a list of airplane images after user confirmation and optional rotation. | |
void | saveAirplane (const cv::Mat &airplane, int &count, const std::string &img_filename, const std::filesystem::path &straight_airplane_folder) |
Saves an airplane image to a specified directory with a unique filename. | |
void | extractRotatedAirplanes (const cv::Mat &img, const std::vector< cv::Mat > &bin_airplanes, const std::vector< std::pair< cv::Point2f, double > > &geometric_moments_descriptors, const std::vector< cv::Rect > &yolo_boxes, std::vector< cv::Mat > &airplanes_vector) |
Extracts and rotates airplane images from the input image based on geometric moments and YOLO bounding boxes. | |
std::string | getValidInput (const std::string &prompt, const std::vector< std::string > &valid_inputs) |
Prompts the user for input until a valid input is provided. | |
cv::Mat | getBoundarySafeROI (const cv::Mat &img, cv::Rect &roi) |
Extracts a region of interest (ROI) from an image, ensuring it stays within image boundaries. | |
void | extractStraightAirplanes () |
Extracts, processes, and saves straightened airplane images from a dataset. | |
double | correctAngle (double angle) |
Corrects the orientation angle of an airplane image. | |
cv::Rect | calculateCenteredROI (const cv::Point2f ¢er, const cv::Size &size, float scale_factor) |
Calculates a centered region of interest (ROI) around a given point with a specified size and scale factor. | |
void binarizeAirplanes | ( | const cv::Mat & | channel, |
const std::vector< cv::Rect > & | selected_airplanes_yolo_boxes, | ||
std::vector< cv::Mat > & | bin_airplanes ) |
Binarizes regions of interest (ROIs) in an image using adaptive thresholding.
This function extracts specified ROIs from an image channel, applies adaptive thresholding to binarize them, and performs morphological dilation to enhance the binary images. The resulting binary images are stored in an output vector.
[in] | channel | The input image channel from which the ROIs are extracted. |
[in] | selected_airplanes_yolo_boxes | A vector of cv::Rect objects representing the ROIs to be binarized. |
[out] | bin_airplanes | A vector of cv::Mat objects to store the resulting binary images. |
C
is used to fine-tune the thresholding. cv::Rect calculateCenteredROI | ( | const cv::Point2f & | center, |
const cv::Size & | size, | ||
float | scale_factor ) |
Calculates a centered region of interest (ROI) around a given point with a specified size and scale factor.
This function computes a rectangular ROI centered at the given point, with dimensions scaled by the specified scale factor.
[in] | center | The center point around which the ROI is calculated. |
[in] | size | The size of the ROI before scaling. |
[in] | scale_factor | The factor by which the size of the ROI is scaled. |
cv::Rect
representing the calculated ROI.void calculateGeometricMoments | ( | const std::vector< cv::Mat > & | bin_airplanes, |
const std::vector< cv::Rect > & | yolo_boxes, | ||
std::vector< std::pair< cv::Point2f, double > > & | geometric_moments_descriptors ) |
Calculates geometric moments for a set of binary airplane images and corresponding YOLO bounding boxes.
This function computes the geometric moments for each binary airplane image, calculates the center and orientation angle, and adjusts the center based on the corresponding YOLO bounding box. The results are stored in a vector of pairs, where each pair contains the corrected center point and the orientation angle in degrees.
[in] | bin_airplanes | A vector of binary cv::Mat objects representing the segmented airplanes. |
[in] | yolo_boxes | A vector of cv::Rect objects representing the YOLO bounding boxes for each airplane. |
[out] | geometric_moments_descriptors | A vector of pairs where each pair contains the corrected center point (cv::Point2f ) and the orientation angle (double ) in degrees for each airplane. |
double correctAngle | ( | double | angle | ) |
Corrects the orientation angle of an airplane image.
This function adjusts the orientation angle of an airplane image to ensure it is within a specific range. If the angle is between 0 and 90 degrees, it adds 90 degrees to the angle. If the angle is negative, it adjusts the angle to be within the 0-180 degree range.
[in] | angle | The original orientation angle of the airplane in degrees. |
void extractRotatedAirplanes | ( | const cv::Mat & | img, |
const std::vector< cv::Mat > & | bin_airplanes, | ||
const std::vector< std::pair< cv::Point2f, double > > & | geometric_moments_descriptors, | ||
const std::vector< cv::Rect > & | yolo_boxes, | ||
std::vector< cv::Mat > & | airplanes_vector ) |
Extracts and rotates airplane images from the input image based on geometric moments and YOLO bounding boxes.
This function processes binary airplane images and their corresponding geometric moments and YOLO bounding boxes to extract, rotate, and resize the airplanes. The resulting straightened airplane images are stored in the output vector.
The steps are as follows:
[in] | img | The input image from which the airplanes are extracted. |
[in] | bin_airplanes | A vector of binary cv::Mat objects representing the segmented airplanes. |
[in] | geometric_moments_descriptors | A vector of pairs containing the center points and angles (in degrees) for each airplane. |
[in] | yolo_boxes | A vector of cv::Rect objects representing the YOLO bounding boxes for each airplane. |
[out] | airplanes_vector | A vector of cv::Mat objects to store the extracted and rotated airplane images. |
void extractStraightAirplanes | ( | ) |
Extracts, processes, and saves straightened airplane images from a dataset.
This function processes a dataset of images and their corresponding YOLO label files to extract, straighten, and save airplane images. It performs the following steps:
straight_airplanes
directory within the source directory.cv::Mat getBoundarySafeROI | ( | const cv::Mat & | img, |
cv::Rect & | roi ) |
Extracts a region of interest (ROI) from an image, ensuring it stays within image boundaries.
This function checks if the specified ROI is within the boundaries of the given image. If the ROI is within boundaries, it returns the corresponding sub-image. If the ROI exceeds the image boundaries, it pads the image using reflection border, adjusts the ROI, and then extracts the sub-image.
[in] | img | The input image from which the ROI is extracted. |
[in,out] | roi | The region of interest specified as a cv::Rect . If the ROI exceeds the image boundaries, it is adjusted to fit within the padded image. |
cv::Mat
containing the extracted sub-image corresponding to the ROI.std::string getValidInput | ( | const std::string & | prompt, |
const std::vector< std::string > & | valid_inputs ) |
Prompts the user for input until a valid input is provided.
This function displays a prompt to the user and reads the user's input. It continues to prompt the user until a valid input from the provided list is entered.
[in] | prompt | The message displayed to the user when asking for input. |
[in] | valid_inputs | A vector of strings representing the valid inputs. |
void saveAirplane | ( | const cv::Mat & | airplane, |
int & | count, | ||
const std::string & | img_filename, | ||
const std::filesystem::path & | straight_airplane_folder ) |
Saves an airplane image to a specified directory with a unique filename.
This function saves the provided airplane image to a specified directory. The filename is generated using a count and the original image filename.
[in] | airplane | The cv::Mat object representing the airplane image to be saved. |
[in,out] | count | An integer counter used to generate unique filenames for the saved images. It is incremented with each call to the function. |
[in] | img_filename | The original filename of the image, used as part of the new filename. |
[in] | straight_airplane_folder | The path to the directory where the image will be saved. |
void saveStraightAirplanes | ( | const std::vector< cv::Mat > & | airplanes, |
int & | count, | ||
const std::string & | img_filename, | ||
const std::filesystem::path & | straight_airplanes_folder ) |
Displays and optionally saves a list of airplane images after user confirmation and optional rotation.
This function iterates through a list of airplane images, displaying each one to the user. The user can choose to save each image, optionally rotating it before saving. The saved images are stored in a specified directory with unique filenames.
[in] | airplanes | A vector of cv::Mat objects representing the airplane images to be processed. |
[in,out] | count | An integer counter used to generate unique filenames for the saved images. It is incremented with each saved image. |
[in] | img_filename | The original filename of the image, used as part of the new filename. |
[in] | straight_airplanes_folder | The path to the directory where the images will be saved. |
void selectAirplanes | ( | const cv::Mat & | img, |
const std::vector< cv::Rect > & | yolo_boxes, | ||
std::vector< cv::Rect > & | selected_airplanes_yolo_boxes, | ||
int & | count, | ||
const std::string & | img_filename, | ||
const std::filesystem::path & | straight_airplanes_folder ) |
Selects and processes airplane images based on user input.
This function iterates through a list of YOLO bounding boxes, displays each corresponding airplane image to the user, and prompts the user to decide whether to process and select the airplane. The user can also choose to rotate and save the airplane image.
[in] | img | The input image containing the airplanes. |
[in] | yolo_boxes | A vector of cv::Rect objects representing the YOLO bounding boxes for each airplane. |
[out] | selected_airplanes_yolo_boxes | A vector of cv::Rect objects to store the selected YOLO bounding boxes for further processing. |
[in,out] | count | An integer counter used to generate unique filenames for the saved images. It is incremented with each saved image. |
[in] | img_filename | The original filename of the image, used as part of the new filename. |
[in] | straight_airplanes_folder | The path to the directory where the processed images will be saved. |
selected_airplanes_yolo_boxes
vector.