CVB++ 15.0
white_balance.hpp
1#pragma once
2
3#include "global.hpp"
4
5#include "image.hpp"
6
7namespace Cvb
8{
9
10 CVB_BEGIN_INLINE_NS
11
13
22 {
23 public:
25
31 WhiteBalanceFactors(double red, double green, double blue)
32 {
33 SetRed(red);
34 SetGreen(green);
35 SetBlue(blue);
36 }
37
39
43 double Red() const noexcept
44 {
45 return static_cast<double>(red_) / ConversionFactor;
46 }
47
49
53 void SetRed(double red)
54 {
55 if ((red < 0.0) || (red > MaxFactor))
56 throw std::invalid_argument("argument out of range for red factor");
57
58 red_ = static_cast<int>(red * ConversionFactor);
59 }
60
62
66 double Green() const noexcept
67 {
68 return static_cast<double>(green_) / ConversionFactor;
69 }
70
72
76 void SetGreen(double green)
77 {
78 if ((green < 0.0) || (green > MaxFactor))
79 throw std::invalid_argument("argument out of range for green factor");
80
81 green_ = static_cast<int>(green * ConversionFactor);
82 }
83
85
89 double Blue() const noexcept
90 {
91 return static_cast<double>(blue_) / ConversionFactor;
92 }
93
95
99 void SetBlue(double blue)
100 {
101 if ((blue < 0.0) || (blue > MaxFactor))
102 throw std::invalid_argument("argument out of range for blue factor");
103
104 blue_ = static_cast<int>(blue * ConversionFactor);
105 }
106
108
113 {
114 return WhiteBalanceFactors(1.0, 1.0, 1.0);
115 }
116
117 private:
118 int red_ = 1;
119 int green_ = 1;
120 int blue_ = 1;
121
122 static constexpr double MaxFactor = 16.0;
123 static constexpr double ConversionFactor = 256.0;
124 };
125
127
138 {
141 if (!CVB_CALL_CAPI(
142 CalculateWhiteBalance(image.Handle(), *reinterpret_cast<CExports::TArea *>(&aoi), red, green, blue)))
143 Utilities::SystemInfo::ThrowLastError();
144
145 return WhiteBalanceFactors(red, green, blue);
146 }
147
149
156 inline void ApplyWhiteBalanceFactors(const Image &image, WhiteBalanceFactors factors)
157 {
158 if (!CVB_CALL_CAPI(ApplyWhiteBalance(image.Handle(), factors.Red(), factors.Green(), factors.Blue())))
159 Utilities::SystemInfo::ThrowLastError();
160 }
161
162 CVB_END_INLINE_NS
163
164} // namespace Cvb
Structure that represents an area of interest in the image.
Definition area_2d.hpp:21
The Common Vision Blox image.
Definition decl_image.hpp:45
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:232
void SetGreen(double green)
Sets the white balance factor for the green channel.
Definition white_balance.hpp:76
void ApplyWhiteBalanceFactors(const Image &image, WhiteBalanceFactors factors)
Applies the white balance factors to the given image.
Definition white_balance.hpp:156
double Green() const noexcept
Gets the white balance factor for the geen channel.
Definition white_balance.hpp:66
double Blue() const noexcept
Gets the white balance factor for the blue channel.
Definition white_balance.hpp:89
WhiteBalanceFactors CalculateWhiteBalanceFactors(const Image &image, Area2D aoi)
Calculate the red, green and blue gain factor for white balancing.
Definition white_balance.hpp:137
void SetRed(double red)
Sets the white balance factor for the red channel.
Definition white_balance.hpp:53
WhiteBalanceFactors(double red, double green, double blue)
Initialize a white balance factors structure.
Definition white_balance.hpp:31
void SetBlue(double blue)
Sets the white balance factor for the blue channel.
Definition white_balance.hpp:99
static WhiteBalanceFactors Identity() noexcept
Identity transformation leaving all values as they are.
Definition white_balance.hpp:112
double Red() const noexcept
Gets the white balance factor for the red channel.
Definition white_balance.hpp:43
cvbbool_t CalculateWhiteBalance(IMG Image, TArea Area, double &GainRed, double &GainGreen, double &GainBlue)
cvbbool_t ApplyWhiteBalance(IMG Image, double GainRed, double GainGreen, double GainBlue)
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
T quiet_NaN(T... args)