DarkHelp  v1.9.7-1
C++ API for the neural network framework Darknet
Looking for a C++ dev who knows OpenCV?
I'm looking for work. Hire me!
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
resize_corners.cpp File Reference
#include <filesystem>
#include <fstream>
#include <map>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <opencv2/opencv.hpp>
Include dependency graph for resize_corners.cpp:

Functions

void find_all_images (const std::filesystem::path &root_directory)
 Perform a recursive directory search to find all the images. More...
 
std::string lowercase (const std::string &raw)
 
int main (int argc, char *argv[])
 
cv::Size network_dimensions (-1, -1)
 The size of the network will be parsed from the width=... and height=... lines in the .cfg file. More...
 
void parse_cfg_file (const std::filesystem::path &cfg_file)
 Find the width=... and height=... values from the .cfg file. More...
 
void parse_names_file (const std::filesystem::path &names_file)
 Read the .names file and find all of the corner indexes we need to resize. More...
 
void process_images ()
 Loop through all of the images and resize the corner annotations. More...
 

Variables

std::vector< std::string > annotated_image_filenames
 These are all of the images with annotations that we need to process. More...
 
const int corner_size = 16
 Size to use for corner rectangles. More...
 
std::map< int, std::string > corners
 Annotation indexes, such as 0 -> "tl", 1 -> "tr", ... More...
 
std::map< std::string, int > indexes
 Annotation indexes, such as "tl" -> 0, "tr" -> 1, ... More...
 

Detailed Description

This simple tool looks for classes named "TL", "TR", "BL", and "BR". This is typically used to indicate the corners of objects, where "TL" is "top-left", "BR is "bottom-right", etc. If it finds any of these classes, the tool will then read through all of the existing annotations, resize the corners to a specific size, and re-write the annotation files with the new sizes.

Function Documentation

◆ find_all_images()

void find_all_images ( const std::filesystem::path &  root_directory)

Perform a recursive directory search to find all the images.

Then we exclude anything in DarkMark's image cache or which doesn't have an annotation file. Results are stored in the global variable annotated_image_filenames.

References annotated_image_filenames, and lowercase().

Referenced by main().

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

◆ lowercase()

std::string lowercase ( const std::string &  raw)

Referenced by find_all_images(), parse_cfg_file(), and parse_names_file().

Here is the caller graph for this function:

◆ main()

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

References find_all_images(), parse_cfg_file(), parse_names_file(), and process_images().

Here is the call graph for this function:

◆ network_dimensions()

cv::Size network_dimensions ( 1,
1 
)

The size of the network will be parsed from the width=... and height=... lines in the .cfg file.

Referenced by DarkHelp::NN::init(), DarkHelp::NN::is_initialized(), DarkHelp::NN::network_size(), parse_cfg_file(), DarkHelp::NN::predict_internal_darknet(), DarkHelp::NN::predict_internal_opencv(), DarkHelp::NN::predict_tile(), process_images(), and DarkHelp::NN::reset().

Here is the caller graph for this function:

◆ parse_cfg_file()

void parse_cfg_file ( const std::filesystem::path &  cfg_file)

Find the width=... and height=... values from the .cfg file.

References lowercase(), and network_dimensions().

Referenced by main().

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

◆ parse_names_file()

void parse_names_file ( const std::filesystem::path &  names_file)

Read the .names file and find all of the corner indexes we need to resize.

These classes will have names such as TL, TR, BR, and BL. The search for names is case-insensitive.

References corners, indexes, and lowercase().

Referenced by main().

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

◆ process_images()

void process_images ( )

Loop through all of the images and resize the corner annotations.

References annotated_image_filenames, corner_size, corners, and network_dimensions().

Referenced by main().

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

Variable Documentation

◆ annotated_image_filenames

std::vector<std::string> annotated_image_filenames

These are all of the images with annotations that we need to process.

See also
find_all_images()

Referenced by find_all_images(), and process_images().

◆ corner_size

const int corner_size = 16

Size to use for corner rectangles.

This size is in pixels AFTER the image has been resized to the neural network dimensions! But the only way to do this is to parse the .cfg file for the width and height of the network.

Referenced by process_images().

◆ corners

std::map<int, std::string> corners

Annotation indexes, such as 0 -> "tl", 1 -> "tr", ...

Referenced by parse_names_file(), and process_images().

◆ indexes

std::map<std::string, int> indexes

Annotation indexes, such as "tl" -> 0, "tr" -> 1, ...

Referenced by parse_names_file().