From d5909ed9773f89f78203ba4d8324c066b8159925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= <1671644+arrufat@users.noreply.github.com> Date: Wed, 6 Mar 2024 10:17:36 +0900 Subject: [PATCH] allow reading and writing rgb-alpha images in Python (#2925) --- dlib/python/numpy_image.h | 1 + tools/python/src/numpy_returns.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/dlib/python/numpy_image.h b/dlib/python/numpy_image.h index 3672fad89..33f576efe 100644 --- a/dlib/python/numpy_image.h +++ b/dlib/python/numpy_image.h @@ -262,6 +262,7 @@ namespace dlib else if (is_image(src)) assign_image(dest, numpy_image(src)); else if (is_image(src)) assign_image(dest, numpy_image(src)); else if (is_image(src)) assign_image(dest, numpy_image(src)); + else if (is_image(src)) assign_image(dest, numpy_image(src)); else DLIB_CASSERT(false, "Unsupported pixel type used in assign_image()."); } diff --git a/tools/python/src/numpy_returns.cpp b/tools/python/src/numpy_returns.cpp index e32480ca5..a1aa006e3 100644 --- a/tools/python/src/numpy_returns.cpp +++ b/tools/python/src/numpy_returns.cpp @@ -20,6 +20,13 @@ numpy_image load_rgb_image (const std::string &path) return img; } +numpy_image load_rgb_alpha_image (const std::string &path) +{ + numpy_image img; + load_image(img, path); + return img; +} + numpy_image load_grayscale_image (const std::string &path) { numpy_image img; @@ -168,6 +175,10 @@ void bind_numpy_returns(py::module &m) "Saves the given image to the specified path. Determines the file type from the file extension specified in the path", py::arg("img"), py::arg("filename"), py::arg("quality") = 75 ); + m.def("save_image", &save_image, + "Saves the given image to the specified path. Determines the file type from the file extension specified in the path", + py::arg("img"), py::arg("filename"), py::arg("quality") = 75 + ); m.def("save_image", &save_image, "Saves the given image to the specified path. Determines the file type from the file extension specified in the path", py::arg("img"), py::arg("filename"), py::arg("quality") = 75