I have written some code to read a video and do some processing on it.
int totalframes=(int) cap.get(CV_CAP_PROP_FRAME_COUNT);
total frames=1707
int fps=(int) cap.get(CV_CAP_PROP_FPS);
fps=30
I do processing on each frame but my code does it for only 804 frames. How can I do the processing for all frames? After processing 804 frames ,i see this text:
Unhandled exception at at 0x75299617 in opencv learning.exe: Microsoft C++ exception: cv::Exception at memory location 0x0041B778.
this is a .avi video format.
Can you please help me to solve this problem? I use windows 7,visual studio 2012,opencv 2.4.6 for processing this video file. my code:
#include "opencv2/opencv.hpp"
#include <stdio.h>
#include <conio.h>
using namespace cv;
using namespace std;
int main(int, char**)
{
int k=0;
VideoCapture cap("f:/video for test/hassan_1.avi"); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
bool stop(false);
Mat edges;
namedWindow("edges",1);
while(!stop)
{
Mat frame;
cap >> frame; // get a new frame from camera
int fps=(int) cap.get(CV_CAP_PROP_FPS);
int totalframes=(int) cap.get(CV_CAP_PROP_FRAME_COUNT);
double delay=1000/fps;
cvtColor(frame, edges, CV_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
k++;
if (waitKey(delay)>=0)
stop= true;
}
cap.release();
cout<<"number of frames that do processing on them= "<<k<<endl;
getch();
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}