使用giflib segfault C ++提取帧 [英] Extracting frames with giflib segfault C++

查看:427
本文介绍了使用giflib segfault C ++提取帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上试图使用giflib从gif文件中提取图像,并使用以下代码。

I'am actually trying to extract images from a gifFile using the giflib with the following code.

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;
}

但这会导致segfault。我在v2.4.5中使用opencv,在v5.0.4中使用giflib。
我认为这不是由Opencv引起的,因为在v4中的giflib在这里没有问题。

But this causes a segfault. I am using opencv in v2.4.5 and giflib in v5.0.4. I think this is not caused by Opencv because with giflib in v4 I had no problem here.

更多以下测试也会导致segfault。

MoreOver the following test also causes 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表。

I also don't find how to get color back using the colorGlobal table.

有人可以帮助我吗?
感谢

Can someone Help me ? Thanks

推荐答案

我只是回到4.1.6版本,一切都很好。 v5可能有bug。

I just get back to version 4.1.6 and everything is good. The v5 is probably bugged.

这篇关于使用giflib segfault C ++提取帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆