CVB++ 14.0
white_balance.hpp
1#pragma once
2
3#include "global.hpp"
4
5#include "image.hpp"
6
7namespace Cvb
8{
9
10CVB_BEGIN_INLINE_NS
11
12
13
15
24{
25 public:
26
28
34 WhiteBalanceFactors(double red, double green, double blue)
35 {
36 SetRed(red);
37 SetGreen(green);
38 SetBlue(blue);
39 }
40
42
46 double Red() const noexcept
47 {
48 return static_cast<double>(red_) / ConversionFactor;
49 }
50
52
56 void SetRed(double red)
57 {
58 if ((red < 0.0) || (red > MaxFactor))
59 throw std::invalid_argument("argument out of range for red factor");
60
61 red_ = static_cast<int>(red * ConversionFactor);
62 }
63
65
69 double Green() const noexcept
70 {
71 return static_cast<double>(green_) / ConversionFactor;
72 }
73
75
79 void SetGreen(double green)
80 {
81 if ((green < 0.0) || (green > MaxFactor))
82 throw std::invalid_argument("argument out of range for green factor");
83
84 green_ = static_cast<int>(green *ConversionFactor);
85 }
86
88
92 double Blue() const noexcept
93 {
94 return static_cast<double>(blue_) / ConversionFactor;
95 }
96
97
99
103 void SetBlue(double blue)
104 {
105 if ((blue < 0.0) || (blue > MaxFactor))
106 throw std::invalid_argument("argument out of range for blue factor");
107
108 blue_ = static_cast<int>(blue * ConversionFactor);
109 }
110
112
117 {
118 return WhiteBalanceFactors(1.0, 1.0, 1.0);
119 }
120
121 private:
122
123 int red_ = 1;
124 int green_ = 1;
125 int blue_ = 1;
126
127 static constexpr double MaxFactor = 16.0;
128 static constexpr double ConversionFactor = 256.0;
129
130};
131
132
134
145{
146 double red, green, blue;
147 if (!CVB_CALL_CAPI(CalculateWhiteBalance(image.Handle(),
148 *reinterpret_cast<CExports::TArea*>(&aoi),
149 red,
150 green,
151 blue)))
152 Utilities::SystemInfo::ThrowLastError();
153
154 return WhiteBalanceFactors(red, green, blue);
155}
156
157
159
166inline void ApplyWhiteBalanceFactors(const Image & image, WhiteBalanceFactors factors)
167{
168 if (!CVB_CALL_CAPI(ApplyWhiteBalance(image.Handle(), factors.Red(), factors.Green(), factors.Blue())))
169 Utilities::SystemInfo::ThrowLastError();
170}
171
172
173
174CVB_END_INLINE_NS
175
176}
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
Factors for white balance correction.
Definition: white_balance.hpp:24
void SetGreen(double green)
Sets the white balance factor for the green channel.
Definition: white_balance.hpp:79
void ApplyWhiteBalanceFactors(const Image &image, WhiteBalanceFactors factors)
Applies the white balance factors to the given image.
Definition: white_balance.hpp:166
double Green() const noexcept
Gets the white balance factor for the geen channel.
Definition: white_balance.hpp:69
double Blue() const noexcept
Gets the white balance factor for the blue channel.
Definition: white_balance.hpp:92
WhiteBalanceFactors CalculateWhiteBalanceFactors(const Image &image, Area2D aoi)
Calculate the red, green and blue gain factor for white balancing.
Definition: white_balance.hpp:144
void SetRed(double red)
Sets the white balance factor for the red channel.
Definition: white_balance.hpp:56
WhiteBalanceFactors(double red, double green, double blue)
Initialize a white balance factors structure.
Definition: white_balance.hpp:34
void SetBlue(double blue)
Sets the white balance factor for the blue channel.
Definition: white_balance.hpp:103
static WhiteBalanceFactors Identity() noexcept
Identity transformation leaving all values as they are.
Definition: white_balance.hpp:116
double Red() const noexcept
Gets the white balance factor for the red channel.
Definition: white_balance.hpp:46
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24