使用giflib提取帧segfault C ++

我实际上试图从下面的代码使用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我没有问题。

以下testing也会导致段错误。

 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) 

我也没有find如何使用colorGlobal表返回颜色。

有人能帮我吗 ? 谢谢

Solutions Collecting From Web of "使用giflib提取帧segfault C ++"