2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 * @file FUixVisionFaceDetector.h
21 * @brief This is the header file for the %FaceDetector class.
23 * This header file contains the declarations of the %FaceDetector class.
26 #ifndef _FUIX_VISION_FACE_DETECTOR_H_
27 #define _FUIX_VISION_FACE_DETECTOR_H_
29 #include <FBaseDataType.h>
30 #include <FBaseObject.h>
31 #include <FGrpBitmapCommon.h>
32 #include <FGrpPixelFormat.h>
33 #include <FUixVisionFaceTypes.h>
34 #include <FUixVisionFaceBuffer.h>
35 #include <FUixVisionFaceComponentsPosition.h>
37 namespace Tizen { namespace Base
42 namespace Tizen { namespace Base { namespace Collection
45 template<class Type> class IListT;
48 namespace Tizen { namespace Graphics
55 namespace Tizen { namespace Uix { namespace Vision
57 class _FaceDetectorImpl;
61 * @brief This class is used to trace faces in an image or a video.
65 * @remarks @b Header @b %file: @b \#include @b <FUix.h> @n
66 * @b Library : @b osp-face
68 * The %FaceDetector class provides the ability to automatically detect and trace faces in a still image or a video stream.
70 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/uix/face_detector_recognizer.htm">Face Detector and Recognizer</a>.
72 * The following example demonstrates how to use the %FaceDetector class.
77 * #include <FGraphics.h>
81 * using namespace Tizen::Base;
82 * using namespace Tizen::Media;
83 * using namespace Tizen::Graphics;
84 * using namespace Tizen::Io;
85 * using namespace Tizen::Uix::Vision;
88 * MyClass::TestFaceDetect(void)
90 * ByteBuffer* pByteBuffer = null;
91 * int width = 0, height = 0;
92 * result r = E_SUCCESS;
94 * Image* pImage = new Image();
95 * r = pImage->Construct();
97 * String path(L"test.bmp");
99 * pByteBuffer = pImage->DecodeToBufferN(path, BITMAP_PIXEL_FORMAT_RGB565,width,height );
101 * //Deletes the image object
107 * FaceDetector faceDetect;
108 * r = faceDetect.Construct();
109 * const Tizen::Base::Collection::IList* pFaceDetectList = faceDetect.DetectFacesFromStillImageN(*pByteBuffer, Dimension(width,height), BITMAP_PIXEL_FORMAT_RGB565);
111 * if(pFaceDetectList == null)
113 * delete pByteBuffer;
114 * return GetLastResult();
117 * for(int i=0; i < pFaceDetectList->GetCount(); i++)
119 * Tizen::Graphics::Rectangle* pRect = (Tizen::Graphics::Rectangle*)pFaceDetectList->GetAt(i);
122 * delete pFaceDetectList;
129 class _OSP_EXPORT_ FaceDetector
130 : public Tizen::Base::Object
136 * This is the default constructor for this class.
137 * The object is not fully constructed after this constructor is called.
138 * For full construction, the Construct() method must be called right after calling this constructor.
145 * This is the destructor for this class. @n
146 * The resources are deallocated by this method.
147 * This destructor overrides Tizen::Base::Object::~Object().
151 virtual ~FaceDetector(void);
157 * Initializes this instance of %FaceDetector.
161 * @return An error code
162 * @exception E_SUCCESS The method is successful.
163 * @exception E_OUT_OF_MEMORY The memory is insufficient.
165 result Construct(void);
168 * Gets the range and default value of the specified configuration property.
172 * @return An error code
173 * @param[in] configProperty The property to query
174 * @param[out] min The minimum value of the property
175 * @param[out] max The maximum value of the property
176 * @param[out] steppingDelta The step size for the property @n
177 * The step size is the smallest increment by which the property can be changed.
178 * @param[out] defaultVal The default value of the property
179 * @exception E_SUCCESS The method is successful.
180 * @exception E_UNSUPPORTED_OPERATION The device does not support this property.
182 result GetRange(FaceDetectorConfigProperty configProperty, long& min, long& max, long& steppingDelta, long& defaultVal) const;
185 * Sets the value of the specified property.
189 * @return An error code
190 * @param[in] configProperty The property to query
191 * @param[in] value The new value of the property
192 * @exception E_SUCCESS The method is successful.
193 * @exception E_UNSUPPORTED_OPERATION The device does not support this property.
194 * @exception E_OUT_OF_RANGE The specified @c value is out of range.
197 result SetProperty(FaceDetectorConfigProperty configProperty, long value);
200 * Gets the current setting of the specified configuration property.
204 * @return The value of the property, @n
205 * else @c -1 if an exception occurs
206 * @param[in] configProperty The property to query
207 * @exception E_SUCCESS The method is successful.
208 * @exception E_UNSUPPORTED_OPERATION The device does not support this property.
209 * @remarks The specific error code can be accessed using the GetLastResult() method.
211 long GetProperty(FaceDetectorConfigProperty configProperty) const;
214 * Gets a list of supported pixel formats.
218 * @return A list of the supported pixel formats that are used in the DetectFacesFromVideoStreamN() method @n
219 * The format is in the form of a string.
220 * @exception E_SUCCESS The method is successful.
221 * @exception E_OUT_OF_MEMORY The memory is insufficient.
222 * @remarks The specific error code can be accessed using the GetLastResult() method.
224 Tizen::Base::Collection::IListT <Tizen::Graphics::PixelFormat>* GetSupportedFormatListN(void) const;
227 * Searches for faces from a video.
231 * @return A list of the detected face positions @n
232 * Each list's item has a pointer of Tizen::Graphics::Rectangle value. @n
233 * An empty list, if there are no detected faces and there is no error. @n
234 * The faces are not detected when the faces are too small or the video data is not clear. @n
235 * This is the result of a normal operation, @n
236 * else @c null if an exception occurs.
237 * @param[in] byteBuffer The buffer containing the video data
238 * @param[in] dim The width and height of the video data @n
239 * Both the width and height must be greater than @c 0.
240 * @param[in] format The format of video data @n
241 * It must be one of the pixel formats extracted from GetSupportedFormatListN().
242 * @exception E_SUCCESS The method is successful.
243 * @exception E_INVALID_ARG A specified input parameter is invalid.
244 * @exception E_OUT_OF_MEMORY The memory is insufficient.
245 * @exception E_FAILURE A system error has occurred.
246 * @remarks The specific error code can be accessed using the GetLastResult() method.
248 Tizen::Base::Collection::IList* DetectFacesFromVideoStreamN(const Tizen::Base::ByteBuffer& byteBuffer, const Tizen::Graphics::Dimension& dim, const Tizen::Graphics::PixelFormat format);
252 * Detects faces from a still image.
254 * @brief <i> [Deprecated] </i>
255 * @deprecated This method is deprecated as it may return an improper result.
256 * Instead of using this method, use DetectFacesFromStillImageN(Tizen::Base::ByteBuffer &, Tizen::Graphics::Dimension &, Tizen::Graphics::BitmapPixelFormat).
257 * To optimize the memory usage and processing time, the bitmap scales down an image by decreasing its resolution in some models,
258 * that in turn decreases the accuracy of the face library. Therefore, the usage of this method using Tizen::Base::ByteBuffer is encouraged.
261 * @return A list of the detected face positions @n
262 * Each list's item has a pointer of Tizen::Graphics::Rectangle value. @n
263 * An empty list, if there are no detected faces and there is no error @n
264 * The faces are not detected when the faces are too small or the image is not clear. @n
265 * This is the result of a normal operation, @n
266 * else @c null if an exception occurs.
267 * @param[in] bitmap The bitmap file containing the input image data
268 * @exception E_SUCCESS The method is successful.
269 * @exception E_OUT_OF_MEMORY The memory is insufficient.
270 * @exception E_FAILURE A system error has occurred.
271 * @remarks The specific error code can be accessed using the GetLastResult() method.
272 * @remarks BitmapPixelFormat::BITMAP_PIXEL_FORMAT_R8G8B8A8 is not applicable for this method.
275 Tizen::Base::Collection::IList* DetectFacesFromStillImageN(const Tizen::Graphics::Bitmap& bitmap);
278 * Searches for faces from a still image.
282 * @return A list of the detected face positions @n
283 * Each list's item has a pointer of Tizen::Graphics::Rectangle value. @n
284 * An empty list, if there are no detected faces and there is no error @n
285 * The faces are not detected when the faces are too small or the image is not clear. @n
286 * This is the result of a normal operation, @n
287 * else @c null if an exception occurs.
288 * @param[in] byteBuffer The buffer containing the input image data
289 * @param[in] dim The width and height of the input image @n
290 * Both the width and height must be greater than @c 0.
291 * @param[in] format The color format defined by Tizen::Graphics::BitmapPixelFormat
292 * @exception E_SUCCESS The method is successful.
293 * @exception E_INVALID_ARG A specified input parameter is invalid.
294 * @exception E_OUT_OF_MEMORY The memory is insufficient.
295 * @exception E_FAILURE A system error has occurred.
296 * @remarks The specific error code can be accessed using the GetLastResult() method.
297 * @remarks BitmapPixelFormat::BITMAP_PIXEL_FORMAT_R8G8B8A8 is not applicable for this method.
299 Tizen::Base::Collection::IList* DetectFacesFromStillImageN(const Tizen::Base::ByteBuffer& byteBuffer, const Tizen::Graphics::Dimension& dim, Tizen::Graphics::BitmapPixelFormat format);
303 * Converts the input data to a proper data format that can be used in the face related methods.
307 * @return The preprocessed data, @n
308 * else @c null if an exception occurs
309 * @param[in] byteBuffer The buffer containing the input data
310 * @param[in] dim The width and height of the input data @n
311 * Both the width and height must be greater than @c 0.
312 * @param[in] format The format of the input data @n
313 * It must be one of the pixel formats extracted from GetSupportedFormatListN().
314 * @exception E_SUCCESS The method is successful.
315 * @exception E_INVALID_ARG A specified input parameter is invalid.
316 * @exception E_OUT_OF_MEMORY The memory is insufficient.
317 * @exception E_SYSTEM A system error has occurred.
318 * @remarks The specific error code can be accessed using the GetLastResult() method.
321 FaceBuffer* PreprocessDataN(const Tizen::Base::ByteBuffer& byteBuffer, const Tizen::Graphics::Dimension& dim, Tizen::Graphics::PixelFormat format);
324 * Searches for faces from the preprocessed data.
328 * @return A list of the detected face positions @n
329 * Each list's item has a pointer of Tizen::Graphics::Rectangle value. @n
330 * An empty list, if there are no detected faces and there is no error. @n
331 * The faces are not detected when the faces are too small or the input data is not clear. @n
332 * This is the result of a normal operation, @n
333 * else @c null if an exception occurs.
334 * @param[in] preprocessedFaceBuffer The preprocessed data @n
335 * The @c preprocessedFaceBuffer must be obtained from PreprocessDataN().
336 * @param[in] option The working option of detecting faces
337 * @exception E_SUCCESS The method is successful.
338 * @exception E_UNSUPPORTED_OPERATION The specified mode is not supported.
339 * @exception E_OUT_OF_MEMORY The memory is insufficient.
340 * @exception E_SYSTEM A system error has occurred.
341 * @remarks The specific error code can be accessed using the GetLastResult() method.
342 * @see FaceDetectorConfigProperty
344 Tizen::Base::Collection::IList* DetectFacesN(const FaceBuffer& preprocessedFaceBuffer, FaceDetectionOption option = FACE_DETECTION_OPTION_FAST);
347 * Extracts the facial components information.
351 * @return The facial components information, @n
352 * else @c null if an exception occurs
353 * @param[in] preprocessedFaceBuffer The preprocessed data @n
354 * The @c preprocessedFaceBuffer must be obtained from PreprocessDataN().
355 * @param[in] faceRect The position of the detected face that is from DetectFacesN() @n
356 * The value of x and y positions for the @c faceRect parameter must be greater than or equal to @c 0. @n
357 * The value of width and height for the @c faceRect parameter must be greater than @c 0. @n
358 * The position of @c faceRect must be within @c preprocessedFaceBuffer.
359 * @exception E_SUCCESS The method is successful.
360 * @exception E_INVALID_ARG A specified input parameter is invalid.
361 * @exception E_SYSTEM A system error has occurred.
362 * @exception E_OPERATION_FAILED The method has failed to extract the facial information, but there is no error reported. @n
363 * This happens when the detected faces are too small or the input data is not clear. This is the result of a normal operation.
364 * @remarks The specific error code can be accessed using the GetLastResult() method.
365 * @see FaceComponentsPosition
367 FaceComponentsPosition* ExtractFaceComponentsN(const FaceBuffer& preprocessedFaceBuffer, const Tizen::Graphics::Rectangle& faceRect);
371 * Gets the position difference of the face.
375 * @return An error code
376 * @param[in] prevData The buffer containing the previous video data
377 * @param[in] curData The buffer containing the current video data @n
378 * The size of @c prevData and @c curData must be the same. @n
379 * The @c prevData and @c curData must be gotten from PreprocessDataN().
380 * @param[in] prevFaceRect The region of the face inside @c prevData @n
381 * The value of x and y positions for the @c prevFaceRect parameter must be greater than or equal to @c 0. @n
382 * The value of width and height for the @c prevFaceRect parameter must be greater than @c 0. @n
383 * The specified @c prevFaceRect must be within @c prevData.
384 * @param[out] xDiff The x offset that is moved from the previous to current video data
385 * @param[out] yDiff The y offset that is moved from the previous to current video data
386 * @exception E_SUCCESS The method is successful.
387 * @exception E_INVALID_ARG A specified input parameter is invalid.
388 * @exception E_OPERATION_FAILED The method has failed to get the position difference of the specified region, but there is no error reported. @n
389 * In this case, @c xDiff and @c yDiff will be returned with @c 0. @n
390 * It can happen when the detected faces are too small or two video data are different even if they contain the same face.
391 * This is the result of a normal operation.
392 * @remarks The specific error code can be accessed using the GetLastResult() method.
393 * @remarks This can be used for tracking the face from a sequential video data.
394 * @see DetectFacesN()
396 result GetFaceMovement(const FaceBuffer& prevData, const FaceBuffer& curData, const Tizen::Graphics::Rectangle& prevFaceRect, int& xDiff, int& yDiff);
400 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
402 FaceDetector(const FaceDetector& value);
404 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
406 FaceDetector& operator =(const FaceDetector& value);
407 friend class _FaceDetectorImpl;
411 _FaceDetectorImpl* __pFaceDetectorImpl;
415 } } } // Tizen::Uix::Vision
417 #endif // _FUIX_VISION_FACE_DETECTOR_H_