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
ae88702b
Commit
ae88702b
authored
Oct 16, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added --jpg and --one-object-per-image.
parent
d6959964
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
9 deletions
+45
-9
main.cpp
tools/imglab/src/main.cpp
+45
-9
No files found.
tools/imglab/src/main.cpp
View file @
ae88702b
...
@@ -20,8 +20,9 @@
...
@@ -20,8 +20,9 @@
#include <dlib/dir_nav.h>
#include <dlib/dir_nav.h>
const
char
*
VERSION
=
"1.
6
"
;
const
char
*
VERSION
=
"1.
7
"
;
const
int
JPEG_QUALITY
=
90
;
using
namespace
std
;
using
namespace
std
;
...
@@ -275,6 +276,14 @@ string to_png_name (const string& filename)
...
@@ -275,6 +276,14 @@ string to_png_name (const string& filename)
return
filename
.
substr
(
0
,
pos
)
+
".png"
;
return
filename
.
substr
(
0
,
pos
)
+
".png"
;
}
}
string
to_jpg_name
(
const
string
&
filename
)
{
string
::
size_type
pos
=
filename
.
find_last_of
(
"."
);
if
(
pos
==
string
::
npos
)
throw
dlib
::
error
(
"invalid filename: "
+
filename
);
return
filename
.
substr
(
0
,
pos
)
+
".jpg"
;
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
void
flip_dataset
(
const
command_line_parser
&
parser
)
void
flip_dataset
(
const
command_line_parser
&
parser
)
...
@@ -296,11 +305,19 @@ void flip_dataset(const command_line_parser& parser)
...
@@ -296,11 +305,19 @@ void flip_dataset(const command_line_parser& parser)
for
(
unsigned
long
i
=
0
;
i
<
metadata
.
images
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
metadata
.
images
.
size
();
++
i
)
{
{
file
f
(
metadata
.
images
[
i
].
filename
);
file
f
(
metadata
.
images
[
i
].
filename
);
const
string
filename
=
get_parent_directory
(
f
).
full_name
()
+
directory
::
get_separator
()
+
"flipped_"
+
to_png_name
(
f
.
name
());
string
filename
=
get_parent_directory
(
f
).
full_name
()
+
directory
::
get_separator
()
+
"flipped_"
+
to_png_name
(
f
.
name
());
load_image
(
img
,
metadata
.
images
[
i
].
filename
);
load_image
(
img
,
metadata
.
images
[
i
].
filename
);
flip_image_left_right
(
img
,
temp
);
flip_image_left_right
(
img
,
temp
);
save_png
(
temp
,
filename
);
if
(
parser
.
option
(
"jpg"
))
{
filename
=
to_jpg_name
(
filename
);
save_jpeg
(
temp
,
filename
,
JPEG_QUALITY
);
}
else
{
save_png
(
temp
,
filename
);
}
for
(
unsigned
long
j
=
0
;
j
<
metadata
.
images
[
i
].
boxes
.
size
();
++
j
)
for
(
unsigned
long
j
=
0
;
j
<
metadata
.
images
[
i
].
boxes
.
size
();
++
j
)
{
{
...
@@ -344,11 +361,19 @@ void rotate_dataset(const command_line_parser& parser)
...
@@ -344,11 +361,19 @@ void rotate_dataset(const command_line_parser& parser)
for
(
unsigned
long
i
=
0
;
i
<
metadata
.
images
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
metadata
.
images
.
size
();
++
i
)
{
{
file
f
(
metadata
.
images
[
i
].
filename
);
file
f
(
metadata
.
images
[
i
].
filename
);
const
string
filename
=
get_parent_directory
(
f
).
full_name
()
+
directory
::
get_separator
()
+
file_prefix
+
to_png_name
(
f
.
name
());
string
filename
=
get_parent_directory
(
f
).
full_name
()
+
directory
::
get_separator
()
+
file_prefix
+
to_png_name
(
f
.
name
());
load_image
(
img
,
metadata
.
images
[
i
].
filename
);
load_image
(
img
,
metadata
.
images
[
i
].
filename
);
const
point_transform_affine
tran
=
rotate_image
(
img
,
temp
,
angle
*
pi
/
180
);
const
point_transform_affine
tran
=
rotate_image
(
img
,
temp
,
angle
*
pi
/
180
);
save_png
(
temp
,
filename
);
if
(
parser
.
option
(
"jpg"
))
{
filename
=
to_jpg_name
(
filename
);
save_jpeg
(
temp
,
filename
,
JPEG_QUALITY
);
}
else
{
save_png
(
temp
,
filename
);
}
for
(
unsigned
long
j
=
0
;
j
<
metadata
.
images
[
i
].
boxes
.
size
();
++
j
)
for
(
unsigned
long
j
=
0
;
j
<
metadata
.
images
[
i
].
boxes
.
size
();
++
j
)
{
{
...
@@ -558,6 +583,7 @@ int resample_dataset(const command_line_parser& parser)
...
@@ -558,6 +583,7 @@ int resample_dataset(const command_line_parser& parser)
const
size_t
obj_size
=
get_option
(
parser
,
"cropped-object-size"
,
100
*
100
);
const
size_t
obj_size
=
get_option
(
parser
,
"cropped-object-size"
,
100
*
100
);
const
double
margin_scale
=
get_option
(
parser
,
"crop-size"
,
2.5
);
// cropped image will be this times wider than the object.
const
double
margin_scale
=
get_option
(
parser
,
"crop-size"
,
2.5
);
// cropped image will be this times wider than the object.
const
unsigned
long
min_object_size
=
get_option
(
parser
,
"min-object-size"
,
1
);
const
unsigned
long
min_object_size
=
get_option
(
parser
,
"min-object-size"
,
1
);
const
bool
one_object_per_image
=
parser
.
option
(
"one-object-per-image"
);
dlib
::
image_dataset_metadata
::
dataset
data
,
resampled_data
;
dlib
::
image_dataset_metadata
::
dataset
data
,
resampled_data
;
std
::
ostringstream
sout
;
std
::
ostringstream
sout
;
...
@@ -614,7 +640,7 @@ int resample_dataset(const command_line_parser& parser)
...
@@ -614,7 +640,7 @@ int resample_dataset(const command_line_parser& parser)
// mark boxes we include in the crop as ignored. Also mark boxes that
// mark boxes we include in the crop as ignored. Also mark boxes that
// aren't totally within the crop as ignored.
// aren't totally within the crop as ignored.
if
(
crop_rect
.
contains
(
grow_rect
(
box
.
rect
,
10
)))
if
(
crop_rect
.
contains
(
grow_rect
(
box
.
rect
,
10
))
&&
(
!
one_object_per_image
||
k
==
j
)
)
data
.
images
[
i
].
boxes
[
k
].
ignore
=
true
;
data
.
images
[
i
].
boxes
[
k
].
ignore
=
true
;
else
else
box
.
ignore
=
true
;
box
.
ignore
=
true
;
...
@@ -633,7 +659,15 @@ int resample_dataset(const command_line_parser& parser)
...
@@ -633,7 +659,15 @@ int resample_dataset(const command_line_parser& parser)
sout
<<
hex
<<
murmur_hash3_128bit
(
&
chip
[
0
][
0
],
chip
.
size
()
*
sizeof
(
chip
[
0
][
0
])).
second
;
sout
<<
hex
<<
murmur_hash3_128bit
(
&
chip
[
0
][
0
],
chip
.
size
()
*
sizeof
(
chip
[
0
][
0
])).
second
;
dimg
.
filename
=
data
.
images
[
i
].
filename
+
"_RESAMPLED_"
+
sout
.
str
()
+
".png"
;
dimg
.
filename
=
data
.
images
[
i
].
filename
+
"_RESAMPLED_"
+
sout
.
str
()
+
".png"
;
save_png
(
chip
,
dimg
.
filename
);
if
(
parser
.
option
(
"jpg"
))
{
dimg
.
filename
=
to_jpg_name
(
dimg
.
filename
);
save_jpeg
(
chip
,
dimg
.
filename
,
JPEG_QUALITY
);
}
else
{
save_png
(
chip
,
dimg
.
filename
);
}
resampled_data
.
images
.
push_back
(
dimg
);
resampled_data
.
images
.
push_back
(
dimg
);
}
}
}
}
...
@@ -767,8 +801,10 @@ int main(int argc, char** argv)
...
@@ -767,8 +801,10 @@ int main(int argc, char** argv)
parser
.
add_option
(
"cropped-object-size"
,
"When doing --resample, make the cropped objects contain about <arg> pixels (default 10000)."
,
1
);
parser
.
add_option
(
"cropped-object-size"
,
"When doing --resample, make the cropped objects contain about <arg> pixels (default 10000)."
,
1
);
parser
.
add_option
(
"min-object-size"
,
"When doing --resample, skip objects that have fewer than <arg> pixels in them (default 1)."
,
1
);
parser
.
add_option
(
"min-object-size"
,
"When doing --resample, skip objects that have fewer than <arg> pixels in them (default 1)."
,
1
);
parser
.
add_option
(
"crop-size"
,
"When doing --resample, the entire cropped image will be <arg> times wider than the object (default 2.5)."
,
1
);
parser
.
add_option
(
"crop-size"
,
"When doing --resample, the entire cropped image will be <arg> times wider than the object (default 2.5)."
,
1
);
parser
.
add_option
(
"one-object-per-image"
,
"When doing --resample, only include one non-ignored object per image (i.e. the central object)."
);
parser
.
add_option
(
"extract-chips"
,
"Crops out images with tight bounding boxes around each object. Also crops out "
parser
.
add_option
(
"extract-chips"
,
"Crops out images with tight bounding boxes around each object. Also crops out "
"many background chips. All these image chips are serialized into one big data file. The chips will contain <arg> pixels each."
,
1
);
"many background chips. All these image chips are serialized into one big data file. The chips will contain <arg> pixels each."
,
1
);
parser
.
add_option
(
"jpg"
,
"When saving images to disk, write them as jpg files instead of png."
);
...
@@ -776,12 +812,12 @@ int main(int argc, char** argv)
...
@@ -776,12 +812,12 @@ int main(int argc, char** argv)
const
char
*
singles
[]
=
{
"h"
,
"c"
,
"r"
,
"l"
,
"files"
,
"convert"
,
"parts"
,
"rmdiff"
,
"rmtrunc"
,
"rmdupes"
,
"seed"
,
"shuffle"
,
"split"
,
"add"
,
const
char
*
singles
[]
=
{
"h"
,
"c"
,
"r"
,
"l"
,
"files"
,
"convert"
,
"parts"
,
"rmdiff"
,
"rmtrunc"
,
"rmdupes"
,
"seed"
,
"shuffle"
,
"split"
,
"add"
,
"flip"
,
"rotate"
,
"tile"
,
"size"
,
"cluster"
,
"resample"
,
"extract-chips"
,
"min-object-size"
,
"rmempty"
,
"flip"
,
"rotate"
,
"tile"
,
"size"
,
"cluster"
,
"resample"
,
"extract-chips"
,
"min-object-size"
,
"rmempty"
,
"crop-size"
,
"cropped-object-size"
,
"rmlabel"
,
"rm-if-overlaps"
,
"sort-num-objects"
};
"crop-size"
,
"cropped-object-size"
,
"rmlabel"
,
"rm-if-overlaps"
,
"sort-num-objects"
,
"one-object-per-image"
,
"jpg"
};
parser
.
check_one_time_options
(
singles
);
parser
.
check_one_time_options
(
singles
);
const
char
*
c_sub_ops
[]
=
{
"r"
,
"convert"
};
const
char
*
c_sub_ops
[]
=
{
"r"
,
"convert"
};
parser
.
check_sub_options
(
"c"
,
c_sub_ops
);
parser
.
check_sub_options
(
"c"
,
c_sub_ops
);
parser
.
check_sub_option
(
"shuffle"
,
"seed"
);
parser
.
check_sub_option
(
"shuffle"
,
"seed"
);
const
char
*
resample_sub_ops
[]
=
{
"min-object-size"
,
"crop-size"
,
"cropped-object-size"
};
const
char
*
resample_sub_ops
[]
=
{
"min-object-size"
,
"crop-size"
,
"cropped-object-size"
,
"one-object-per-image"
};
parser
.
check_sub_options
(
"resample"
,
resample_sub_ops
);
parser
.
check_sub_options
(
"resample"
,
resample_sub_ops
);
const
char
*
size_parent_ops
[]
=
{
"tile"
,
"cluster"
};
const
char
*
size_parent_ops
[]
=
{
"tile"
,
"cluster"
};
parser
.
check_sub_options
(
size_parent_ops
,
"size"
);
parser
.
check_sub_options
(
size_parent_ops
,
"size"
);
...
...
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