Page 1 of 1

ImageMagick + Opencv

Posted: 2011-02-25T12:38:04-07:00
by Xenith
at first sorry for my bad English!

we know that one of the richest library for image manipulating is ImageMagick, but its document specially in Magick++ is not as rich as its library. by the way, this is my first experience to use ImageMagicK and Opencv. if you want to convert from IplImage to Image and vice versa, just put these two funtion inside you source file.

Code: Select all

Image Ipl2Magick(IplImage* iplImage)
{
	Image mgk(iplImage->width, iplImage->height, "BGR", CharPixel, (char *)iplImage->imageData);
	return mgk;
}

Code: Select all

void Magick2Ipl(Image magicImage, IplImage* cvImage)
{
	int width= magicImage.size().width();
	int height = magicImage.size().height();

	byte* blob= new byte[cvImage->imageSize];
	magicImage.write(0,0, width, height, "BGRA", MagickCore::CharPixel, blob);
	memcpy(cvImage->imageData, blob, cvImage->imageSize);
	delete [] blob;
}
and the last thing, don't forget to make the cvImage parameter as a 4 channels something like this:

Code: Select all

IplImage* cvimg =  cvCreateImage(cvSize(...,...), IPL_DEPTH_8U, 4);
hope these tips help you :D