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
85f0c0ff
Commit
85f0c0ff
authored
Dec 09, 2014
by
Patrick Snape
Browse files
Wrap the dlib point for Python
parent
70db61c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
8 deletions
+40
-8
tools/python/src/vector.cpp
tools/python/src/vector.cpp
+40
-8
No files found.
tools/python/src/vector.cpp
View file @
85f0c0ff
...
...
@@ -5,6 +5,7 @@
#include <boost/shared_ptr.hpp>
#include <dlib/matrix.h>
#include <boost/python/slice.hpp>
#include <dlib/geometry/vector.h>
using
namespace
dlib
;
...
...
@@ -84,9 +85,9 @@ void cv__setitem__(cv& c, long p, double val)
p
=
c
.
size
()
+
p
;
// negative index
}
if
(
p
>
c
.
size
()
-
1
)
{
PyErr_SetString
(
PyExc_IndexError
,
"index out of range"
);
boost
::
python
::
throw_error_already_set
();
PyErr_SetString
(
PyExc_IndexError
,
"index out of range"
);
boost
::
python
::
throw_error_already_set
();
}
c
(
p
)
=
val
;
}
...
...
@@ -97,9 +98,9 @@ double cv__getitem__(cv& m, long r)
r
=
m
.
size
()
+
r
;
// negative index
}
if
(
r
>
m
.
size
()
-
1
||
r
<
0
)
{
PyErr_SetString
(
PyExc_IndexError
,
"index out of range"
);
boost
::
python
::
throw_error_already_set
();
PyErr_SetString
(
PyExc_IndexError
,
"index out of range"
);
boost
::
python
::
throw_error_already_set
();
}
return
m
(
r
);
}
...
...
@@ -133,8 +134,30 @@ boost::python::tuple cv_get_matrix_size(cv& m)
return
boost
::
python
::
make_tuple
(
m
.
nr
(),
m
.
nc
());
}
// ----------------------------------------------------------------------------------------
string
point__repr__
(
const
point
&
p
)
{
std
::
ostringstream
sout
;
sout
<<
"point("
<<
p
.
x
()
<<
", "
<<
p
.
y
()
<<
")"
;
return
sout
.
str
();
}
string
point__str__
(
const
point
&
p
)
{
std
::
ostringstream
sout
;
sout
<<
"("
<<
p
.
x
()
<<
", "
<<
p
.
y
()
<<
")"
;
return
sout
.
str
();
}
long
point_x
(
const
point
&
p
)
{
return
p
.
x
();
}
long
point_y
(
const
point
&
p
)
{
return
p
.
y
();
}
// ----------------------------------------------------------------------------------------
void
bind_vector
()
{
using
boost
::
python
::
arg
;
{
class_
<
cv
>
(
"vector"
,
"This object represents the mathematical idea of a column vector."
,
init
<>
())
.
def
(
"set_size"
,
&
cv_set_size
)
.
def
(
"resize"
,
&
cv_set_size
)
...
...
@@ -147,7 +170,16 @@ void bind_vector()
.
def
(
"__setitem__"
,
&
cv__setitem__
)
.
add_property
(
"shape"
,
&
cv_get_matrix_size
)
.
def_pickle
(
serialize_pickle
<
cv
>
());
}
{
typedef
point
type
;
class_
<
type
>
(
"point"
,
"This object represents a single point of integer coordinates that maps directly to a dlib::point."
)
.
def
(
init
<
long
,
long
>
((
arg
(
"x"
),
arg
(
"y"
))))
.
def
(
"__repr__"
,
&
point__repr__
)
.
def
(
"__str__"
,
&
point__str__
)
.
def
(
"x"
,
&
point_x
)
.
def
(
"y"
,
&
point_y
)
.
def_pickle
(
serialize_pickle
<
type
>
());
}
def
(
"dot"
,
dotprod
,
"Compute the dot product between two dense column vectors."
);
}
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