Ask Your Question

Manavi's profile - activity

2014-10-05 10:50:38 -0600 asked a question Error in video capture in OpenCV 2.4.2+ VS2010 Ultimate

I used the following code for implementing Background Subtraction in OpenCV:

//opencv
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/background_segm.hpp>
#include <opencv2/video/video.hpp>
//C
#include <stdio.h>
//C++
#include <iostream>
#include <sstream>

using namespace cv;
using namespace std;

//global variables
Mat frame; //current frame
Mat fgMaskMOG; //fg mask fg mask generated by MOG method

Ptr<BackgroundSubtractor> pMOG; //MOG Background subtractor
int keyboard;

int main( )
{
  //create GUI windows
  namedWindow("Frame");
  namedWindow("FG Mask MOG");

  //create Background Subtractor objects
  pMOG = new BackgroundSubtractorMOG(); //MOG approach

  char* videoFilename;
  videoFilename="E:\\Vide123.avi";

  VideoCapture capture(videoFilename);
  if(!capture.isOpened())
  {
    //error in opening the video input
    cerr << "Unable to open video file: " << videoFilename << endl;
    exit(EXIT_FAILURE);
  }
  //read input data. ESC or 'q' for quitting
  while( (char)keyboard != 'q' && (char)keyboard != 27 )
  {
    //read the current frame
    if(!capture.read(frame)) 
    {
      cerr << "Unable to read next frame." << endl;
      cerr << "Exiting..." << endl;
      exit(EXIT_FAILURE);
    }
     pMOG->apply(frame, fgMaskMOG);

     pMOG->operator()(frame,fgMaskMOG);
         //get the frame number and write it on the current frame
    stringstream ss;
    rectangle(frame, cv::Point(10, 2), cv::Point(100,20),
              cv::Scalar(255,255,255), -1);
    ss << capture.get(CAP_PROP_POS_FRAMES);
    string frameNumberString = ss.str();
    putText(frame, frameNumberString.c_str(), cv::Point(15, 15),
            FONT_HERSHEY_SIMPLEX, 0.5 , cv::Scalar(0,0,0));
    //show the current frame and the fg masks
    imshow("Frame", frame);
    imshow("FG Mask MOG", fgMaskMOG);

    //get the input from the keyboard
    keyboard = waitKey( 30 );
  }
   capture.release();
   //destroy GUI windows
  destroyAllWindows();
  return 0;
}

I got the following warning: Error opening file(../../module/highgui/src/cap_ffmpeg_impl.hpp:361)

Unhandled exception at 0X77467bb8(ntdll.dll) in cvp.exe: 0xC0000005: Access violation reading location 0x718df4d8

I am new to openCV and video processing.. Any help would be appreciated. Please help me out!