1

i am trying to execut a program to display a video file using opencv. the program compiles properly. but wen i execute it i get the error : segmentation fault(core dumped). can u please find the error..

    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <stdlib.h>
    #include <opencv2/imgproc/imgproc.hpp>
    #include <opencv2/opencv.hpp>
    #include <iostream>
    #include <fstream>
    #include <stdio.h>

    using namespace cv;
    using namespace std;

    int main(int argc, char *argv[])
    {
        if (argc != 2)
        {
              printf("Usage:video\n");
              return -1;
        }
        VideoCapture capture("Home//cuda-workspace//DisplayVideo//video_1.avi");
        namedWindow("display", cv::WINDOW_AUTOSIZE);


        if(!capture.isOpened())
        {
              printf("Failed to open the video\n");
              return -1;
        }

        for(;;)
        {
              Mat frame;
              capture >> frame; // get a new frame from camera
              imshow("display",frame);
        }

    return 0;
        }
1
  • 1
    We need to know where exactly (on which line) it core-dumps! Commented Jan 6, 2014 at 11:17

4 Answers 4

0

Infinite for loop?!!! I don't think this is correct! You are not exiting from it.

for(;;)
{
    Mat frame;
    capture >> frame; // get a new frame from camera
    imshow("display",frame);
}
Sign up to request clarification or add additional context in comments.

2 Comments

now i made the for loop to iterate to the exact number of frames in video i am not getting any error but the video window is not appering. i tried displaying the values of frame, i got a matrix of values but no window is appearing
It seems this is all together different problem now. Its good idea to open new question mentioning it. If we mixed couple of problems here, it might be confusing..
0

Can you please elaborate your error more specifically means at which line your program crash?

anyway i have re-write your program as follows please check it.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdlib.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <fstream>
#include <stdio.h>

using namespace cv;
using namespace std;

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
      printf("Usage:video\n");
      return -1;
    }

    VideoCapture capture("Home//cuda-workspace//DisplayVideo//video_1.avi");


    double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video

    cout << "Frame per seconds : " << fps << endl;

    namedWindow("display", cv::WINDOW_AUTOSIZE);


    if(!capture.isOpened())
    {
      printf("Failed to open the video\n");
      return -1;
    }

    while(1)
    {
        Mat frame;

        bool bSuccess = capture.read(frame); // read a new frame from video

        if (!bSuccess) //if not success, break loop
        {
            cout << "can't read the frame from video file" << endl;
            break;
        }

        imshow("display",frame);
    }

    return 0;
}

1 Comment

thanks for the reply. but i am still not getting the output. only th e printf line is being displayed..
0

In your program why you traverse for loop 1000 times? It's not true you only traverse until last frame of video. so please make following change in your code and check again.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdlib.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <fstream>
#include <stdio.h>

using namespace cv;
using namespace std;

int main(int argc, char *argv[])
{
    printf("Usage: %s video\n", argv[0]);

    if(argc != 2)
    {
        printf("\nPlease provide video path \n");
        return -1;
    }
    else
    {
        printf("\nyour video file path :%s \n",argv[1]);
    }

    VideoCapture capture(argv[1]);

    namedWindow("display",cv::WINDOW_AUTOSIZE);

    printf("2\n");

    if(!capture.isOpened())
    {
        printf("Failed to open the video\n");

        return -1
    }

    while(1)
    {
        Mat frame;

        bool bSuccess = capture.read(frame); // read a new frame from video

        if (!bSuccess) //if not success, break loop
        {
            cout << "can't read the frame from video file" << endl;
            break;
        }

        imshow("display",frame);
    }

    return 0;
}

1 Comment

hi,i added these two lines to the code: capture.set(cv::CAP_PROP_FRAME_WIDTH, 640); capture.set(cv::CAP_PROP_FRAME_HEIGHT, 480); i am nt getting any error but the video is nt being displayed..
0

I don't know if you solve your problem. But what I do to process a video is the following:

VideoCapture capture("//Home//cuda-workspace//DisplayVideo//video_1.avi");

if(!capture.isOpened())
{
  return -1;
}

namedWindow("display"); 
Mat frame;
while(1)
{
    capture >> frame; // get a new frame from camera
    if (frame.empty()) //When it finish the video it breaks out of the cycle
    {
        break;
    }
    imshow("display",frame);
    waitKey(30);    // This is for you can visualize the video, 
        //otherwise the reading process is very fast 
}

I hope it work for you :) For more information of the usage of waitkey you can check the documentation waitKey documentation

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.