forked from cinepi/cinepi-raw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcinepi_frameinfo.hpp
86 lines (70 loc) · 2.98 KB
/
cinepi_frameinfo.hpp
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
77
78
79
80
81
82
83
84
85
86
#pragma once
#include <cstdio>
#include <string>
#include <linux/bcm2835-isp.h>
#include <libcamera/controls.h>
#include "core/frame_info.hpp"
#define HISTOGRAM_SIZE 3*NUM_HISTOGRAM_BINS
struct CinePIFrameInfo : public FrameInfo
{
CinePIFrameInfo(libcamera::ControlList &ctrls)
: FrameInfo(ctrls)
{
auto colorT = ctrls.get(libcamera::controls::ColourTemperature);
if (colorT)
colorTemp = *colorT;
auto sts = ctrls.get(libcamera::controls::SensorTimestamp);
if(sts){
ts = (*sts);
}
#ifdef LIBCAMERA_CINEPI_CONTROLS
trafficLight = 0;
threshold_l = 2.0;
threshold_h = 25.0;
auto histo = ctrls.get(libcamera::controls::RawHistogram);
if(histo){
memcpy(histogram,&(*histo)[0],sizeof(histogram));
}
auto histo_stats = ctrls.get(libcamera::controls::RawHistogramExt);
if(histo_stats){
histogram_stats[0] = (*histo_stats)[0];
histogram_stats[1] = (*histo_stats)[1];
histogram_stats[2] = (*histo_stats)[2];
histogram_stats[3] = (*histo_stats)[3];
histogram_stats[4] = (*histo_stats)[4];
histogram_stats[5] = (*histo_stats)[5];
histogram_stats[6] = (*histo_stats)[6];
histogram_stats[7] = (*histo_stats)[7];
histogram_stats[8] = (*histo_stats)[8];
rL = ((float)histogram_stats[3] / (float)histogram_stats[0])*100.0;
gL = ((float)histogram_stats[4] / (float)histogram_stats[1])*100.0;
bL = ((float)histogram_stats[5] / (float)histogram_stats[2])*100.0;
rH = ((float)histogram_stats[6] / (float)histogram_stats[0])*100.0;
gH = ((float)histogram_stats[7] / (float)histogram_stats[1])*100.0;
bH = ((float)histogram_stats[8] / (float)histogram_stats[2])*100.0;
trafficLight = 0;
trafficLight ^= (-(rL > threshold_l) ^ trafficLight) & (0x01);
trafficLight ^= (-(gL > threshold_l) ^ trafficLight) & (0x02);
trafficLight ^= (-(bL > threshold_l) ^ trafficLight) & (0x04);
trafficLight ^= (-(rH > threshold_h) ^ trafficLight) & (0x10);
trafficLight ^= (-(gH > threshold_h) ^ trafficLight) & (0x20);
trafficLight ^= (-(bH > threshold_h) ^ trafficLight) & (0x40);
}
#endif
}
#ifdef LIBCAMERA_CINEPI_CONTROLS
std::string histoString() const{
std::ostringstream os;
os << rL << "%, " << gL << "%, " << bL << "% : " << rH << "%, " << gH << "%, " << bH << "%";
// os << (unsigned int)trafficLight;
return os.str();
};
uint8_t trafficLight;
float threshold_h, threshold_l;
float rL, gL, bL, rH, gH, bH;
int32_t histogram[HISTOGRAM_SIZE];
int32_t histogram_stats[9];
#endif
unsigned int colorTemp;
int64_t ts;
};