/
SimpleWB.cs
199 lines (182 loc) · 5.1 KB
/
SimpleWB.cs
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
using OpenCvSharp.Internal;
// ReSharper disable InconsistentNaming
namespace OpenCvSharp.XPhoto;
/// <summary>
/// A simple white balance algorithm that works by independently stretching each of the input image channels to the specified range. For increased robustness it ignores the top and bottom p% of pixel values.
/// </summary>
public class SimpleWB : WhiteBalancer
{
private Ptr? ptrObj;
/// <summary>
/// Constructor
/// </summary>
internal SimpleWB(IntPtr p)
{
ptrObj = new Ptr(p);
ptr = ptrObj.Get();
}
/// <summary>
/// Creates an instance of SimpleWB
/// </summary>
/// <returns></returns>
public static SimpleWB Create()
{
NativeMethods.HandleException(
NativeMethods.xphoto_createSimpleWB(out var ptr));
return new SimpleWB(ptr);
}
/// <summary>
/// Releases managed resources
/// </summary>
protected override void DisposeManaged()
{
ptrObj?.Dispose();
ptrObj = null;
base.DisposeManaged();
}
/// <summary>
/// Input image range maximum value.
/// </summary>
public float InputMax
{
get
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.xphoto_SimpleWB_InputMax_get(ptr, out var ret));
GC.KeepAlive(this);
return ret;
}
set
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.xphoto_SimpleWB_InputMax_set(ptr, value));
GC.KeepAlive(this);
}
}
/// <summary>
/// Input image range minimum value.
/// </summary>
public float InputMin
{
get
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.xphoto_SimpleWB_InputMin_get(ptr, out var ret));
GC.KeepAlive(this);
return ret;
}
set
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.xphoto_SimpleWB_InputMin_set(ptr, value));
GC.KeepAlive(this);
}
}
/// <summary>
/// Output image range maximum value.
/// </summary>
public float OutputMax
{
get
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.xphoto_SimpleWB_OutputMax_get(ptr, out var ret));
GC.KeepAlive(this);
return ret;
}
set
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.xphoto_SimpleWB_OutputMax_set(ptr, value));
GC.KeepAlive(this);
}
}
/// <summary>
/// Output image range minimum value.
/// </summary>
public float OutputMin
{
get
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.xphoto_SimpleWB_OutputMin_get(ptr, out var ret));
GC.KeepAlive(this);
return ret;
}
set
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.xphoto_SimpleWB_OutputMin_set(ptr, value));
GC.KeepAlive(this);
}
}
/// <summary>
/// Percent of top/bottom values to ignore.
/// </summary>
public float P
{
get
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.xphoto_SimpleWB_P_get(ptr, out var ret));
GC.KeepAlive(this);
return ret;
}
set
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.xphoto_SimpleWB_P_set(ptr, value));
GC.KeepAlive(this);
}
}
/// <summary>
/// Applies white balancing to the input image.
/// </summary>
/// <param name="src">Input image</param>
/// <param name="dst">White balancing result</param>
public override void BalanceWhite(InputArray src, OutputArray dst)
{
if (src is null)
throw new ArgumentNullException(nameof(src));
if (dst is null)
throw new ArgumentNullException(nameof(dst));
src.ThrowIfDisposed();
dst.ThrowIfNotReady();
NativeMethods.HandleException(
NativeMethods.xphoto_SimpleWB_balanceWhite(ptr, src.CvPtr, dst.CvPtr));
GC.KeepAlive(this);
GC.KeepAlive(src);
GC.KeepAlive(dst);
dst.Fix();
}
internal class Ptr : OpenCvSharp.Ptr
{
public Ptr(IntPtr ptr)
: base(ptr)
{
}
public override IntPtr Get()
{
NativeMethods.HandleException(
NativeMethods.xphoto_Ptr_SimpleWB_get(ptr, out var ret));
GC.KeepAlive(this);
return ret;
}
protected override void DisposeUnmanaged()
{
NativeMethods.HandleException(
NativeMethods.xphoto_Ptr_SimpleWB_delete(ptr));
base.DisposeUnmanaged();
}
}
}