[poppler] OpenCV and the image format in older versions of Poppler

Stéphane Charette stephanecharette at gmail.com
Sun May 1 13:31:48 UTC 2022


Thank you.  That did help me get it working.  The format is indeed
32-bit BGRA.  In case this thread comes up in the future, the relevant
code for older versions of Poppler is this:

    poppler::image image = renderer.render_page(page, dpi, dpi);
    cv::Mat src(image.height(), image.width(), CV_8UC4, image.data(),
image.bytes_per_row());
    cv::Mat dst;
    cv::cvtColor(src, dst, cv::COLOR_BGRA2BGR);

Note the cv::Mat type is 8UC4, for the 4-channel BGRA.

Stéphane


On Sun, May 1, 2022 at 3:04 AM suzuki toshiya
<mpsuzuki at hiroshima-u.ac.jp> wrote:
>
> Hi Stéphane,
>
> According to:
>
> https://gitlab.freedesktop.org/poppler/poppler/-/blob/poppler-0.62.0/cpp/poppler-page-renderer.cpp#L191
>
>      const image img(reinterpret_cast<char *>(data_ptr), bw, bh, image::format_argb32);
>
> It might be ARGB32 format (although I've not confirmed yet).
>
> Regards,
> mpsuzuki
>
> On 2022/05/01 9:08, Stéphane Charette wrote:
> > I'm combining Poppler and OpenCV.  I use poppler::page_renderer's call
> > set_image_format() so the image can easily be used in OpenCV.  Code
> > more-or-less looks like this:
> >
> > renderer.set_image_format(poppler::image::format_enum::format_bgr24);
> > poppler::image image = renderer.render_page(page, dpi, dpi);
> > cv::Mat mat(image.height(), image.width(), CV_8UC3, image.data(),
> > image.bytes_per_row());
> >
> > But with older versions of Poppler (like what is included in Ubuntu
> > 18.04:  poppler 0.62.0) the call to set_image_format() does not exist.
> > What is the image format used by poppler in this case?
> >
> > Stéphane


More information about the poppler mailing list