However, using MagickReadImageFile, I can not read image.
I use window 7, QT.
Here is my code:
Code: Select all
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "magick/MagickCore.h"
#include "wand/MagickWand.h"
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
//#include <Magick++.h>
#include <iostream>
//#include <list>
#include <QFile>
#include <QDir>
#include <QFileInfo>
using namespace cv;
using namespace std;
//using namespace magick;
//using namespace Magick;
void ThrowWandException(MagickWand *wand) {
char *description;
ExceptionType severity;
description = MagickGetException(wand, &severity);
(void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description);
description=(char *) MagickRelinquishMemory(description);
exit(-1);
}
void LoadGifImage(const char *filename, std::vector<cv::Mat> &dest)
{
cout << "Start LoadGifImage";
MagickBooleanType status;
MagickWand *magick_wand;
MagickWandGenesis();
MagickCoreGenesis(NULL, MagickTrue);
magick_wand = NewMagickWand();
ExceptionInfo *exception;
exception = AcquireExceptionInfo();
QFile qf(filename);
qf.open(QIODevice::ReadOnly);
int fd = qf.handle();
FILE *fp = fdopen(fd, "rb");
if (!fp){
qf.close();
}
status = MagickReadImageFile(magick_wand, fp);
qf.close();
fclose(fp);
//status = MagickReadImage(magick_wand, filename);
if (status == MagickFalse) {
cout << "Not sucess: ";
}
Image *image = GetImageFromMagickWand(magick_wand);
size_t image_num = MagickGetNumberImages(magick_wand);
cv::Mat img;
for (int i = 0; i < image_num; i++) {
//Convert Image structure into cv:Mat
img = cv::Mat(image->rows, image->columns, CV_8UC4);
ExportImagePixels(image, 0, 0, image->columns, image->rows,
"BGRA", CharPixel, img.data, exception);
dest.insert (dest.begin(), img);
if (i < image_num - 1)
image = GetPreviousImage(image);
}
cout << "End LoadGifImage";
}
int main(int, char** argv) {
char * filename0 = "D:\\asb\\res\\upload\\animal.gif";
vector <Mat> dest;
LoadGifImage(filename0, dest);
for(int i = 0; i < dest.size(); i++)
{
imwrite("D:\\asb\\res\\download\\giphy"+to_string(i)+".png", dest[i]);
}
return(0);
}