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
8798955d
Commit
8798955d
authored
Jun 16, 2018
by
Davis King
Browse files
Made it so you can fully build image_dataset_metadata::dataset objects from python.
parent
30ba39c9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
0 deletions
+42
-0
tools/python/src/image_dataset_metadata.cpp
tools/python/src/image_dataset_metadata.cpp
+38
-0
tools/python/src/opaque_types.h
tools/python/src/opaque_types.h
+4
-0
No files found.
tools/python/src/image_dataset_metadata.cpp
View file @
8798955d
...
...
@@ -137,6 +137,7 @@ void bind_image_dataset_metadata(py::module &m_)
auto
datasetrepr
=
[
datasetstr
](
const
dataset
&
item
)
{
return
"<"
+
datasetstr
(
item
)
+
">"
;
};
py
::
class_
<
dataset
>
(
m
,
"dataset"
,
"This object represents a labeled set of images. In particular, it contains the filename for each image as well as annotated boxes."
)
.
def
(
py
::
init
())
.
def
(
"__str__"
,
datasetstr
)
.
def
(
"__repr__"
,
datasetrepr
)
.
def_readwrite
(
"images"
,
&
dataset
::
images
)
...
...
@@ -146,11 +147,29 @@ void bind_image_dataset_metadata(py::module &m_)
auto
imagestr
=
[](
const
image
&
item
)
{
return
"dlib.image_dataset_metadata.image: boxes:"
+
to_string
(
item
.
boxes
.
size
())
+
", "
+
item
.
filename
;
};
auto
imagerepr
=
[
imagestr
](
const
image
&
item
)
{
return
"<"
+
imagestr
(
item
)
+
">"
;
};
py
::
class_
<
image
>
(
m
,
"image"
,
"This object represents an annotated image."
)
.
def
(
py
::
init
())
.
def_readwrite
(
"filename"
,
&
image
::
filename
)
.
def
(
"__str__"
,
imagestr
)
.
def
(
"__repr__"
,
imagerepr
)
.
def_readwrite
(
"boxes"
,
&
image
::
boxes
);
auto
imagesstr
=
[
imagerepr
](
const
std
::
vector
<
image
>&
images
)
{
std
::
ostringstream
sout
;
for
(
size_t
i
=
0
;
i
<
images
.
size
();
++
i
)
{
if
(
i
==
0
)
sout
<<
"["
<<
imagerepr
(
images
[
i
])
<<
",
\n
"
;
else
if
(
i
+
1
==
images
.
size
())
sout
<<
" "
<<
imagerepr
(
images
[
i
])
<<
"]"
;
else
sout
<<
" "
<<
imagerepr
(
images
[
i
])
<<
",
\n
"
;
}
return
sout
.
str
();
};
py
::
bind_vector
<
std
::
vector
<
image
>>
(
m
,
"images"
,
"An array of dlib::image_dataset_metadata::image objects."
)
.
def
(
"__str__"
,
imagesstr
)
.
def
(
"__repr__"
,
imagesstr
);
auto
partsstr
=
[](
const
std
::
map
<
std
::
string
,
point
>&
item
)
{
std
::
ostringstream
sout
;
...
...
@@ -190,6 +209,7 @@ void bind_image_dataset_metadata(py::module &m_)
"
\n
"
"The main variable of interest is rect. It gives the location of
\n
"
"the box. All the other variables are optional."
);
pybox
.
def
(
py
::
init
())
.
def
(
"__str__"
,
boxstr
)
.
def
(
"__repr__"
,
boxrepr
)
.
def_readwrite
(
"rect"
,
&
box
::
rect
)
...
...
@@ -205,6 +225,24 @@ void bind_image_dataset_metadata(py::module &m_)
.
def_readwrite
(
"gender"
,
&
box
::
gender
)
.
def_readwrite
(
"age"
,
&
box
::
age
);
auto
boxesstr
=
[
boxrepr
](
const
std
::
vector
<
box
>&
boxes
)
{
std
::
ostringstream
sout
;
for
(
size_t
i
=
0
;
i
<
boxes
.
size
();
++
i
)
{
if
(
i
==
0
)
sout
<<
"["
<<
boxrepr
(
boxes
[
i
])
<<
",
\n
"
;
else
if
(
i
+
1
==
boxes
.
size
())
sout
<<
" "
<<
boxrepr
(
boxes
[
i
])
<<
"]"
;
else
sout
<<
" "
<<
boxrepr
(
boxes
[
i
])
<<
",
\n
"
;
}
return
sout
.
str
();
};
py
::
bind_vector
<
std
::
vector
<
box
>>
(
m
,
"boxes"
,
"An array of dlib::image_dataset_metadata::box objects."
)
.
def
(
"__str__"
,
boxesstr
)
.
def
(
"__repr__"
,
boxesstr
);
py
::
enum_
<
gender_t
>
(
pybox
,
"gender_type"
)
.
value
(
"MALE"
,
gender_t
::
MALE
)
.
value
(
"FEMALE"
,
gender_t
::
FEMALE
)
...
...
tools/python/src/opaque_types.h
View file @
8798955d
...
...
@@ -11,6 +11,7 @@
#include <dlib/image_processing/full_object_detection.h>
#include <map>
#include <dlib/svm/ranking_tools.h>
#include <dlib/data_io.h>
// All uses of PYBIND11_MAKE_OPAQUE need to be in this common header to avoid ODR
// violations.
...
...
@@ -52,5 +53,8 @@ PYBIND11_MAKE_OPAQUE(sparse_ranking_pairs);
PYBIND11_MAKE_OPAQUE
(
std
::
vector
<
dlib
::
point
>
);
PYBIND11_MAKE_OPAQUE
(
std
::
vector
<
dlib
::
dpoint
>
);
PYBIND11_MAKE_OPAQUE
(
std
::
vector
<
dlib
::
image_dataset_metadata
::
box
>
);
PYBIND11_MAKE_OPAQUE
(
std
::
vector
<
dlib
::
image_dataset_metadata
::
image
>
);
#endif // DLIB_PyTHON_OPAQUE_TYPES_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