bbdcec2fc126fda2b26f7e8106bfeb21124edc8b
[platform/framework/native/vision.git] / inc / FUixVisionImageFeatureManager.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18
19 /**
20  * @file     FUixVisionImageFeatureManager.h
21  * @brief    This is the header file for the %ImageFeatureManager class.
22  *
23  * This header file contains the declarations of the %ImageFeatureManager class.
24  */
25
26 #ifndef _FUIX_VISION_IMAGE_FEATURE_MANAGER_H_
27 #define _FUIX_VISION_IMAGE_FEATURE_MANAGER_H_
28 #include <FBaseObject.h>
29 #include <FBase.h>
30 #include <FGrpBitmap.h>
31 #include <FUixVisionImageFeatureInfo.h>
32 #include <FMedia.h>
33
34 namespace Tizen { namespace Uix { namespace Vision
35 {
36
37 /**
38  * @class    ImageFeatureManager
39  * @brief    This class provides methods to generate individual feature data from an individual image data and collect to feature set file.
40  *
41  * @since    2.1
42  *
43  * The %ImageFeatureManager class provides methods to generate individual feature data from an individual image data. This class also provides methods to manage image feature set which is a collection of individual feature data.
44  *
45  * The following example demonstrates how to use the %ImageFeatureManager class.
46  *
47  * @code
48  * 
49  * #include <FBase.h>
50  * #include <FUix.h>
51  * #include <FGraphics.h>
52  * #include <FIo.h>
53  * #include <FMedia.h>
54  *
55  * using namespace Tizen::Base;
56  * using namespace Tizen::Media;
57  * using namespace Tizen::Graphics;
58  * using namespace Tizen::Io;
59  * using namespace Tizen::Uix::Vision;
60  *
61  * class MyClass
62  * {
63  *
64  * public:
65  *      MyClass();
66  *      ~MyClass();
67  *      result GenerateFeatureSet(void);
68  *      result AddImageFeatureSet(void);
69  * };
70  *
71  * result
72  * MyClass::GenerateFeatureSet(void)
73  * {
74  *     result r;
75  *     ImageFeatureManager imageFeatureManager;
76  *     r = imageFeatureManager.Construct();
77  *     //Creating new feature set
78  *     imageFeatureManager.AddFeature("/opt/usr/media/Images/image1.jpg");
79  *     imageFeatureManager.AddFeature("/opt/usr/media/Images/image2.jpg");
80  *     imageFeatureManager.AddFeature("/opt/usr/media/Images/image3.jpg");
81  *     r = imageFeatureManager.Flush(new String("/opt/usr/media/Images/testFeatureSet.xdb"));
82  *
83  *     return r;
84  * }
85  *
86  * result
87  * MyClass::AddImageFeatureSet()
88  * {
89  *     result r;
90  *     ImageFeatureManager imageFeatureManager;
91  *     imageFeatureManager.Construct();
92  *     imageFeatureManager.Load("/opt/usr/media/Images/testFeatureSet.xdb");
93  *     imageFeatureManager.AddFeature("/opt/usr/media/Images/image1.jpg");
94  *     imageFeatureManager.AddFeature("/opt/usr/media/Images/image2.jpg");
95  *     imageFeatureManager.AddFeature("/opt/usr/media/Images/image3.jpg");
96  *     r = imageFeatureManager.Flush();
97  *
98  *     return r;
99  * }
100  * @endcode
101  */
102 class _OSP_EXPORT_ ImageFeatureManager
103     : public Tizen::Base::Object
104 {
105 public:
106
107     /**
108      * This is the default constructor for this class. @n
109      * The object is not fully constructed after this constructor is called. @n
110      * For full construction, the Construct() method must be called right after calling this constructor.
111      *
112      * @since    2.1
113      */
114     ImageFeatureManager(void);
115
116     /**
117      * This is the destructor for this class. @n
118      * The resources are deallocated by this method.
119      * This destructor overrides Tizen::Base::Object::~Object().
120      *
121      * @since    2.1
122      */
123     ~ImageFeatureManager(void);
124
125     /**
126      * Initializes this instance of %ImageFeatureManager and create image feature set. @n
127      * Every application must call %Construct() before calling any other methods of %ImageFeatureManager.
128      *
129      * @since       2.1
130      *
131      * @feature     %http://tizen.org/feature/vision.image_recognition
132      *
133      * @return      An error code
134      *
135      * @exception   E_SUCCESS          The method is successful.
136      * @exception   E_UNSUPPORTED_OPERATION   The Emulator or target device does not support the required feature. 
137      * For more information, see <a href="../org.tizen.gettingstarted/html/tizen_overview/application_filtering.htm">Application Filtering</a>.
138      * @remarks     Before calling this method, check whether the feature is supported by %Tizen::System::SystemInfo::GetValue() methods.
139      */
140     result Construct(void);
141
142     /**
143      * Loads a feature set file.
144      *
145      * @since       2.1
146      *
147      * @return      An error code
148      *
149      * @param[in]   featureSetFilePath       The feature set file path
150      *
151      * @exception   E_SUCCESS                The method is successful.
152      * @exception   E_INVALID_ARG            The specified feature set file path is invalid.
153      * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
154      *
155      * @remarks     
156      *              - If a feature set file exists, it is updated.
157      *              - If a feature set file does not exist, it is newly created.
158      *              - It is not mandatory to call this method to create new feature set file, but Flush() must be called with valid feature set file path.
159      */
160     result Load(const Tizen::Base::String& featureSetFilePath);
161
162     /**
163      * Gets a list of supported image file formats for adding a feature.
164      *
165      * @since       2.1
166          *
167      * @return      A list of supported image file formats
168      */
169     static Tizen::Base::Collection::IListT<Tizen::Media::ImageFormat>* GetSupportedImageFileFormatsListN(void);
170
171     /**
172      * Adds a feature to a feature set.
173      *
174      * @since       2.1
175      *
176      * @return      A feature index of newly and successfully created feature, otherwise returns -1.
177      *
178      * @param[in]   imagePath            The input image file path
179      *
180      * @exception   E_INVALID_ARG        The specified input parameter is invalid.
181      *
182      * @remarks     
183      *              - The specific error code can be accessed using the GetLastResult() method.
184      *              - Input image file must be one of the supported image file formats.
185      *              - Calling this method actually means 'Mark As Add Feature'.
186      *              And the marked feature data will be added to a feature set file after calling Flush().
187      * @see         GetSupportedImageFileFormatsListN()
188      *              Flush(const Tizen::Base::String*)
189      */
190     int AddFeature(const Tizen::Base::String& imagePath);
191
192     /**
193      * Adds a feature to a feature set.
194      *
195      * @since       2.1
196      *
197      * @return      A feature index of newly and successfully created feature, otherwise returns -1.
198      *
199      * @param[in]   imageBuffer              The image buffer of grayscale image data of specified width and height
200      * @param[in]   width                    The width of the input image
201      * @param[in]   height                   The height of the input image
202      * @param[in]   description              The description of the feature
203      *
204      * @exception   E_INVALID_ARG            A specified input parameter is invalid.
205      *
206      * @remarks     
207      *              - The specific error code can be accessed using the GetLastResult() method.
208      *              - Calling this method actually means 'Mark As Add Feature'.
209      *              And the marked feature data will be added to a feature set file after calling Flush().
210      * @see         Flush(const Tizen::Base::String*)
211      */
212     int AddFeature(const Tizen::Base::ByteBuffer& imageBuffer, int width, int height, const Tizen::Base::String& description);
213
214     /**
215      * Gets the total number of features in a feature set.
216      *
217      * @since       2.1
218      *
219      * @return      The total number of features in a feature set
220      */
221     int GetTotalNumberOfFeatures(void);
222
223     /**
224      * Deletes a feature with a specified index in a feature set.
225      *
226      * @since       2.1
227      *
228      * @return      An error code
229      *
230      * @param[in]   featureIndex             The feature index in a feature set
231      *
232      * @exception   E_SUCCESS                The method is successful.
233      * @exception   E_INVALID_ARG            The specified input parameter is invalid.
234      * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
235      *
236      * @remarks     Calling this method actually means 'Mark As Delete Feature'.
237      *              And the marked feature data is deleted after calling Flush().
238      * @see         Flush(const Tizen::Base::String*)
239      */
240     result DeleteFeature(int featureIndex);
241
242     /**
243      * Deletes all features in a feature set.
244      *
245      * @since       2.1
246      *
247      * @return      An error code
248      *
249      * @exception   E_SUCCESS          The method is successful.
250      * @exception   E_OUT_OF_MEMORY    The memory is insufficient.
251      *
252      * @remarks     Calling this method actually means 'Mark As Delete All Features'.
253      *              And all feature data is deleted after calling Flush().
254      * @see         Flush(const Tizen::Base::String*)
255      */
256     result DeleteAllFeatures(void);
257
258     /**
259      * Flushes features into a feature set file and updates all changes as marked.
260      *
261      *
262      * @since       2.1
263      *
264      * @return      An error code
265      *
266      * @param[in]   featureSetFilePath   The feature set file path
267      * @exception   E_SUCCESS            The method is successful.
268      * @exception   E_INVALID_ARG        The specified feature set path is invalid.
269      *
270      * @remarks     
271      *              - All changes in the feature set file by AddFeature() or DeleteFeature() or DeleteAllFeatures() are updated by calling this method.
272      *              - If @c featureSetFilePath is not decided or is same as the file path used in Load(), the loaded feature set file is updated.
273      *              - If @c featureSetFilePath is not same as the file path used in %Load(), the loaded feature set file remains as is and new feature set file is created.
274      *              - If @c featureSetFilePath is @c null, the feature set file loaded by %Load() is overwritten.
275      *                          - If @c featureSetFilePath is not decided or is same to file path used in %Load() and the loaded feature set file is read-only @c E_INVALID_ARG exception will be  returned.
276      *                          - If %Load() is not called to create new feature set file, this method must be called with valid @c featureSetFilePath.
277      *
278      */
279     result Flush(const Tizen::Base::String* featureSetFilePath = null);
280
281     /**
282      * Gets information of the individual feature.
283      *
284      * @since       2.1
285      *
286      * @return      A pointer to ImageFeatureInfo
287      *
288      * @param[in]   featureIndex       The feature index in a feature set
289      */
290     const Tizen::Uix::Vision::ImageFeatureInfo* GetImageFeatureInfo(int featureIndex) const;
291
292
293 private:
294     /**
295      * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
296      */
297     ImageFeatureManager(const ImageFeatureManager&);
298
299     /**
300      * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
301      */
302     ImageFeatureManager& operator=(const ImageFeatureManager&);
303
304 private:
305     class _ImageFeatureManagerImpl* __pImageFeatureManagerImpl;
306     friend class _ImageFeatureManagerImpl;
307   };
308
309 } } } //Tizen::Uix::Vision
310
311 #endif // _FUIX_VISION_IMAGE_FEATURE_MANAGER_H_