Ask Your Question
1

How to calculate Frames per second? [closed]

asked 2016-04-21 04:39:29 -0500

Sandesh14 gravatar image

updated 2016-04-21 11:32:45 -0500

berak gravatar image

I am using CameraBridgeViewBase object to create an app that uses camera. I want frames per second to decide somethings in my app. How can I frames per second? can I use Videoio.CAP_PROP_FPS for this purpose?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Sandesh14
close date 2016-04-22 10:23:53.068513

2 answers

Sort by ยป oldest newest most voted
2

answered 2016-04-21 11:16:34 -0500

The following code prints the FPS every second. Use it as an example.

#include <iostream>
#include <ctime>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace std;

int main()
{
    cv::VideoCapture cam;

    if (!cam.open(0))
        std::cout << "Problem connecting to cam " << std::endl;
    else
        std::cout << "Successfuly connected to camera " << std::endl;

    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;
        }
    }

    return 0;
}
edit flag offensive delete link more

Comments

Thanks for providing an example.

Sandesh14 gravatar imageSandesh14 ( 2016-04-22 10:17:32 -0500 )edit
1

answered 2016-04-21 11:53:39 -0500

berak gravatar image

CameraBridgeViewBase has a enableFpsMeter() method ,which will calc fps, and show it in an overlay.

edit flag offensive delete link more

Comments

I know that but I want fps to be stored in a variable and should be able to use in some of the calculations I want to do on the image data obtained.

Sandesh14 gravatar imageSandesh14 ( 2016-04-21 12:04:30 -0500 )edit
1
berak gravatar imageberak ( 2016-04-22 00:09:24 -0500 )edit

I had seen that code before. Still your comment was helpful!!! Thanks

Sandesh14 gravatar imageSandesh14 ( 2016-04-22 10:20:20 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-04-21 04:39:29 -0500

Seen: 4,019 times

Last updated: Apr 21 '16