Aircraft Detection 1.0
|
#include "utils.h"
Functions | |
double | degrees2rad (double degrees) |
Converts degrees to radians. | |
double | rad2degrees (double radians) |
Converts radians to degrees. | |
bool | sortByDescendingArea (const object &first, const object &second) |
Comparator function to sort contours by descending area. | |
cv::Mat | rotate90 (cv::Mat img, int step) |
Rotates an image by multiples of 90 degrees clockwise. | |
std::filesystem::path | createDirectory (const std::filesystem::path &folder_path, const std::string &directory_name) |
Creates a new directory if it does not already exist. | |
void | globFiles (const std::string &directory, const std::string &pattern, std::vector< std::string > &file_paths) |
Retrieves a list of file paths that match a specified pattern in a directory. | |
void | readImages (const std::vector< std::string > &img_paths, std::vector< cv::Mat > &images, int flags) |
Reads images from a list of file paths and stores them in a vector. | |
void | processYoloLabels (const std::string &filePath, const cv::Mat &img, std::vector< cv::Rect > &yolo_boxes) |
Processes YOLO labels from a file and converts them to bounding boxes. | |
cv::Rect | Yolo2BRect (const cv::Mat &img, double x_center, double y_center, double width, double height) |
Converts YOLO format bounding box coordinates to a cv::Rect . | |
bool | isRoiInImage (const cv::Rect &roi, int width, int height) |
Checks if a region of interest (ROI) is completely within the image boundaries. | |
std::vector< cv::Rect > | readYoloBoxes (const std::filesystem::path &file_path, const cv::Mat &img) |
Reads YOLO bounding boxes from a file and converts them to OpenCV cv::Rect format. | |
std::ofstream | openFile (const std::string &filename) |
Opens a file for writing and returns the output file stream. | |
std::vector< cv::Rect > | generateRoisFromPoints (const std::vector< cv::Point > &points, const std::vector< cv::Size > &roi_sizes) |
Generates regions of interest (ROIs) from a set of points and ROI sizes. | |
cv::Size | calculateAvgDims (const std::filesystem::path &directory_path) |
Calculates the average dimensions of all images in a specified directory. | |
void | reshape2sameDim (std::vector< cv::Mat > &clustered_imgs_by_intensity, const cv::Size &avg_dim) |
Resizes a vector of images to the same dimensions. | |
double | euclidean_distance (const cv::Point &a, const cv::Point &b) |
Calculates the Euclidean distance between two points. | |
std::vector< cv::Point > | filterPointsByMinDistance (std::vector< cv::Point > &points, double min_distance) |
Filters a set of points by a minimum distance criterion. | |
void | listDirectories (const std::filesystem::path &directory_path, std::vector< std::string > &final_paths) |
Recursively lists all leaf directories within a specified directory. | |
void | imshow (const std::string &win_name, cv::InputArray arr, bool wait, float scale) |
int | bitdepth (int ocv_depth) |
Variables | |
constexpr double | PI = 3.14159265358979323846 |
int bitdepth | ( | int | ocv_depth | ) |
cv::Size calculateAvgDims | ( | const std::filesystem::path & | directory_path | ) |
Calculates the average dimensions of all images in a specified directory.
This function reads all PNG images in the specified directory and calculates the average width and height of the images. It returns the average dimensions as a cv::Size
object.
[in] | directory_path | The path to the directory containing the images. |
cv::Size
object representing the average width and height of the images.std::runtime_error | If no images are found in the directory or if any image fails to load. |
std::filesystem::path createDirectory | ( | const std::filesystem::path & | folder_path, |
const std::string & | directory_name ) |
Creates a new directory if it does not already exist.
This function takes a base folder path and a directory name, creates the directory if it does not already exist, and returns the path to the created directory.
[in] | folder_path | The base path where the new directory will be created. |
[in] | directory_name | The name of the directory to be created. |
std::filesystem::path
object representing the path to the created directory.double degrees2rad | ( | double | degrees | ) |
Converts degrees to radians.
This function converts an angle from degrees to radians.
[in] | degrees | The angle in degrees. |
double euclidean_distance | ( | const cv::Point & | a, |
const cv::Point & | b ) |
Calculates the Euclidean distance between two points.
This function computes the Euclidean distance between two points a
and b
using the OpenCV cv::norm
function.
[in] | a | The first point. |
[in] | b | The second point. |
std::vector< cv::Point > filterPointsByMinDistance | ( | std::vector< cv::Point > & | points, |
double | min_distance ) |
Filters a set of points by a minimum distance criterion.
This function filters a vector of points, selecting only those points that are not closer than a specified minimum distance to any previously selected points. The points are first sorted by their coordinates to ensure consistent results.
[in,out] | points | A vector of cv::Point objects representing the points to be filtered. The vector is sorted by coordinates. |
[in] | min_distance | The minimum distance required between any two selected points. |
cv::Point
objects representing the points that meet the minimum distance criterion.std::vector< cv::Rect > generateRoisFromPoints | ( | const std::vector< cv::Point > & | points, |
const std::vector< cv::Size > & | roi_sizes ) |
Generates regions of interest (ROIs) from a set of points and ROI sizes.
This function takes a vector of points and a vector of ROI sizes, and generates ROIs centered at each point with each of the given sizes. It ensures that the generated ROIs are within the image boundaries before adding them to the output vector.
[in] | points | A vector of cv::Point objects representing the centers of the ROIs. |
[in] | roi_sizes | A vector of cv::Size objects representing the sizes of the ROIs. |
cv::Rect
objects representing the valid ROIs.isRoiInImage
function is defined and checks if an ROI is within the image boundaries.void globFiles | ( | const std::string & | directory, |
const std::string & | pattern, | ||
std::vector< std::string > & | file_paths ) |
Retrieves a list of file paths that match a specified pattern in a directory.
This function uses the OpenCV cv::glob
function to find all files in the specified directory that match the given pattern and stores the paths of these files in a vector.
[in] | directory | The directory in which to search for files. |
[in] | pattern | The pattern to match files against, such as "*.png". |
[out] | file_paths | A vector of strings where the matching file paths will be stored. |
void imshow | ( | const std::string & | win_name, |
cv::InputArray | arr, | ||
bool | wait, | ||
float | scale ) |
bool isRoiInImage | ( | const cv::Rect & | roi, |
int | width, | ||
int | height ) |
Checks if a region of interest (ROI) is completely within the image boundaries.
This function checks whether a given ROI is entirely contained within the boundaries of an image with the specified width and height.
[in] | roi | The region of interest represented as a cv::Rect . |
[in] | width | The width of the image. |
[in] | height | The height of the image. |
true
if the ROI is completely within the image boundaries, false
otherwise. void listDirectories | ( | const std::filesystem::path & | directory_path, |
std::vector< std::string > & | final_paths ) |
Recursively lists all leaf directories within a specified directory.
This function traverses the directory tree starting from the specified directory path and collects the paths of all leaf directories (directories that do not contain any subdirectories).
[in] | directory_path | The path to the directory to start the traversal from. |
[out] | final_paths | A vector of strings to store the paths of all leaf directories. |
std::ofstream openFile | ( | const std::string & | filename | ) |
Opens a file for writing and returns the output file stream.
This function opens a file with the specified filename for writing. If the file cannot be opened, it throws a std::runtime_error
.
[in] | filename | The name of the file to be opened. |
std::ofstream
object representing the opened file stream.std::runtime_error | If the file cannot be opened. |
void processYoloLabels | ( | const std::string & | filePath, |
const cv::Mat & | img, | ||
std::vector< cv::Rect > & | yolo_boxes ) |
Processes YOLO labels from a file and converts them to bounding boxes.
This function reads a YOLO label file and converts the normalized bounding box coordinates to cv::Rect
objects representing the bounding boxes in the image. The bounding boxes are then stored in a vector.
[in] | filePath | The path to the YOLO label file. |
[in] | img | The image in which the bounding boxes are defined. |
[out] | yolo_boxes | A vector of cv::Rect objects where the converted bounding boxes will be stored. |
center_x
, center_y
, width
, and height
are normalized coordinates. double rad2degrees | ( | double | radians | ) |
Converts radians to degrees.
This function converts an angle from radians to degrees.
[in] | radians | The angle in radians. |
void readImages | ( | const std::vector< std::string > & | img_paths, |
std::vector< cv::Mat > & | images, | ||
int | flags ) |
Reads images from a list of file paths and stores them in a vector.
This function iterates through a list of image file paths, reads each image using OpenCV's cv::imread
function with the specified flags, and stores the successfully read images in a vector.
[in] | img_paths | A vector of strings representing the paths to the image files to be read. |
[out] | images | A vector of cv::Mat objects where the successfully read images will be stored. |
[in] | flags | The flag that specifies the way the image should be read. This is passed to cv::imread . |
std::vector< cv::Rect > readYoloBoxes | ( | const std::filesystem::path & | file_path, |
const cv::Mat & | img ) |
Reads YOLO bounding boxes from a file and converts them to OpenCV cv::Rect
format.
This function reads a file containing YOLO format bounding box coordinates and converts them to OpenCV cv::Rect
objects, which are stored in a vector. The YOLO format assumes normalized coordinates in the range [0, 1].
[in] | file_path | The path to the file containing YOLO bounding box coordinates. |
[in] | img | The image for which the bounding boxes are defined. Used to convert normalized coordinates to pixel values. |
cv::Rect
objects representing the bounding boxes.std::runtime_error | If the file cannot be opened. |
void reshape2sameDim | ( | std::vector< cv::Mat > & | clustered_imgs_by_intensity, |
const cv::Size & | avg_dim ) |
Resizes a vector of images to the same dimensions.
This function resizes each image in a vector of images to the specified average dimensions.
[in,out] | clustered_imgs_by_intensity | A vector of cv::Mat objects representing the images to be resized. |
[in] | avg_dim | The target dimensions to which all images will be resized. |
cv::Mat rotate90 | ( | cv::Mat | img, |
int | step ) |
Rotates an image by multiples of 90 degrees clockwise.
This function rotates the input image by a specified number of 90-degree steps clockwise. The valid step values are 0 (no rotation), 1 (90 degrees), 2 (180 degrees), and 3 (270 degrees).
[in] | img | The input image to be rotated. |
[in] | step | The number of 90-degree steps to rotate the image. A negative value is converted to its positive equivalent. |
cv::Mat
object representing the rotated image.cv::transpose
and cv::flip
to perform the rotations. step
is greater than 3, it is reduced modulo 4 to ensure a valid number of steps.Comparator function to sort contours by descending area.
This function compares the areas of two contours and returns true
if the area of the first contour is greater than the area of the second contour.
[in] | first | The first contour. |
[in] | second | The second contour. |
true
if the area of the first contour is greater than the area of the second contour, false
otherwise.cv::Rect Yolo2BRect | ( | const cv::Mat & | img, |
double | x_center, | ||
double | y_center, | ||
double | width, | ||
double | height ) |
Converts YOLO format bounding box coordinates to a cv::Rect
.
This function converts normalized YOLO bounding box coordinates (center x, center y, width, height) to a cv::Rect
with pixel coordinates, ensuring the bounding box is within the image boundaries.
[in] | img | The image for which the bounding box is defined. |
[in] | x_center | The normalized x coordinate of the bounding box center. |
[in] | y_center | The normalized y coordinate of the bounding box center. |
[in] | width | The normalized width of the bounding box. |
[in] | height | The normalized height of the bounding box. |
cv::Rect
representing the bounding box in pixel coordinates. If the bounding box falls outside the image boundaries, an empty cv::Rect
is returned.cv::Rect
is returned.
|
constexpr |