gmic-community icon indicating copy to clipboard operation
gmic-community copied to clipboard

How to Read and Export OpenCV cv::Mat Image Data with libcgmic C++ Library

Open seasnakes opened this issue 10 months ago • 2 comments

@dtschump I am trying to integrate libgmic into an existing SDK that uses OpenCV for image processing. The challenge is that the SDK relies on OpenCV's cv::Mat format for handling and passing image data , but I haven't found clear documentation on how to read and export images between cv::Mat and libgmic(maybe cimg?) in memory. So do you know how to do data transfer between libgmic and Opencv without relying on intermediate formats or binary files. Thanks in advance!

seasnakes avatar Jan 21 '25 04:01 seasnakes

I don't think this is possible. You have to convert the mat structure into an intermediate pixel data object first, then pass this to the gmic library call, then convert the output buffer you receive back to cv::mat. That is how integration in other frameworks/SDKs is handled as well (e.g. After Effects, Nuke, etc.).

tobybear avatar Jan 21 '25 04:01 tobybear

Look at the source for the gmic_call function. Here the pointer to the raw RGB pixel data gets converted into a gmic_image. This is what you need to do for cv::mat as well, but since a cv::mat can hold a variety of pixel data, bit depths and colorspace formats, you have to define a custom mapping here.

tobybear avatar Jan 21 '25 04:01 tobybear