Add support for loading custom label fonts in imglab (#2733)

pull/2735/head
Adrià Arrufat 2 years ago committed by GitHub
parent dc94754607
commit eb5de0d534
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,7 +21,7 @@
#include <dlib/dir_nav.h>
const char* VERSION = "1.19";
const char* VERSION = "1.20";
@ -599,6 +599,7 @@ int main(int argc, char** argv)
parser.add_option("h","Displays this information.");
parser.add_option("v","Display version.");
parser.add_option("font", "Set the label font in the GUI.", 1);
parser.set_group_name("Creating XML files");
parser.add_option("c","Create an XML file named <arg> listing a set of images.",1);
@ -672,6 +673,8 @@ int main(int argc, char** argv)
parser.parse(argc, argv);
const std::string font_path = get_option(parser, "font", "");
const char* singles[] = {"h","c","r","l","files","convert","parts","rmdiff", "rmtrunc", "rmdupes", "seed", "shuffle", "split", "add",
"flip-basic", "flip", "rotate", "tile", "size", "cluster", "resample", "min-object-size", "rmempty",
"crop-size", "cropped-object-size", "rmlabel", "rm-other-labels", "rm-if-overlaps", "sort-num-objects",
@ -1263,7 +1266,7 @@ int main(int argc, char** argv)
if (parser.number_of_arguments() == 1)
{
metadata_editor editor(parser[0]);
metadata_editor editor(parser[0], font_path);
if (parser.option("parts"))
{
std::vector<string> parts = split(parser.option("parts").argument());

@ -23,7 +23,8 @@ extern const char* VERSION;
metadata_editor::
metadata_editor(
const std::string& filename_
const std::string& filename_,
const std::string& font_path
) :
mbar(*this),
lb_images(*this),
@ -36,6 +37,26 @@ metadata_editor(
{
file metadata_file(filename_);
filename = metadata_file.full_name();
// Set the custom label fonts
if (!font_path.empty())
{
const auto custom_font = std::make_shared<dlib::bdf_font>();
std::ifstream fin(font_path);
if (fin.good())
{
custom_font->read_bdf_file(fin, 0xFFFF);
custom_font->adjust_metrics();
font = std::move(custom_font);
}
else
{
std::cerr << "WARNING: could not open file '" + font_path + "', using default font\n.";
}
}
display.set_main_font(font);
overlay_label.set_main_font(font);
// Make our current directory be the one that contains the metadata file. We
// do this because that file might contain relative paths to the image files
// we are supposed to be loading.

@ -58,7 +58,8 @@ class metadata_editor : public dlib::drawable_window
{
public:
metadata_editor(
const std::string& filename_
const std::string& filename_,
const std::string& font_path = ""
);
~metadata_editor();
@ -107,6 +108,8 @@ private:
time_t last_keyboard_jump_pos_update;
bool display_equialized_image = false;
color_mapper string_to_color;
std::shared_ptr<dlib::font> font = dlib::default_font::get_font();
};
// ----------------------------------------------------------------------------------------

Loading…
Cancel
Save