Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenCV: VideoCapture::get(CV_CAP_PROP_FPS) returns 0 FPS
    text
    copied!<p>I am trying to get the fps from my camera so that I can pass it to the <code>VideoWriter</code> for outputting the video. However, I am getting 0 fps by calling <code>VideoCapture::get(CV_CAP_PROP_FPS)</code> from my camera. If I hardcode it, my video may be too slow or too fast.</p> <pre><code>#include "opencv2/opencv.hpp" #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; using namespace std; using namespace cv; int main(int argc, char *argv[]) { cv::VideoCapture cap; int key = 0; if(argc &gt; 1){ cap.open(string(argv[1])); } else { cap.open(CV_CAP_ANY); } if(!cap.isOpened()) { printf("Error: could not load a camera or video.\n"); } Mat frame; cap &gt;&gt; frame; waitKey(5); namedWindow("video", 1); double fps = cap.get(CV_CAP_PROP_FPS); CvSize size = cvSize((int)cap.get(CV_CAP_PROP_FRAME_WIDTH),(int)cap.get(CV_CAP_PROP_FRAME_HEIGHT)); int codec = CV_FOURCC('M', 'J', 'P', 'G'); if(!codec){ waitKey(0); return 0; } std::cout &lt;&lt; "CODEC: " &lt;&lt; codec &lt;&lt; std::endl; std::cout &lt;&lt; "FPS: " &lt;&lt; fps &lt;&lt; std::endl; VideoWriter v("Hello.avi",-1,fps,size); while(key != 'q'){ cap &gt;&gt; frame; if(!frame.data) { printf("Error: no frame data.\n"); break; } if(frame.empty()){ break; } v &lt;&lt; frame; imshow("video", frame); key = waitKey(5); } return(0); } </code></pre> <p>How can I get <code>VideoCapture::get(CV_CAP_PROP_FPS)</code> to return the right fps or give a fps to the <code>VideoWriter</code> that works universally for all webcams?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload