Ask Your Question

Manavi's profile - activity

2014-10-05 10:50:38 -0500 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:

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/background_segm.hpp>
#include <opencv2/video/video.hpp>
#include <stdio.h>
#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("FG Mask MOG");

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

  char* videoFilename;

  VideoCapture capture(videoFilename);
    //error in opening the video input
    cerr << "Unable to open video file: " << videoFilename << endl;
  //read input data. ESC or 'q' for quitting
  while( (char)keyboard != 'q' && (char)keyboard != 27 )
    //read the current frame
      cerr << "Unable to read next frame." << endl;
      cerr << "Exiting..." << endl;
     pMOG->apply(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 );
   //destroy GUI windows
  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!