6

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?

Bill Cheatham
  • 11,396
  • 17
  • 69
  • 104

2 Answers2

12

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

Sam
  • 19,708
  • 4
  • 59
  • 82
-1

mat is always bigger then the image itself. The width is changed to multiple of 2 for sake of more efficient accessing the image data.

joey
  • 1