Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
972bf3c4
Commit
972bf3c4
authored
Sep 01, 2017
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made the box colors in imglab spread more evenly over the color space.
parent
511c05ad
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
27 deletions
+66
-27
main.cpp
tools/imglab/src/main.cpp
+1
-1
metadata_editor.cpp
tools/imglab/src/metadata_editor.cpp
+15
-25
metadata_editor.h
tools/imglab/src/metadata_editor.h
+50
-1
No files found.
tools/imglab/src/main.cpp
View file @
972bf3c4
...
...
@@ -20,7 +20,7 @@
#include <dlib/dir_nav.h>
const
char
*
VERSION
=
"1.1
1
"
;
const
char
*
VERSION
=
"1.1
2
"
;
const
int
JPEG_QUALITY
=
90
;
...
...
tools/imglab/src/metadata_editor.cpp
View file @
972bf3c4
...
...
@@ -19,27 +19,6 @@ using namespace dlib;
extern
const
char
*
VERSION
;
rgb_alpha_pixel
string_to_color
(
const
std
::
string
&
str
)
{
if
(
str
.
size
()
==
0
)
{
return
rgb_alpha_pixel
(
255
,
0
,
0
,
255
);
}
else
{
// make up a random color based on the string label.
hsi_pixel
pix
;
pix
.
h
=
static_cast
<
unsigned
char
>
(
dlib
::
hash
(
str
)
&
0xFF
);
pix
.
s
=
255
;
pix
.
i
=
150
;
rgb_alpha_pixel
result
;
assign_pixel
(
result
,
pix
);
return
result
;
}
}
// ----------------------------------------------------------------------------------------
metadata_editor
::
...
...
@@ -78,6 +57,7 @@ metadata_editor(
overlay_label_name
.
set_text
(
"Next Label: "
);
overlay_label
.
set_width
(
200
);
display
.
set_image_clicked_handler
(
*
this
,
&
metadata_editor
::
on_image_clicked
);
display
.
set_overlay_rects_changed_handler
(
*
this
,
&
metadata_editor
::
on_overlay_rects_changed
);
display
.
set_overlay_rect_selected_handler
(
*
this
,
&
metadata_editor
::
on_overlay_rect_selected
);
overlay_label
.
set_text_modified_handler
(
*
this
,
&
metadata_editor
::
on_overlay_label_changed
);
...
...
@@ -479,7 +459,8 @@ on_lb_images_clicked(
// ----------------------------------------------------------------------------------------
std
::
vector
<
dlib
::
image_display
::
overlay_rect
>
get_overlays
(
const
dlib
::
image_dataset_metadata
::
image
&
data
const
dlib
::
image_dataset_metadata
::
image
&
data
,
color_mapper
&
string_to_color
)
{
std
::
vector
<
dlib
::
image_display
::
overlay_rect
>
temp
(
data
.
boxes
.
size
());
...
...
@@ -521,7 +502,7 @@ load_image(
if
(
display_equialized_image
)
equalize_histogram
(
img
);
display
.
set_image
(
img
);
display
.
add_overlay
(
get_overlays
(
metadata
.
images
[
idx
]));
display
.
add_overlay
(
get_overlays
(
metadata
.
images
[
idx
]
,
string_to_color
));
}
// ----------------------------------------------------------------------------------------
...
...
@@ -569,7 +550,7 @@ load_image_and_set_size(
if
(
display_equialized_image
)
equalize_histogram
(
img
);
display
.
set_image
(
img
);
display
.
add_overlay
(
get_overlays
(
metadata
.
images
[
idx
]));
display
.
add_overlay
(
get_overlays
(
metadata
.
images
[
idx
]
,
string_to_color
));
}
// ----------------------------------------------------------------------------------------
...
...
@@ -600,12 +581,21 @@ on_overlay_rects_changed(
// ----------------------------------------------------------------------------------------
void
metadata_editor
::
on_image_clicked
(
const
point
&
/*p*/
,
bool
/*is_double_click*/
,
unsigned
long
/*btn*/
)
{
display
.
set_default_overlay_rect_color
(
string_to_color
(
trim
(
overlay_label
.
text
())));
}
// ----------------------------------------------------------------------------------------
void
metadata_editor
::
on_overlay_label_changed
(
)
{
display
.
set_default_overlay_rect_label
(
trim
(
overlay_label
.
text
()));
display
.
set_default_overlay_rect_color
(
string_to_color
(
trim
(
overlay_label
.
text
())));
}
// ----------------------------------------------------------------------------------------
...
...
tools/imglab/src/metadata_editor.h
View file @
972bf3c4
...
...
@@ -4,7 +4,54 @@
#define DLIB_METADATA_EdITOR_H__
#include <dlib/gui_widgets.h>
#include "dlib/data_io.h"
#include <dlib/data_io.h>
#include <dlib/pixel.h>
#include <map>
// ----------------------------------------------------------------------------------------
class
color_mapper
{
public
:
dlib
::
rgb_alpha_pixel
operator
()
(
const
std
::
string
&
str
)
{
auto
i
=
colors
.
find
(
str
);
if
(
i
!=
colors
.
end
())
{
return
i
->
second
;
}
else
{
using
namespace
dlib
;
hsi_pixel
pix
;
pix
.
h
=
reverse
(
colors
.
size
());
std
::
cout
<<
"new h: "
<<
(
unsigned
int
)
pix
.
h
<<
std
::
endl
;
pix
.
s
=
255
;
pix
.
i
=
150
;
rgb_alpha_pixel
result
;
assign_pixel
(
result
,
pix
);
colors
[
str
]
=
result
;
return
result
;
}
}
private
:
// We use a bit reverse here because it causes us to evenly spread the colors as we
// allocated them. First the colors are maximally different, then become interleaved
// and progressively more similar as they are allocated.
unsigned
char
reverse
(
unsigned
char
b
)
{
// reverse the order of the bits in b.
b
=
((
b
*
0x0802LU
&
0x22110LU
)
|
(
b
*
0x8020LU
&
0x88440LU
))
*
0x10101LU
>>
16
;
return
b
;
}
std
::
map
<
std
::
string
,
dlib
::
rgb_alpha_pixel
>
colors
;
};
// ----------------------------------------------------------------------------------------
...
...
@@ -39,6 +86,7 @@ private:
void
save_metadata_to_file
(
const
std
::
string
&
file
);
void
load_image
(
unsigned
long
idx
);
void
load_image_and_set_size
(
unsigned
long
idx
);
void
on_image_clicked
(
const
dlib
::
point
&
p
,
bool
is_double_click
,
unsigned
long
btn
);
void
on_overlay_rects_changed
();
void
on_overlay_label_changed
();
void
on_overlay_rect_selected
(
const
dlib
::
image_display
::
overlay_rect
&
orect
);
...
...
@@ -59,6 +107,7 @@ private:
unsigned
long
keyboard_jump_pos
;
time_t
last_keyboard_jump_pos_update
;
bool
display_equialized_image
=
false
;
color_mapper
string_to_color
;
};
// ----------------------------------------------------------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment