Skip to content

Instantly share code, notes, and snippets.

@alepez
Created November 7, 2017 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alepez/b6e4264bf92d5bb082713cb745b35bab to your computer and use it in GitHub Desktop.
Save alepez/b6e4264bf92d5bb082713cb745b35bab to your computer and use it in GitHub Desktop.
#include "opencv2/opencv.hpp"
#include <ctime>
#include <sys/timeb.h>
using namespace cv;
int main(int, char**) {
VideoCapture cap(1); // open the default camera
if (!cap.isOpened()) // check if we succeeded
return -1;
cap.set(cv::CAP_PROP_FRAME_WIDTH, 1280);
cap.set(cv::CAP_PROP_FRAME_HEIGHT, 720);
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));
Mat edges;
namedWindow("edges", 1);
int i = 0;
clock_t start, stop;
struct timeb tstart, tstop;
start = clock();
ftime(&tstart);
for (;;) {
Mat frame;
cap >> frame; // get a new frame from camera
++i;
stop = clock();
ftime(&tstop);
double diff = (stop - start) / double(CLOCKS_PER_SEC);
double tdiff = ((1000.0 * (tstop.time - tstart.time) + (tstop.millitm - tstart.millitm))) / 1000.0;
double rate = i / tdiff;
printf("n: %d, rate: %f, cpu_time=%.3f time=%.3f\n", i, rate, diff, tdiff);
// imshow("edges", frame);
// if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment