使用opencv从文件读取视频时出现分段错误

时间:2013-10-22 10:25:31

标签: c++ c opencv segmentation-fault

我正在运行一个简单的代码来捕获文件中的视频,但它返回了一个分段错误

     #include "opencv2/highgui/highgui.hpp"
     #include<opencv2/opencv.hpp>
     #include <stdio.h>
     //#include <iostream>

     using namespace cv;
     using namespace std;

     int main()
     {
    CvCapture* capture = cvCreateFileCapture("/home/ayush/20130521053652.avi");

    IplImage* frame = NULL;

    if(!capture)
    {
        printf("Video Not Opened\n");
        return -1;
    }

    int width = (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH);
    int height = (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT);
    double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
    int frame_count = (int)cvGetCaptureProperty(capture,  CV_CAP_PROP_FRAME_COUNT);

    printf("Video Size = %d x %d\n",width,height);
    printf("FPS = %f\nTotal Frames = %d\n",fps,frame_count);

    while(1)
    {
        frame = cvQueryFrame(capture);

        if(!frame)
        {
            printf("Capture Finished\n");
            break;
        }

        cvShowImage("video",frame);
        cvWaitKey(10);
    }

    cvReleaseCapture(&capture);
    return 0;
}

我也试过上面的代码,这实际上是一个特定问题的解决方案,但它仍然给我一样的东西......

视频文件信息

   $file 20130521053652.avi 
   20130521053652.avi: RIFF (little-endian) data, AVI, 640 x 480, 30.00 fps, video:

更多信息

   Dimensions: 640 x 480
   Codec:      24-bit RGB
   Framerate:  30 frames per second
   Bitrate:    N/A  

我认为编解码器一定存在问题我的平台是linux / ubuntu 12.04 LTS请任何机构建议我解决这个问题

通过gdb调试器,分段错误在frame = cvQueryFrame(capture)

处给出

o / p就是这个

     (gdb) 
      66          frame = cvQueryFrame(capture);           
     (gdb) 

                  Program received signal SIGSEGV, Segmentation fault.
                __memcpy_ssse3 () at ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S:160
       160  ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S: No such file or directory.

通过Qt IDE ==&gt;调试

      0xb751d9fa  <+0x146a>         movzbl (%eax),%eax
      1951  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      0xb751d9fd  <+0x146d>         mov    %al,(%edx)
      1952  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      1953  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      0xb751d9ff  <+0x146f>         mov    0x8(%esp),%eax
      1954  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      1955  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      1956  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      1957  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      1958  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      1959  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      0xb751da03  <+0x1473>         pop    %ebx
      0xb751da04  <+0x1474

1 个答案:

答案 0 :(得分:1)

我在OpenCV 2.4中遇到了同样的问题,使用了cvCaptureFromFile()/ cvQueryFrame()。将我的AVI转换为FLV(使用avconv)对我有用。

我的猜测是这是一个OpenCV错误。