-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtevent_stats.cpp
More file actions
76 lines (71 loc) · 1.63 KB
/
tevent_stats.cpp
File metadata and controls
76 lines (71 loc) · 1.63 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "teventcamera.h"
#include <fstream>
uint16_t findMin(uint16_t *arr,size_t n)
{
uint16_t temp=0;
for(size_t i=0;i<n;++i){
if(arr[i]<temp){
temp = arr[i];
}
}
return temp;
}
uint64_t findMax(uint16_t *arr,size_t n)
{
uint64_t temp=0;
for(size_t i=0;i<n;++i){
if(arr[i]>temp){
temp=arr[i];
}
}
return temp;
}
float findMean(uint16_t *arr,size_t n)
{
uint64_t sum = 0;
for(size_t i=0;i<n;++i){
sum += arr[i];
}
return (float)sum/(float)n;
}
float findStdDev(uint16_t *arr,size_t n,float mean)
{
float var = 0;
for(size_t i=0;i<n;++i){
auto sub = (float)arr[i]-mean;
var += (sub*sub);
}
var /= (float)n;
return sqrt(var);
}
int main(){
ThermalEventCamera cam(32);
int tlim = 120;
std::ofstream statfile;
statfile.open("Scripts/bin/event_stats.csv",std::ofstream::out |std::ofstream::trunc);
statfile << "min,max,mean,std\n";
// copy of frame to find stats on
uint16_t ff[834] = {0};
// get start time of program
auto start = std::chrono::system_clock::now();
cam.start();
while(cam.isUpdateAlive(0))
{
cam.getFrame(ff);
statfile << findMin(ff,834) << ',' << findMax(ff,834) << ',';
float mean = findMean(ff,834);
statfile << mean << ',' << findStdDev(ff,834,mean) << '\n';
// get elapsed time
auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now() - start);
// if the elapsed time exceeds the limit, break from loop
if(elapsed.count()>tlim){
std::cout << "stopping due to time limit" << std::endl;
cam.stop();
statfile.close();
return 0;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
statfile.close();
return 1;
}