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 public class FaceDetectionConfiguration : EngineConfiguration
26 private const string KeyModelFilePath = "MV_FACE_DETECTION_MODEL_FILE_PATH";
27 private const string KeyRoiX = "MV_FACE_DETECTION_ROI_X";
28 private const string KeyRoiY = "MV_FACE_DETECTION_ROI_Y";
29 private const string KeyRoiWidth = "MV_FACE_DETECTION_ROI_WIDTH";
30 private const string KeyRoiHeight = "MV_FACE_DETECTION_ROI_HEIGHT";
31 private const string KeyMinWidth = "MV_FACE_DETECTION_MIN_SIZE_WIDTH";
32 private const string KeyMinHeight = "MV_FACE_DETECTION_MIN_SIZE_HEIGHT";
35 /// Initializes a new instance of the <see cref="FaceDetectionConfiguration"/> class.
37 /// <exception cref="NotSupportedException">The feature is not supported.</exception>
38 public FaceDetectionConfiguration() : base("face_recognition")
43 /// Gets or sets the face detection haarcascade xml file for face detection.
45 /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
46 public string ModelFilePath
50 return GetString(KeyModelFilePath);
56 throw new ArgumentNullException(nameof(ModelFilePath), "ModeFilePath can't be null.");
58 Set(KeyModelFilePath, value);
64 /// Gets or sets minimum height of face which will be detected.
67 /// Default value is null (all detected faces will be applied), can be changed to specify the minimum face height.
69 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
74 int value = GetInt(KeyMinHeight);
75 if (value == -1) return null;
80 if (value.HasValue && value < 0)
82 throw new ArgumentOutOfRangeException(nameof(MinHeight), value,
83 $"{nameof(MinHeight)} can't be less than zero.");
86 Set(KeyMinHeight, value ?? -1);
91 /// Gets or sets minimum width of face which will be detected.
94 /// Default value is null (all detected faces will be applied), can be changed to specify the minimum face width.
96 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
101 int value = GetInt(KeyMinWidth);
102 if (value == -1) return null;
107 if (value.HasValue && value < 0)
109 throw new ArgumentOutOfRangeException(nameof(MinWidth), value,
110 $"{nameof(MinWidth)} can't be less than zero.");
113 Set(KeyMinWidth, value ?? -1);
117 private static readonly Rectangle DefaultRoi = new Rectangle(-1, -1, -1, -1);
119 private Rectangle? _roi;
122 /// Gets or sets the roi of the face detection.
125 /// Default value is null (the roi will be a full image) can be changed to specify the roi for face detection.
127 /// <exception cref="ArgumentOutOfRangeException">
128 /// The width of <paramref name="value"/> is less than or equal to zero.\n
130 /// The height of <paramref name="value"/> is less than or equal to zero.\n
132 /// The x position of <paramref name="value"/> is less than zero.\n
134 /// The y position of <paramref name="value"/> is less than zero.\n
136 public Rectangle? Roi
146 ValidateRoi(value.Value);
149 SetRoi(value ?? DefaultRoi);
155 private static void ValidateRoi(Rectangle roi)
159 throw new ArgumentOutOfRangeException("Roi.Width", roi.Width,
160 "The width of roi can't be less than or equal to zero.");
165 throw new ArgumentOutOfRangeException("Roi.Height", roi.Height,
166 "The height of roi can't be less than or equal to zero.");
171 throw new ArgumentOutOfRangeException("Roi.X", roi.X,
172 "The x position of roi can't be less than zero.");
177 throw new ArgumentOutOfRangeException("Roi.Y", roi.Y,
178 "The y position of roi can't be less than zero.");
182 private void SetRoi(Rectangle roi)
186 Set(KeyRoiWidth, roi.Width);
187 Set(KeyRoiHeight, roi.Height);