Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
c95a2a6f
Commit
c95a2a6f
authored
Mar 21, 2012
by
Davis King
Browse files
Added the load_image_dataset() routine.
parent
a3651eb5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
160 additions
and
0 deletions
+160
-0
dlib/data_io.h
dlib/data_io.h
+4
-0
dlib/data_io/load_image_dataset.h
dlib/data_io/load_image_dataset.h
+84
-0
dlib/data_io/load_image_dataset_abstract.h
dlib/data_io/load_image_dataset_abstract.h
+72
-0
No files found.
dlib/data_io.h
View file @
c95a2a6f
...
@@ -6,6 +6,10 @@
...
@@ -6,6 +6,10 @@
#include "data_io/libsvm_io.h"
#include "data_io/libsvm_io.h"
#include "data_io/image_dataset_metadata.h"
#include "data_io/image_dataset_metadata.h"
#ifndef DLIB_ISO_CPP_ONLY
#include "data_io/load_image_dataset.h"
#endif
#endif // DLIB_DATA_Io_HEADER
#endif // DLIB_DATA_Io_HEADER
...
...
dlib/data_io/load_image_dataset.h
0 → 100644
View file @
c95a2a6f
// Copyright (C) 2012 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_LOAD_IMAGE_DaTASET_H__
#define DLIB_LOAD_IMAGE_DaTASET_H__
#include "load_image_dataset_abstract.h"
#include "../misc_api.h"
#include "../dir_nav.h"
#include "../image_io.h"
#include "../array.h"
#include <vector>
#include "../geometry.h"
#include "image_dataset_metadata.h"
#include <string>
namespace
dlib
{
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
,
typename
MM
>
void
load_image_dataset
(
array
<
image_type
,
MM
>&
images
,
std
::
vector
<
std
::
vector
<
rectangle
>
>&
object_locations
,
const
std
::
string
&
filename
,
const
std
::
string
&
label
)
{
images
.
clear
();
object_locations
.
clear
();
const
std
::
string
old_working_dir
=
get_current_dir
();
// 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.
const
std
::
string
parent_dir
=
get_parent_directory
(
file
(
filename
)).
full_name
();
set_current_dir
(
parent_dir
);
using
namespace
dlib
::
image_dataset_metadata
;
dataset
data
;
load_image_dataset_metadata
(
data
,
filename
);
images
.
resize
(
data
.
images
.
size
());
std
::
vector
<
rectangle
>
rects
;
for
(
unsigned
long
i
=
0
;
i
<
data
.
images
.
size
();
++
i
)
{
load_image
(
images
[
i
],
data
.
images
[
i
].
filename
);
rects
.
clear
();
for
(
unsigned
long
j
=
0
;
j
<
data
.
images
[
i
].
boxes
.
size
();
++
j
)
{
if
(
label
.
size
()
==
0
||
data
.
images
[
i
].
boxes
[
j
].
label
==
label
)
{
rects
.
push_back
(
data
.
images
[
i
].
boxes
[
j
].
rect
);
}
}
object_locations
.
push_back
(
rects
);
}
set_current_dir
(
old_working_dir
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
,
typename
MM
>
void
load_image_dataset
(
array
<
image_type
,
MM
>&
images
,
std
::
vector
<
std
::
vector
<
rectangle
>
>&
object_locations
,
const
std
::
string
&
filename
)
{
load_image_dataset
(
images
,
object_locations
,
filename
,
""
);
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_LOAD_IMAGE_DaTASET_H__
dlib/data_io/load_image_dataset_abstract.h
0 → 100644
View file @
c95a2a6f
// Copyright (C) 2012 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_LOAD_IMAGE_DaTASET_ABSTRACT_H__
#ifdef DLIB_LOAD_IMAGE_DaTASET_ABSTRACT_H__
#include "load_image_dataset.h"
#include "../misc_api.h"
#include "../dir_nav.h"
#include "../image_io.h"
#include "../array.h"
#include <vector>
#include "../geometry.h"
#include "../image_dataset_metadata.h"
#include <string>
namespace
dlib
{
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
,
typename
MM
>
void
load_image_dataset
(
array
<
image_type
,
MM
>&
images
,
std
::
vector
<
std
::
vector
<
rectangle
>
>&
object_locations
,
const
std
::
string
&
filename
,
const
std
::
string
&
label
);
/*!
ensures
- This routine loads the images and their associated object boxes from
the image metadata file indicated by filename. This metadata file
should be in the XML format used by the save_image_dataset_metadata()
routine.
- #images.size() == the number of images in the metadata file
- #images.size() == object_locations.size()
- This routine is capable of loading any image format which can be read
by the load_image() routine.
- for all valid i:
- #images[i] == a copy of the ith image from the dataset
- #object_locations[i] == a vector of all the rectangles associated with
#images[i].
- if (labels != "") then
- only boxes with the given label will be loaded into object_locations.
- else
- all boxes in the dataset will be loaded into object_locations
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
,
typename
MM
>
void
load_image_dataset
(
array
<
image_type
,
MM
>&
images
,
std
::
vector
<
std
::
vector
<
rectangle
>
>&
object_locations
,
const
std
::
string
&
filename
);
/*!
ensures
- performs: load_image_dataset(images, object_locations, filename, "");
(i.e. it ignores box labels and therefore loads all the boxes in the dataset)
!*/
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_LOAD_IMAGE_DaTASET_ABSTRACT_H__
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