Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get fps/frames per second of a videocapture object

I am using a videocapture object to capture and process frames of a video in opencv/javacv. I dont know how to get the frame rate.I want a timer that runs in the background during the live video capture.It should pause on a face being detected and continue later. Due to the processing of haarcascade file,it is taking much time for each rame to process. how to adjust the frame rate.

   System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
   VideoCapture camera = new VideoCapture(0);
like image 260
slaveCoder Avatar asked Feb 18 '14 12:02

slaveCoder


3 Answers

You can extract various parameter from VideoCapture like frame rate, frame height, frame width etc.

cv::VideoCapture input_video;
 if(input_video.open(my_device))
 {
    std::cout<<"Video file open "<<std::endl;
 }
 else
 {
    std::cout<<"Not able to Video file open "<<std::endl;

 }
int fps = input_video.get(CV_CAP_PROP_FPS);
int frameCount = input_video.get(CV_CAP_PROP_FRAME_COUNT);
double fheight = input_video.get(CV_CAP_PROP_FRAME_HEIGHT);
double fwidth = input_video.get(CV_CAP_PROP_FRAME_WIDTH);
like image 110
praks411 Avatar answered Nov 30 '22 23:11

praks411


 System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
 VideoCapture VC = new VideoCapture(0);

//First you requried open Camera.

VC.open();

//Now for geting 'Frame per secand"

VC.get(Videoio.CAP_PROP_FPS); // it returns FPS(Frame per secand)

//Now for seting 'Frame per secand"

VC.set(Videoio.CAP_PROP_FPS,10.0);//in this 10.0 is value for FPS,its double value.
VC.relase();
like image 43
Pranav Avatar answered Dec 01 '22 00:12

Pranav


This answer helps me. There is a list of constants and their values. Just put value to VideoCapture's get() method. Ex. videoCapture.get(5), will return FPS of video.

like image 38
cylinder.y Avatar answered Nov 30 '22 23:11

cylinder.y