mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
allow reading and writing rgb-alpha images in Python (#2925)
This commit is contained in:
parent
d45f534d68
commit
d5909ed977
@ -262,6 +262,7 @@ namespace dlib
|
|||||||
else if (is_image<float>(src)) assign_image(dest, numpy_image<float>(src));
|
else if (is_image<float>(src)) assign_image(dest, numpy_image<float>(src));
|
||||||
else if (is_image<double>(src)) assign_image(dest, numpy_image<double>(src));
|
else if (is_image<double>(src)) assign_image(dest, numpy_image<double>(src));
|
||||||
else if (is_image<rgb_pixel>(src)) assign_image(dest, numpy_image<rgb_pixel>(src));
|
else if (is_image<rgb_pixel>(src)) assign_image(dest, numpy_image<rgb_pixel>(src));
|
||||||
|
else if (is_image<rgb_alpha_pixel>(src)) assign_image(dest, numpy_image<rgb_alpha_pixel>(src));
|
||||||
else DLIB_CASSERT(false, "Unsupported pixel type used in assign_image().");
|
else DLIB_CASSERT(false, "Unsupported pixel type used in assign_image().");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,13 @@ numpy_image<rgb_pixel> load_rgb_image (const std::string &path)
|
|||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
numpy_image<rgb_pixel> load_rgb_alpha_image (const std::string &path)
|
||||||
|
{
|
||||||
|
numpy_image<rgb_alpha_pixel> img;
|
||||||
|
load_image(img, path);
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
numpy_image<unsigned char> load_grayscale_image (const std::string &path)
|
numpy_image<unsigned char> load_grayscale_image (const std::string &path)
|
||||||
{
|
{
|
||||||
numpy_image<unsigned char> img;
|
numpy_image<unsigned char> 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",
|
"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
|
py::arg("img"), py::arg("filename"), py::arg("quality") = 75
|
||||||
);
|
);
|
||||||
|
m.def("save_image", &save_image<rgb_alpha_pixel>,
|
||||||
|
"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<unsigned char>,
|
m.def("save_image", &save_image<unsigned char>,
|
||||||
"Saves the given image to the specified path. Determines the file type from the file extension specified in the path",
|
"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
|
py::arg("img"), py::arg("filename"), py::arg("quality") = 75
|
||||||
|
Loading…
Reference in New Issue
Block a user