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
c13ca8eb
Commit
c13ca8eb
authored
Jan 13, 2018
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Just moved code around to clean things up a little.
parent
09b31219
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
111 additions
and
72 deletions
+111
-72
CMakeLists.txt
tools/imglab/CMakeLists.txt
+1
-0
common.cpp
tools/imglab/src/common.cpp
+20
-0
common.h
tools/imglab/src/common.h
+9
-0
flip_dataset.cpp
tools/imglab/src/flip_dataset.cpp
+68
-0
flip_dataset.h
tools/imglab/src/flip_dataset.h
+12
-0
main.cpp
tools/imglab/src/main.cpp
+1
-72
No files found.
tools/imglab/CMakeLists.txt
View file @
c13ca8eb
...
...
@@ -26,6 +26,7 @@ add_executable(${target_name}
src/common.h
src/common.cpp
src/cluster.cpp
src/flip_dataset.cpp
)
...
...
tools/imglab/src/common.cpp
View file @
c13ca8eb
...
...
@@ -38,3 +38,23 @@ void make_empty_file (
// ----------------------------------------------------------------------------------------
std
::
string
to_png_name
(
const
std
::
string
&
filename
)
{
std
::
string
::
size_type
pos
=
filename
.
find_last_of
(
"."
);
if
(
pos
==
std
::
string
::
npos
)
throw
dlib
::
error
(
"invalid filename: "
+
filename
);
return
filename
.
substr
(
0
,
pos
)
+
".png"
;
}
// ----------------------------------------------------------------------------------------
std
::
string
to_jpg_name
(
const
std
::
string
&
filename
)
{
std
::
string
::
size_type
pos
=
filename
.
find_last_of
(
"."
);
if
(
pos
==
std
::
string
::
npos
)
throw
dlib
::
error
(
"invalid filename: "
+
filename
);
return
filename
.
substr
(
0
,
pos
)
+
".jpg"
;
}
// ----------------------------------------------------------------------------------------
tools/imglab/src/common.h
View file @
c13ca8eb
...
...
@@ -32,5 +32,14 @@ void make_empty_file (
// ----------------------------------------------------------------------------------------
std
::
string
to_png_name
(
const
std
::
string
&
filename
);
std
::
string
to_jpg_name
(
const
std
::
string
&
filename
);
// ----------------------------------------------------------------------------------------
const
int
JPEG_QUALITY
=
90
;
// ----------------------------------------------------------------------------------------
#endif // DLIB_IMGLAB_COmMON_H__
tools/imglab/src/flip_dataset.cpp
0 → 100644
View file @
c13ca8eb
// Copyright (C) 2011 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#include "flip_dataset.h"
#include <dlib/data_io.h>
#include <dlib/dir_nav.h>
#include <string>
#include "common.h"
#include <dlib/image_transforms.h>
using
namespace
dlib
;
using
namespace
std
;
// ----------------------------------------------------------------------------------------
void
flip_dataset
(
const
command_line_parser
&
parser
)
{
image_dataset_metadata
::
dataset
metadata
;
const
string
datasource
=
parser
.
option
(
"flip"
).
argument
();
load_image_dataset_metadata
(
metadata
,
datasource
);
// Set the current directory to be the one that contains the
// metadata file. We do this because the file might contain
// file paths which are relative to this folder.
set_current_dir
(
get_parent_directory
(
file
(
datasource
)));
const
string
metadata_filename
=
get_parent_directory
(
file
(
datasource
)).
full_name
()
+
directory
::
get_separator
()
+
"flipped_"
+
file
(
datasource
).
name
();
array2d
<
rgb_pixel
>
img
,
temp
;
for
(
unsigned
long
i
=
0
;
i
<
metadata
.
images
.
size
();
++
i
)
{
file
f
(
metadata
.
images
[
i
].
filename
);
string
filename
=
get_parent_directory
(
f
).
full_name
()
+
directory
::
get_separator
()
+
"flipped_"
+
to_png_name
(
f
.
name
());
load_image
(
img
,
metadata
.
images
[
i
].
filename
);
flip_image_left_right
(
img
,
temp
);
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
)
{
metadata
.
images
[
i
].
boxes
[
j
].
rect
=
impl
::
flip_rect_left_right
(
metadata
.
images
[
i
].
boxes
[
j
].
rect
,
get_rect
(
img
));
// flip all the object parts
std
::
map
<
std
::
string
,
point
>::
iterator
k
;
for
(
k
=
metadata
.
images
[
i
].
boxes
[
j
].
parts
.
begin
();
k
!=
metadata
.
images
[
i
].
boxes
[
j
].
parts
.
end
();
++
k
)
{
k
->
second
=
impl
::
flip_rect_left_right
(
rectangle
(
k
->
second
,
k
->
second
),
get_rect
(
img
)).
tl_corner
();
}
}
metadata
.
images
[
i
].
filename
=
filename
;
}
save_image_dataset_metadata
(
metadata
,
metadata_filename
);
}
// ----------------------------------------------------------------------------------------
tools/imglab/src/flip_dataset.h
0 → 100644
View file @
c13ca8eb
// Copyright (C) 2011 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_IMGLAB_FLIP_DaTASET_H__
#define DLIB_IMGLAB_FLIP_DaTASET_H__
#include <dlib/cmd_line_parser.h>
void
flip_dataset
(
const
dlib
::
command_line_parser
&
parser
);
#endif // DLIB_IMGLAB_FLIP_DaTASET_H__
tools/imglab/src/main.cpp
View file @
c13ca8eb
...
...
@@ -6,6 +6,7 @@
#include "convert_pascal_v1.h"
#include "convert_idl.h"
#include "cluster.h"
#include "flip_dataset.h"
#include <dlib/cmd_line_parser.h>
#include <dlib/image_transforms.h>
#include <dlib/svm.h>
...
...
@@ -22,7 +23,6 @@
const
char
*
VERSION
=
"1.12"
;
const
int
JPEG_QUALITY
=
90
;
using
namespace
std
;
...
...
@@ -268,77 +268,6 @@ void merge_metadata_files (
// ----------------------------------------------------------------------------------------
string
to_png_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
)
+
".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
)
{
image_dataset_metadata
::
dataset
metadata
;
const
string
datasource
=
parser
.
option
(
"flip"
).
argument
();
load_image_dataset_metadata
(
metadata
,
datasource
);
// Set the current directory to be the one that contains the
// metadata file. We do this because the file might contain
// file paths which are relative to this folder.
set_current_dir
(
get_parent_directory
(
file
(
datasource
)));
const
string
metadata_filename
=
get_parent_directory
(
file
(
datasource
)).
full_name
()
+
directory
::
get_separator
()
+
"flipped_"
+
file
(
datasource
).
name
();
array2d
<
rgb_pixel
>
img
,
temp
;
for
(
unsigned
long
i
=
0
;
i
<
metadata
.
images
.
size
();
++
i
)
{
file
f
(
metadata
.
images
[
i
].
filename
);
string
filename
=
get_parent_directory
(
f
).
full_name
()
+
directory
::
get_separator
()
+
"flipped_"
+
to_png_name
(
f
.
name
());
load_image
(
img
,
metadata
.
images
[
i
].
filename
);
flip_image_left_right
(
img
,
temp
);
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
)
{
metadata
.
images
[
i
].
boxes
[
j
].
rect
=
impl
::
flip_rect_left_right
(
metadata
.
images
[
i
].
boxes
[
j
].
rect
,
get_rect
(
img
));
// flip all the object parts
std
::
map
<
std
::
string
,
point
>::
iterator
k
;
for
(
k
=
metadata
.
images
[
i
].
boxes
[
j
].
parts
.
begin
();
k
!=
metadata
.
images
[
i
].
boxes
[
j
].
parts
.
end
();
++
k
)
{
k
->
second
=
impl
::
flip_rect_left_right
(
rectangle
(
k
->
second
,
k
->
second
),
get_rect
(
img
)).
tl_corner
();
}
}
metadata
.
images
[
i
].
filename
=
filename
;
}
save_image_dataset_metadata
(
metadata
,
metadata_filename
);
}
// ----------------------------------------------------------------------------------------
void
rotate_dataset
(
const
command_line_parser
&
parser
)
{
image_dataset_metadata
::
dataset
metadata
;
...
...
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