Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert cv::Mat to Magick::Image

I am attempting to convert an OpenCV C++ cv::Mat to an ImageMagick Magick::Image. The only examples I can find use the older, C OpenCV iplImage (see, for example, here).

Is there a simple way of achieving this?

like image 843
Bill Cheatham Avatar asked Nov 22 '11 13:11

Bill Cheatham


1 Answers

It's as simple as this:

Image Mat2Magick(Mat& src)
{
   Image mgk(src.cols, src.rows, "BGR", CharPixel, (char *)src.data);
   return mgk;
}

Note that the function does not copy the data. If the magik image is released before you use the Mat image, result is SEGFAULT

like image 103
Sam Avatar answered Oct 18 '22 17:10

Sam