"git@developer.sourcefind.cn:OpenDAS/dlib.git" did not exist on "18489b11d6f74c08b12bdb7d514c5d95b3bc18aa"
image.cpp 1.2 KB
Newer Older
Davis King's avatar
Davis King committed
1
#include "opaque_types.h"
2
3
#include <dlib/python.h>
#include "dlib/pixel.h"
4
#include <dlib/image_transforms.h>
5
6
7

using namespace dlib;
using namespace std;
8
9

namespace py = pybind11;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

// ----------------------------------------------------------------------------------------

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;
25
    sout << "rgb_pixel(" << (int)p.red << "," << (int)p.green << "," << (int)p.blue << ")";
26
27
28
29
    return sout.str();
}

// ----------------------------------------------------------------------------------------
30

31
void bind_image_classes(py::module& m)
32
{
33
34
    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"))
35
36
        .def("__str__", &print_rgb_pixel_str)
        .def("__repr__", &print_rgb_pixel_repr)
37
38
39
        .def_readwrite("red", &rgb_pixel::red)
        .def_readwrite("green", &rgb_pixel::green)
        .def_readwrite("blue", &rgb_pixel::blue);
40
}