如何使用Boost :: GIL从python字节字符串读取图像信息?

时间:2020-05-07 10:59:34

标签: boost boost-python boost-gil

我编写了一个从文件头读取图像宽度和高度的函数

int read_image_dimensions() {
    namespace bg = boost::gil;

    std::string filepath = "image.png";
    std::ifstream byte_stream(filepath, std::ios::binary);

    int width = 0, height = 0;
    bg::image_read_info<bg::png_tag> png_tag_info;

    png_tag_info = bg::read_image_info(byte_stream, bg::image_read_settings<bg::png_tag>())._info;
    width = png_tag_info._width; height = png_tag_info._height;

    std::cout << width << "x" << height << std::endl;
    return 0;
}

我也不知道如何从python字节读取图像信息 Image data taken from Blender API,与在图像文件中写入的内容相同。

using namespace boost::python;

int read_image_dimensions(object &image) {
    object image_packed_file = extract<object>(image.attr("packed_file"));
    object packed_data = extract<object>(image_packed_file.attr("data"));
    size_t packed_size = extract<size_t>(image_packed_file.attr("size"));

    // ... 
}

0 个答案:

没有答案