Fixed typos.
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Vision / MediaVision / FaceDetectionConfiguration.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18
19 namespace Tizen.Multimedia
20 {
21     /// <summary>
22     /// Represents a configuration of <see cref="FaceDetector"/> instances.
23     /// </summary>
24     public class FaceDetectionConfiguration : EngineConfiguration
25     {
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";
33
34         /// <summary>
35         /// Initializes a new instance of the <see cref="FaceDetectionConfiguration"/> class.
36         /// </summary>
37         /// <exception cref="NotSupportedException">The feature is not supported.</exception>
38         public FaceDetectionConfiguration() : base("face_recognition")
39         {
40         }
41
42         /// <summary>
43         /// Gets or sets the face detection haarcascade xml file for face detection.
44         /// </summary>
45         /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
46         public string ModelFilePath
47         {
48             get
49             {
50                 return GetString(KeyModelFilePath);
51             }
52             set
53             {
54                 if (value == null)
55                 {
56                     throw new ArgumentNullException(nameof(ModelFilePath), "ModeFilePath can't be null.");
57                 }
58                 Set(KeyModelFilePath, value);
59             }
60         }
61
62
63         /// <summary>
64         /// Gets or sets minimum height of face which will be detected.
65         /// </summary>
66         /// <remarks>
67         /// Default value is null (all detected faces will be applied), can be changed to specify the minimum face height.
68         /// </remarks>
69         /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
70         public int? MinHeight
71         {
72             get
73             {
74                 int value = GetInt(KeyMinHeight);
75                 if (value == -1) return null;
76                 return value;
77             }
78             set
79             {
80                 if (value.HasValue && value < 0)
81                 {
82                     throw new ArgumentOutOfRangeException(nameof(MinHeight), value,
83                         $"{nameof(MinHeight)} can't be less than zero.");
84                 }
85
86                 Set(KeyMinHeight, value ?? -1);
87             }
88         }
89
90         /// <summary>
91         /// Gets or sets minimum width of face which will be detected.
92         /// </summary>
93         /// <remarks>
94         /// Default value is null (all detected faces will be applied), can be changed to specify the minimum face width.
95         /// </remarks>
96         /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
97         public int? MinWidth
98         {
99             get
100             {
101                 int value = GetInt(KeyMinWidth);
102                 if (value == -1) return null;
103                 return value;
104             }
105             set
106             {
107                 if (value.HasValue && value < 0)
108                 {
109                     throw new ArgumentOutOfRangeException(nameof(MinWidth), value,
110                         $"{nameof(MinWidth)} can't be less than zero.");
111                 }
112
113                 Set(KeyMinWidth, value ?? -1);
114             }
115         }
116
117         private static readonly Rectangle DefaultRoi = new Rectangle(-1, -1, -1, -1);
118
119         private Rectangle? _roi;
120
121         /// <summary>
122         /// Gets or sets the roi of the face detection.
123         /// </summary>
124         /// <remarks>
125         /// Default value is null (the roi will be a full image) can be changed to specify the roi for face detection.
126         /// </remarks>
127         /// <exception cref="ArgumentOutOfRangeException">
128         ///     The width of <paramref name="value"/> is less than or equal to zero.\n
129         ///     -or-\n
130         ///     The height of <paramref name="value"/> is less than or equal to zero.\n
131         ///     -or-\n
132         ///     The x position of <paramref name="value"/> is less than zero.\n
133         ///     -or-\n
134         ///     The y position of <paramref name="value"/> is less than zero.\n
135         /// </exception>
136         public Rectangle? Roi
137         {
138             get
139             {
140                 return _roi;
141             }
142             set
143             {
144                 if (value != null)
145                 {
146                     ValidateRoi(value.Value);
147                 }
148
149                 SetRoi(value ?? DefaultRoi);
150
151                 _roi = value;
152             }
153         }
154
155         private static void ValidateRoi(Rectangle roi)
156         {
157             if (roi.Width <= 0)
158             {
159                 throw new ArgumentOutOfRangeException("Roi.Width", roi.Width,
160                     "The width of roi can't be less than or equal to zero.");
161             }
162
163             if (roi.Height <= 0)
164             {
165                 throw new ArgumentOutOfRangeException("Roi.Height", roi.Height,
166                     "The height of roi can't be less than or equal to zero.");
167             }
168
169             if (roi.X < 0)
170             {
171                 throw new ArgumentOutOfRangeException("Roi.X", roi.X,
172                     "The x position of roi can't be less than zero.");
173             }
174
175             if (roi.Y < 0)
176             {
177                 throw new ArgumentOutOfRangeException("Roi.Y", roi.Y,
178                     "The y position of roi can't be less than zero.");
179             }
180         }
181
182         private void SetRoi(Rectangle roi)
183         {
184             Set(KeyRoiX, roi.X);
185             Set(KeyRoiY, roi.Y);
186             Set(KeyRoiWidth, roi.Width);
187             Set(KeyRoiHeight, roi.Height);
188         }
189     }
190 }