i use below code for capture video from camera.I do processing ,but i have a problem. I calculate fps but for all frame i see fps=0 and CV_CAP_PROP_FPS=5. how can i calculate fps of my camera?
#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("e:/hassan_1.avi"); // open the default camera
//VideoCapture cap("d:/1.mpg"); // open the default camera
VideoCapture cap(-1);
if(!cap.isOpened()) // check if we succeeded
return -1;
int fps=(float) cap.get(CV_CAP_PROP_FPS)+0.5;
int totalframes=(int) cap.get(CV_CAP_PROP_FRAME_COUNT);
cout<<"total frames ="<<totalframes<<endl;
cout<<"fps= "<<fps<<endl;
getch();
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)+0.5;
//int totalframes=(int) cap.get(CV_CAP_PROP_FRAME_COUNT);
//cout<<"total frames ="<<totalframes<<endl;
cout<<"fps= "<<fps<<endl;
//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++;
//cout<<k<<endl;
//getch();
if (waitKey(10)>=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;
}