forked from derekmolloy/boneCV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boneCVtiming.cpp
50 lines (44 loc) · 1.46 KB
/
boneCVtiming.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* boneCVtiming.cpp
*
* Copyright Derek Molloy, School of Electronic Engineering, Dublin City University
* www.derekmolloy.ie
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that source code redistributions retain this notice.
*
* This software is provided AS IS and it comes with no warranties of any type.
*/
#include<iostream>
#include<opencv2/opencv.hpp>
#include<time.h>
using namespace std;
using namespace cv;
int main()
{
VideoCapture capture(0);
capture.set(CV_CAP_PROP_FRAME_WIDTH,640);
capture.set(CV_CAP_PROP_FRAME_HEIGHT,480);
if(!capture.isOpened()){
cout << "Failed to connect to the camera." << endl;
}
Mat frame, edges;
struct timespec start, end;
clock_gettime( CLOCK_REALTIME, &start );
int frames=10;
for(int i=0; i<frames; i++){
capture >> frame;
if(frame.empty()){
cout << "Failed to capture an image" << endl;
return -1;
}
cvtColor(frame, edges, CV_BGR2GRAY);
Canny(edges, edges, 0, 30, 3);
}
clock_gettime( CLOCK_REALTIME, &end );
double difference = (end.tv_sec - start.tv_sec) + (double)(end.tv_nsec - start.tv_nsec)/1000000000.0d;
cout << "It took " << difference << " seconds to process " << frames << " frames" << endl;
cout << "Capturing and processing " << frames/difference << " frames per second " << endl;
imwrite("edges.png", edges);
imwrite("capture.png", frame);
return 0;
}