我实际上是在尝试使用带有以下代码的 giflib 从 gifFile 中提取图像。
t_gif initGif(const char *filename){
t_gif gif;
int *error;
GifFileType *GifFile = DGifOpenFileName(filename, error);
assert(error != NULL);
int ret = DGifSlurp(GifFile);
assert(ret == GIF_OK);
gif.h = (int)GifFile->SHeight;
gif.w = GifFile->SWidth;
gif.nbFrames = GifFile->ImageCount;
gif.colorSize = GifFile->SColorResolution;
GifImageDesc Image = GifFile->Image;
SavedImage *img = &GifFile->SavedImages[0];
cout << "width: " << gif.w << endl;
cout << "height: " << gif.h << endl;
cout << "Image Count: " << gif.nbFrames << endl;
cout << "SColor Resolution: " << gif.colorSize << endl;
Mat color = Mat(Size(gif.w, gif.h), CV_8UC1, img->RasterBits);
imwrite("./test.png", color);
return gif;
}
但这会导致段错误。我在 v2.4.5 中使用 opencv,在 v5.0.4 中使用 giflib。我认为这不是由 Opencv 引起的,因为在 v4 中使用 giflib 我在这里没有问题。
MoreOver下面的测试也会导致segfault。
printf("%u\n", (unsigned int)img->RasterBits[0]);
Gdb 输出:
(gdb) run bsd.gif
Starting program: /home/matt/Code/perso/utils/gif/a.out bsd.gif
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Gif Analyser tool
started by MG in may 2013
compiled with giflib: v5.0.4
width: 1000
height: 907
Image Count: 0
SColor Resolution: 8
Program received signal SIGSEGV, Segmentation fault.
0x0000000000401af3 in initGif (filename=0x7fffffffe2be "bsd.gif") at main.cpp:40
40 Mat color = Mat(Size(gif.w, gif.h), CV_8UC1, img->RasterBits);
(gdb)
我也找不到如何使用 colorGlobal 表恢复颜色。
有人能帮我吗 ?谢谢