diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:57:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:57:58 +0000 |
commit | be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97 (patch) | |
tree | 9754ff1ca740f6346cf8483ec915d4054bc5da2d /ml/dlib/tools/python/src/image.cpp | |
parent | Initial commit. (diff) | |
download | netdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.tar.xz netdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.zip |
Adding upstream version 1.44.3.upstream/1.44.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ml/dlib/tools/python/src/image.cpp')
-rw-r--r-- | ml/dlib/tools/python/src/image.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/ml/dlib/tools/python/src/image.cpp b/ml/dlib/tools/python/src/image.cpp new file mode 100644 index 00000000..bd43ce5a --- /dev/null +++ b/ml/dlib/tools/python/src/image.cpp @@ -0,0 +1,40 @@ +#include "opaque_types.h" +#include <dlib/python.h> +#include "dlib/pixel.h" +#include <dlib/image_transforms.h> + +using namespace dlib; +using namespace std; + +namespace py = pybind11; + +// ---------------------------------------------------------------------------------------- + +string print_rgb_pixel_str(const rgb_pixel& p) +{ + std::ostringstream sout; + sout << "red: "<< (int)p.red + << ", green: "<< (int)p.green + << ", blue: "<< (int)p.blue; + return sout.str(); +} + +string print_rgb_pixel_repr(const rgb_pixel& p) +{ + std::ostringstream sout; + sout << "rgb_pixel(" << (int)p.red << "," << (int)p.green << "," << (int)p.blue << ")"; + return sout.str(); +} + +// ---------------------------------------------------------------------------------------- + +void bind_image_classes(py::module& m) +{ + py::class_<rgb_pixel>(m, "rgb_pixel") + .def(py::init<unsigned char,unsigned char,unsigned char>(), py::arg("red"), py::arg("green"), py::arg("blue")) + .def("__str__", &print_rgb_pixel_str) + .def("__repr__", &print_rgb_pixel_repr) + .def_readwrite("red", &rgb_pixel::red) + .def_readwrite("green", &rgb_pixel::green) + .def_readwrite("blue", &rgb_pixel::blue); +} |