Ask Your Question
0

How to extract frames in opencv 3.0 c++?

asked 2017-01-18 00:42:09 -0600

Allison gravatar image

I want to extract frames from a video file.But how will i know at what fps to extract the frames? I have been using the code below but

long frameCounter = 0;

    std::time_t timeBegin = std::time(0);
    int tick = 0;

    cv::Mat frame;

    while (1)
    {
        cam.read(frame);

        cv::imshow("Img", frame);
        cv::waitKey(1);

        frameCounter++;

        std::time_t timeNow = std::time(0) - timeBegin;

        if (timeNow - tick >= 1)
        {
            tick++;
            cout << "Frames per second: " << frameCounter << endl;
            frameCounter = 0;
        }
    }
edit retag flag offensive close merge delete

Comments

time() counts in whole seconds, far too coarse for your means.

berak gravatar imageberak ( 2017-01-18 02:41:40 -0600 )edit

Can you give me an idea what should i use instead of time()?

Allison gravatar imageAllison ( 2017-01-18 03:01:17 -0600 )edit

maybe:

int64 t0 = cv::getTickCount();
int64 t1 = cv::getTickCount();   
double seconds = double(t1-t0) / cv::getTickFrequency();

(though beware, this measures clock time, not wall time)

berak gravatar imageberak ( 2017-01-18 03:04:59 -0600 )edit

okay thanks

Allison gravatar imageAllison ( 2017-01-18 03:24:42 -0600 )edit

but if you just want all frames, then grab frames until the frame is empty. You do not need the framerate for that ...

StevenPuttemans gravatar imageStevenPuttemans ( 2017-01-19 10:24:57 -0600 )edit

Can I use the gettickcount() function for frames?

Allison gravatar imageAllison ( 2017-01-21 07:54:55 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-01-18 01:58:35 -0600

LBerger gravatar image

You can try this tutorials first

All flags are here and you need to get CAP_PROP_FPS value

edit flag offensive delete link more

Comments

If you want to " extract frames from a video file" it is get CAP_PROP_FPS and then extract time with i/fps where i is frame number

LBerger gravatar imageLBerger ( 2017-01-18 03:19:17 -0600 )edit

@LBerger in fact i want to know how will i know at what fps to extract the frames from the video file.

Allison gravatar imageAllison ( 2017-01-18 03:27:26 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-18 00:42:09 -0600

Seen: 368 times

Last updated: Jan 18 '17