Error in video capture in OpenCV 2.4.2+ VS2010 Ultimate

asked 2014-10-05 10:50:38 -0500

Manavi gravatar image

updated 2014-10-06 06:16:36 -0500

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!

edit retag flag offensive close merge delete

Comments

1

Try double backslashes in the path of your videoFilename. so "E:\\Vide123.avi".

boaz001 gravatar imageboaz001 ( 2014-10-05 14:11:51 -0500 )edit
1

Remove the use of the char pointer in C++ code. Use the following command directly. VideoCapture capture("E:\\test\\Vide123.avi"); And to add to that put your file not in a root folder! A basic user doesn't has reading rights there. Also are you sure that it shouldnt be video123.avi?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-06 06:19:16 -0500 )edit