0

i wanted to measure the fps of my camera. I found a simple code here. If i compile the code with codeBlocks (on Ununtu) and run the loop for 600 times, the result is 27 fps.

if i compile it from the terminal with:

    g++ -Wall main.cpp -o  main -I/usr/local/include/ -lopencv_core -lopencv_highgui

the result is 14 fps. Why is it so slow after compiling from the terminal?

Here is the code

#include "opencv2/opencv.hpp"
#include <time.h>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{

// Start default camera
VideoCapture video(0);

// With webcam get(CV_CAP_PROP_FPS) does not work.
// Let's see for ourselves.

double fps;


// Number of frames to capture
int num_frames = 600;

// Start and end times
time_t start, end;

// Variable for storing video frames
Mat frame;

cout << "Capturing " << num_frames << " frames" << endl ;

// Start time
time(&start);

// Grab a few frames
for(int i = 0; i < num_frames; i++)
{
    video >> frame;
}

// End Time
time(&end);

// Time elapsed
double seconds = difftime (end, start);
cout << "Time taken : " << seconds << " seconds" << endl;

// Calculate frames per second
fps  = num_frames / seconds;
cout << "Estimated frames per second : " << fps << endl;

// Release video
video.release();
return 0;
}
H.Kai
  • 9
  • 3
  • 7
    What compiler is CodeBlocks using and with what optimization flag? Also never measure anything in debug mode. Add -O2 to the command line and try again. – DeiDei Dec 02 '16 at 23:00
  • i added -O2 to the command line but nothing changed. In codeBlocks the GNU GCC Compiler is selected and only the flag -g (Produce debgging symbols) is selected. The settings are defult, i didnt change anything. – H.Kai Dec 02 '16 at 23:07
  • 1
    To compare compilers for speed you have to compare with options that produce the fastest binaries. You need to find the options in both compilers that will make the code run the fastest, and then compare only those fastest runs. – Dialecticus Dec 03 '16 at 00:02

2 Answers2

0

You just need to compile on the command line the same way that Code::Blocks is compiling. To see what that is, go to Settings for Compiler and Debugging and enable one of the build logging options. More details on that are here: Code::blocks verbose build

Community
  • 1
  • 1
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • i tryed it that way too. g++ -Wall -fexceptions -O2 -I/usr/local/include/opencv2 -I/usr/local/include/opencv -c main.cpp -o main.o g++ -L/usr/local/bin -o main main.o -s -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab The result was the same. – H.Kai Dec 03 '16 at 12:01
  • But there is weird behaviour. if i start the programm from the terminal and minimize the terminal the programm prints 27 fps. if i stay on the terminal it is 14 fps. I'm not outputting something during counting .... – H.Kai Dec 03 '16 at 12:02
0

I think i solved the problem. when the light is bright, the fps are high. if it is dark, the fps are low. So maybe there is a connection to the brightness ...

H.Kai
  • 9
  • 3