/
GrayworldWB.cs
112 lines (98 loc) · 2.84 KB
/
GrayworldWB.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
using OpenCvSharp.Internal;
// ReSharper disable IdentifierTypo
// ReSharper disable InconsistentNaming
// ReSharper disable CommentTypo
namespace OpenCvSharp.XPhoto;
/// <summary>
/// Gray-world white balance algorithm.
/// </summary>
public class GrayworldWB : WhiteBalancer
{
private Ptr? ptrObj;
/// <summary>
/// Constructor
/// </summary>
internal GrayworldWB(IntPtr p)
{
ptrObj = new Ptr(p);
ptr = ptrObj.Get();
}
/// <summary>
/// Creates an instance of GrayworldWB
/// </summary>
/// <returns></returns>
public static GrayworldWB Create()
{
NativeMethods.HandleException(
NativeMethods.xphoto_createGrayworldWB(out var ptr));
return new GrayworldWB(ptr);
}
/// <inheritdoc />
protected override void DisposeManaged()
{
ptrObj?.Dispose();
ptrObj = null;
base.DisposeManaged();
}
/// <summary>
/// Maximum saturation for a pixel to be included in the gray-world assumption.
/// </summary>
public float SaturationThreshold
{
get
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.xphoto_GrayworldWB_SaturationThreshold_get(ptr, out var ret));
GC.KeepAlive(this);
return ret;
}
set
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.xphoto_GrayworldWB_SaturationThreshold_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_GrayworldWB_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_GrayworldWB_get(ptr, out var ret));
GC.KeepAlive(this);
return ret;
}
protected override void DisposeUnmanaged()
{
NativeMethods.HandleException(
NativeMethods.xphoto_Ptr_GrayworldWB_delete(ptr));
base.DisposeUnmanaged();
}
}
}