/
FaceDetectionConfiguration.cs
executable file
·197 lines (178 loc) · 6.85 KB
/
FaceDetectionConfiguration.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
/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
namespace Tizen.Multimedia.Vision
{
/// <summary>
/// Represents a configuration of <see cref="FaceDetector"/> instances.
/// </summary>
/// <feature>http://tizen.org/feature/vision.face_recognition</feature>
/// <since_tizen> 4 </since_tizen>
public class FaceDetectionConfiguration : EngineConfiguration
{
private const string KeyModelFilePath = "MV_FACE_DETECTION_MODEL_FILE_PATH";
private const string KeyRoiX = "MV_FACE_DETECTION_ROI_X";
private const string KeyRoiY = "MV_FACE_DETECTION_ROI_Y";
private const string KeyRoiWidth = "MV_FACE_DETECTION_ROI_WIDTH";
private const string KeyRoiHeight = "MV_FACE_DETECTION_ROI_HEIGHT";
private const string KeyMinWidth = "MV_FACE_DETECTION_MIN_SIZE_WIDTH";
private const string KeyMinHeight = "MV_FACE_DETECTION_MIN_SIZE_HEIGHT";
/// <summary>
/// Initializes a new instance of the <see cref="FaceDetectionConfiguration"/> class.
/// </summary>
/// <exception cref="NotSupportedException">The feature is not supported.</exception>
/// <since_tizen> 4</since_tizen>
public FaceDetectionConfiguration() : base("face_recognition")
{
}
/// <summary>
/// Gets or sets the face detection haarcascade xml file for face detection.
/// </summary>
/// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
/// <since_tizen> 4 </since_tizen>
public string ModelFilePath
{
get
{
return GetString(KeyModelFilePath);
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(ModelFilePath), "ModeFilePath can't be null.");
}
Set(KeyModelFilePath, value);
}
}
/// <summary>
/// Gets or sets the minimum height of a face which will be detected.
/// </summary>
/// <remarks>
/// Default value is null (all detected faces will be applied), which can be changed to specify the minimum face height.
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
/// <since_tizen> 4 </since_tizen>
public int? MinHeight
{
get
{
int value = GetInt(KeyMinHeight);
if (value == -1) return null;
return value;
}
set
{
if (value.HasValue && value < 0)
{
throw new ArgumentOutOfRangeException(nameof(MinHeight), value,
$"{nameof(MinHeight)} can't be less than zero.");
}
Set(KeyMinHeight, value ?? -1);
}
}
/// <summary>
/// Gets or sets the minimum width of a face which will be detected.
/// </summary>
/// <remarks>
/// Default value is null (all detected faces will be applied), which can be changed to specify the minimum face width.
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
/// <since_tizen> 4 </since_tizen>
public int? MinWidth
{
get
{
int value = GetInt(KeyMinWidth);
if (value == -1) return null;
return value;
}
set
{
if (value.HasValue && value < 0)
{
throw new ArgumentOutOfRangeException(nameof(MinWidth), value,
$"{nameof(MinWidth)} can't be less than zero.");
}
Set(KeyMinWidth, value ?? -1);
}
}
private static readonly Rectangle DefaultRoi = new Rectangle(-1, -1, -1, -1);
private Rectangle? _roi;
/// <summary>
/// Gets or sets the roi of the face detection.
/// </summary>
/// <remarks>
/// Default value is null (the roi will be a full image), which can be changed to specify the roi for face detection.
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException">
/// The width of <paramref name="value"/> is less than or equal to zero.<br/>
/// -or-<br/>
/// The height of <paramref name="value"/> is less than or equal to zero.<br/>
/// -or-<br/>
/// The x position of <paramref name="value"/> is less than zero.<br/>
/// -or-<br/>
/// The y position of <paramref name="value"/> is less than zero.
/// </exception>
/// <since_tizen> 4 </since_tizen>
public Rectangle? Roi
{
get
{
return _roi;
}
set
{
if (value != null)
{
ValidateRoi(value.Value);
}
SetRoi(value ?? DefaultRoi);
_roi = value;
}
}
private static void ValidateRoi(Rectangle roi)
{
if (roi.Width <= 0)
{
throw new ArgumentOutOfRangeException("Roi.Width", roi.Width,
"The width of roi can't be less than or equal to zero.");
}
if (roi.Height <= 0)
{
throw new ArgumentOutOfRangeException("Roi.Height", roi.Height,
"The height of roi can't be less than or equal to zero.");
}
if (roi.X < 0)
{
throw new ArgumentOutOfRangeException("Roi.X", roi.X,
"The x position of roi can't be less than zero.");
}
if (roi.Y < 0)
{
throw new ArgumentOutOfRangeException("Roi.Y", roi.Y,
"The y position of roi can't be less than zero.");
}
}
private void SetRoi(Rectangle roi)
{
Set(KeyRoiX, roi.X);
Set(KeyRoiY, roi.Y);
Set(KeyRoiWidth, roi.Width);
Set(KeyRoiHeight, roi.Height);
}
}
}