From a190a1c24290b2857fe0226d7373e4ce3052f6f9 Mon Sep 17 00:00:00 2001 From: Davis King Date: Sun, 20 May 2018 22:34:49 -0400 Subject: [PATCH] Added equalize_histogram() and resize_image() to the Python API. --- tools/python/CMakeLists.txt | 1 + tools/python/src/dlib.cpp | 2 ++ tools/python/src/image2.cpp | 64 +++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 tools/python/src/image2.cpp diff --git a/tools/python/CMakeLists.txt b/tools/python/CMakeLists.txt index 976929b27..13b7772d3 100644 --- a/tools/python/CMakeLists.txt +++ b/tools/python/CMakeLists.txt @@ -61,6 +61,7 @@ set(python_srcs src/sequence_segmenter.cpp src/svm_struct.cpp src/image.cpp + src/image2.cpp src/rectangles.cpp src/object_detection.cpp src/shape_predictor.cpp diff --git a/tools/python/src/dlib.cpp b/tools/python/src/dlib.cpp index ac6fea0db..258529ae6 100644 --- a/tools/python/src/dlib.cpp +++ b/tools/python/src/dlib.cpp @@ -19,6 +19,7 @@ void bind_cca(py::module& m); void bind_sequence_segmenter(py::module& m); void bind_svm_struct(py::module& m); void bind_image_classes(py::module& m); +void bind_image_classes2(py::module& m); void bind_rectangles(py::module& m); void bind_object_detection(py::module& m); void bind_shape_predictors(py::module& m); @@ -91,6 +92,7 @@ PYBIND11_MODULE(dlib, m) bind_sequence_segmenter(m); bind_svm_struct(m); bind_image_classes(m); + bind_image_classes2(m); bind_rectangles(m); bind_object_detection(m); bind_shape_predictors(m); diff --git a/tools/python/src/image2.cpp b/tools/python/src/image2.cpp new file mode 100644 index 000000000..cebbef91f --- /dev/null +++ b/tools/python/src/image2.cpp @@ -0,0 +1,64 @@ +#include "opaque_types.h" +#include +#include "dlib/pixel.h" +#include +#include + +using namespace dlib; +using namespace std; + +namespace py = pybind11; + +// ---------------------------------------------------------------------------------------- + +template +numpy_image py_resize_image ( + const numpy_image& img, + unsigned long rows, + unsigned long cols +) +{ + numpy_image out; + set_image_size(out, rows, cols); + resize_image(img, out); + return out; +} + +// ---------------------------------------------------------------------------------------- + +template +numpy_image py_equalize_histogram ( + const numpy_image& img +) +{ + numpy_image out; + equalize_histogram(img,out); + return out; +} + +// ---------------------------------------------------------------------------------------- + +void bind_image_classes2(py::module& m) +{ + + const char* docs = "Resizes img, using bilinear interpolation, to have the indicated number of rows and columns."; + + + m.def("resize_image", &py_resize_image, py::arg("img"), py::arg("rows"), py::arg("cols")); + m.def("resize_image", &py_resize_image, py::arg("img"), py::arg("rows"), py::arg("cols")); + m.def("resize_image", &py_resize_image, py::arg("img"), py::arg("rows"), py::arg("cols")); + m.def("resize_image", &py_resize_image, py::arg("img"), py::arg("rows"), py::arg("cols")); + m.def("resize_image", &py_resize_image, py::arg("img"), py::arg("rows"), py::arg("cols")); + m.def("resize_image", &py_resize_image, py::arg("img"), py::arg("rows"), py::arg("cols")); + m.def("resize_image", &py_resize_image, py::arg("img"), py::arg("rows"), py::arg("cols")); + m.def("resize_image", &py_resize_image, py::arg("img"), py::arg("rows"), py::arg("cols")); + m.def("resize_image", &py_resize_image, py::arg("img"), py::arg("rows"), py::arg("cols")); + m.def("resize_image", &py_resize_image, docs, py::arg("img"), py::arg("rows"), py::arg("cols")); + + + docs = "Returns a histogram equalized version of img."; + m.def("equalize_histogram", &py_equalize_histogram, py::arg("img")); + m.def("equalize_histogram", &py_equalize_histogram, docs, py::arg("img")); +} + +