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
85f0c0ff
Commit
85f0c0ff
authored
Dec 09, 2014
by
Patrick Snape
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrap the dlib point for Python
parent
70db61c5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
8 deletions
+40
-8
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