sync with master
[framework/osp/vision.git] / src / FUixVisionImageRecognizer.cpp
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 #include <FUixVisionImageRecognizer.h>
19 #include "FUixVision_ImageRecognizerImpl.h"
20 #include <cstring>
21 #include <FText.h>
22 #include <FBaseSysLog.h>
23
24 namespace Tizen { namespace Uix { namespace Vision
25 {
26
27 ImageRecognizer::ImageRecognizer(void)
28     : __pImageRecognizerImpl(0)
29 {
30 }
31
32 ImageRecognizer::~ImageRecognizer(void)
33 {
34     delete __pImageRecognizerImpl;
35 }
36
37 result
38 ImageRecognizer::Construct(void)
39 {
40     SysAssertf(__pImageRecognizerImpl == null, "Already constructed! ",
41             "Calling Construct() twice or more on a same instance is not allowed for this class.");
42
43     __pImageRecognizerImpl = new (std::nothrow) _ImageRecognizerImpl;
44     SysTryReturnResult(NID_UIX, __pImageRecognizerImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
45     return E_SUCCESS;
46 }
47
48 void
49 ImageRecognizer::SetMultiTrackingEnabled(bool enable)
50 {
51     SysAssertf(__pImageRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
52     __pImageRecognizerImpl->SetMultiTracking(enable);
53 }
54
55 result
56 ImageRecognizer::SetImageSize(int width, int height)
57 {
58     SysAssertf(__pImageRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
59
60     SysTryReturnResult(NID_UIX, width > 0 && height > 0, E_INVALID_ARG,
61             "Width and height must me more than 0. [E_INVALID_ARG]");
62
63     return __pImageRecognizerImpl->SetImageSize(width, height) ? E_SUCCESS : E_FAILURE;
64 }
65
66 result
67 ImageRecognizer::SetFeatureManager(ImageFeatureManager& imageFeatureManager)
68 {
69     SysAssertf(__pImageRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
70
71     return __pImageRecognizerImpl->SetImageDatabase(&imageFeatureManager) ? E_SUCCESS : E_FAILURE;
72 }
73
74 int
75 ImageRecognizer::GetRecognizedObjectCount(void)
76 {
77     SysAssertf(__pImageRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
78     __pImageRecognizerImpl->FillObjectStorage();
79     return __pImageRecognizerImpl->GetRecognizedObjectsCount();
80 }
81
82 const ImageObject*
83 ImageRecognizer::GetRecognizedObject(int index) const
84 {
85     SysAssertf(__pImageRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
86     return __pImageRecognizerImpl->GetRecognizedObject(index);
87 }
88
89 result
90 ImageRecognizer::ProcessImage(const Tizen::Base::ByteBuffer& imageBuffer)
91 {
92     SysAssertf(__pImageRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
93
94     SysTryReturn(NID_UIX, imageBuffer.GetPointer(), -1, E_INVALID_ARG,
95             "imageBuffer must not be null. [E_INVALID_ARG]");
96
97     return __pImageRecognizerImpl->ProcessImage((unsigned char*) imageBuffer.GetPointer()) != -1 ? E_SUCCESS : E_FAILURE;
98 }
99
100 } } } //Tizen::Uix::Vision