Ask Your Question
0

Loading 1 frame per 4 second

asked 2017-04-05 05:35:30 -0600

rabi gravatar image

Hi , I have following code

   if ( !cap.isOpened() ) 
   {
     cout << "Cannot open the video file" << endl;
     return -1;
}
double fps = cap.get(CV_CAP_PROP_FPS); 
cout << "Frame per seconds : " << fps << endl;
namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); 
while(1)
{
    Mat frame;

    bool bSuccess = cap.read(frame); 
    if (!bSuccess)
    {
                    cout << "Cannot read the frame from video file" << endl;
                   break;
    }

    imshow("MyVideo", frame);

    if(waitKey(30) == 27)
    {
            cout << "esc key is pressed by user" << endl; 
            break; 
     }

It loads one frame per second. Now , How do I change to read 1 frame in 4 or 5 seconds.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-04-05 05:46:39 -0600

 if(waitKey(30) == 27)

this waits 30 ms -> loads approximately 30 frames per second.

to load one frame per second you need

 if(waitKey(1000) == 27)

for one frame in four second

 if(waitKey(4000) == 27)
edit flag offensive delete link more

Comments

Your code is helpful. thanks

rabi gravatar imagerabi ( 2017-04-05 06:18:38 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-04-05 05:35:30 -0600

Seen: 340 times

Last updated: Apr 05 '17