Commit 85f0c0ff authored by Patrick Snape's avatar Patrick Snape

Wrap the dlib point for Python

parent 70db61c5
......@@ -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;
......@@ -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.");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment