Search code examples
c++opencvvideo-capturecentos6

How to solved Segmentation fault when read the next video frame on centos


I run this program on Centos6.8, I always got Segmentation fault (core dumped)

I also used GDB to debug,it says

Program received signal SIGSEGV, Segmentation fault.
memcpy () at ../sysdeps/x86_64/memcpy.S:398
398     movq    48(%rsi), %r13

But when I run this same program on my Ubuntu 18.04, it worked great.

Does anything I miss install on Centos, or I need to change another API to read frame.

BTW, I can read four frames at the beginning, after that, I got Segmentation fault.

Opencv version is 2.4.9

#include <iostream>
#include <math.h>
#include <chrono>
#include <opencv2/opencv.hpp>
#include <fstream>

using namespace std;
using namespace cv;

int main(int argc, char* argv[])
{
    Mat image;
    int a;
    VideoCapture video("15_41_24_24670.avi");
    int i = 0;
    try{
        while(true){
            video >> image;
            if(image.empty())
                break;
            cout << i++ <<endl;
        }
    }
    catch(std::exception& e){
        std::cerr << "Exception caught : " << e.what() << std::endl;
        cout<<"error"<<endl;
        return 0;
    }
    cout<<"successful"<<endl;
    return 0;
}

Output:

0
1
2
3
4
5
6
Segmentation fault (core dumped)

Solution

  • Try to set backend for VideoCapture:

    VideoCapture video("15_41_24_24670.avi", cv::CAP_FFMPEG);

    or

    VideoCapture video("15_41_24_24670.avi", cv::CAP_GSTREAMER);

    or anything else