| 397 | // ---------------------------------------------------------------------------------------- |
| 398 | |
| 399 | void bind_vector(py::module& m) |
| 400 | { |
| 401 | { |
| 402 | py::class_<cv, std::shared_ptr<cv>>(m, "vector", "This object represents the mathematical idea of a column vector.") |
| 403 | .def(py::init()) |
| 404 | .def("set_size", &cv_set_size) |
| 405 | .def("resize", &cv_set_size) |
| 406 | .def(py::init(&cv_from_object)) |
| 407 | .def("__repr__", &cv__repr__) |
| 408 | .def("__str__", &cv__str__) |
| 409 | .def("__len__", &cv__len__) |
| 410 | .def("__getitem__", &cv__getitem__) |
| 411 | .def("__getitem__", &cv__getitem2__) |
| 412 | .def("__setitem__", &cv__setitem__) |
| 413 | .def_property_readonly("shape", &cv_get_matrix_size) |
| 414 | .def(py::pickle(&getstate<cv>, &setstate<cv>)); |
| 415 | |
| 416 | m.def("dot", &dotprod, "Compute the dot product between two dense column vectors."); |
| 417 | } |
| 418 | { |
| 419 | typedef point type; |
| 420 | py::class_<type>(m, "point", "This object represents a single point of integer coordinates that maps directly to a dlib::point.") |
| 421 | .def(py::init<long,long>(), py::arg("x"), py::arg("y")) |
| 422 | .def(py::init<dpoint>(), py::arg("p")) |
| 423 | .def(py::init<>(&numpy_to_dlib_vect<long>), py::arg("v")) |
| 424 | .def(py::init<>(&numpy_to_dlib_vect<float>), py::arg("v")) |
| 425 | .def(py::init<>(&numpy_to_dlib_vect<double>), py::arg("v")) |
| 426 | .def("__repr__", &point__repr__) |
| 427 | .def("__str__", &point__str__) |
| 428 | .def(py::self + py::self) |
| 429 | .def(py::self - py::self) |
| 430 | .def(py::self / double()) |
| 431 | .def(py::self * double()) |
| 432 | .def(double() * py::self) |
| 433 | .def("normalize", &type::normalize, "Returns a unit normalized copy of this vector.") |
| 434 | .def_property("x", &point_x, [](point& p, long x){p.x()=x;}, "The x-coordinate of the point.") |
| 435 | .def_property("y", &point_y, [](point& p, long y){p.y()=y;}, "The y-coordinate of the point.") |
| 436 | .def(py::pickle(&getstate<type>, &setstate<type>)); |
| 437 | } |
| 438 | { |
| 439 | typedef std::vector<point> type; |
| 440 | py::bind_vector<type>(m, "points", "An array of point objects.") |
| 441 | .def(py::init<size_t>(), py::arg("initial_size")) |
| 442 | .def("clear", &type::clear) |
| 443 | .def("resize", resize<type>) |
| 444 | .def("extend", extend_vector_with_python_list<point>) |
| 445 | .def(py::pickle(&getstate<type>, &setstate<type>)); |
| 446 | } |
| 447 | |
| 448 | { |
| 449 | typedef dpoint type; |
| 450 | py::class_<type>(m, "dpoint", "This object represents a single point of floating point coordinates that maps directly to a dlib::dpoint.") |
| 451 | .def(py::init<double,double>(), py::arg("x"), py::arg("y")) |
| 452 | .def(py::init<point>(), py::arg("p")) |
| 453 | .def(py::init<>(&numpy_to_dlib_vect<long>), py::arg("v")) |
| 454 | .def(py::init<>(&numpy_to_dlib_vect<float>), py::arg("v")) |
| 455 | .def(py::init<>(&numpy_to_dlib_vect<double>), py::arg("v")) |
| 456 | .def("__repr__", &dpoint__repr__) |
no test coverage detected