2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.Multimedia
22 /// Represents a configuration of <see cref="FaceDetector"/> instances.
24 /// <since_tizen> 3</since_tizen>
25 public class FaceDetectionConfiguration : EngineConfiguration
27 private const string KeyModelFilePath = "MV_FACE_DETECTION_MODEL_FILE_PATH";
28 private const string KeyRoiX = "MV_FACE_DETECTION_ROI_X";
29 private const string KeyRoiY = "MV_FACE_DETECTION_ROI_Y";
30 private const string KeyRoiWidth = "MV_FACE_DETECTION_ROI_WIDTH";
31 private const string KeyRoiHeight = "MV_FACE_DETECTION_ROI_HEIGHT";
32 private const string KeyMinWidth = "MV_FACE_DETECTION_MIN_SIZE_WIDTH";
33 private const string KeyMinHeight = "MV_FACE_DETECTION_MIN_SIZE_HEIGHT";
36 /// Initializes a new instance of the <see cref="FaceDetectionConfiguration"/> class.
38 /// <exception cref="NotSupportedException">The feature is not supported.</exception>
39 /// <since_tizen> 3</since_tizen>
40 public FaceDetectionConfiguration() : base("face_recognition")
45 /// Gets or sets the face detection haarcascade xml file for face detection.
47 /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
48 /// <since_tizen> 3</since_tizen>
49 public string ModelFilePath
53 return GetString(KeyModelFilePath);
59 throw new ArgumentNullException(nameof(ModelFilePath), "ModeFilePath can't be null.");
61 Set(KeyModelFilePath, value);
67 /// Gets or sets minimum height of face which will be detected.
70 /// Default value is null (all detected faces will be applied), can be changed to specify the minimum face height.
72 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
73 /// <since_tizen> 3</since_tizen>
78 int value = GetInt(KeyMinHeight);
79 if (value == -1) return null;
84 if (value.HasValue && value < 0)
86 throw new ArgumentOutOfRangeException(nameof(MinHeight), value,
87 $"{nameof(MinHeight)} can't be less than zero.");
90 Set(KeyMinHeight, value ?? -1);
95 /// Gets or sets minimum width of face which will be detected.
98 /// Default value is null (all detected faces will be applied), can be changed to specify the minimum face width.
100 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
101 /// <since_tizen> 3</since_tizen>
106 int value = GetInt(KeyMinWidth);
107 if (value == -1) return null;
112 if (value.HasValue && value < 0)
114 throw new ArgumentOutOfRangeException(nameof(MinWidth), value,
115 $"{nameof(MinWidth)} can't be less than zero.");
118 Set(KeyMinWidth, value ?? -1);
122 private static readonly Rectangle DefaultRoi = new Rectangle(-1, -1, -1, -1);
124 private Rectangle? _roi;
127 /// Gets or sets the roi of the face detection.
130 /// Default value is null (the roi will be a full image) can be changed to specify the roi for face detection.
132 /// <exception cref="ArgumentOutOfRangeException">
133 /// The width of <paramref name="value"/> is less than or equal to zero.\n
135 /// The height of <paramref name="value"/> is less than or equal to zero.\n
137 /// The x position of <paramref name="value"/> is less than zero.\n
139 /// The y position of <paramref name="value"/> is less than zero.\n
141 /// <since_tizen> 3</since_tizen>
142 public Rectangle? Roi
152 ValidateRoi(value.Value);
155 SetRoi(value ?? DefaultRoi);
161 private static void ValidateRoi(Rectangle roi)
165 throw new ArgumentOutOfRangeException("Roi.Width", roi.Width,
166 "The width of roi can't be less than or equal to zero.");
171 throw new ArgumentOutOfRangeException("Roi.Height", roi.Height,
172 "The height of roi can't be less than or equal to zero.");
177 throw new ArgumentOutOfRangeException("Roi.X", roi.X,
178 "The x position of roi can't be less than zero.");
183 throw new ArgumentOutOfRangeException("Roi.Y", roi.Y,
184 "The y position of roi can't be less than zero.");
188 private void SetRoi(Rectangle roi)
192 Set(KeyRoiWidth, roi.Width);
193 Set(KeyRoiHeight, roi.Height);