drop SingleoOutputData class
authorInki Dae <inki.dae@samsung.com>
Fri, 5 Apr 2024 09:06:23 +0000 (18:06 +0900)
committerInki Dae <inki.dae@samsung.com>
Fri, 5 Apr 2024 09:08:50 +0000 (18:08 +0900)
Drop SingleoOuputData and its child classes, and use BaseResultType
and its child structures instead.

Signed-off-by: Inki Dae <inki.dae@samsung.com>
15 files changed:
common/include/SingleoCommonTypes.h
inference/backends/mediavision/include/MvFaceDetection.h
inference/backends/mediavision/include/MvFdOutputData.h [deleted file]
inference/backends/mediavision/include/MvObjectDetection.h
inference/backends/mediavision/include/MvOdOutputData.h [deleted file]
inference/backends/mediavision/src/MvFaceDetection.cpp
inference/backends/mediavision/src/MvObjectDetection.cpp
inference/include/IInferenceServiceInterface.h
inference/include/IInferenceTaskInterface.h
inference/include/InferenceServiceDefault.h
inference/include/InferenceServiceExternal.h
inference/include/SingleoOutputData.h [deleted file]
inference/src/InferenceServiceDefault.cpp
inference/src/InferenceServiceExternal.cpp
services/auto_zoom/src/AutoZoom.cpp

index a125c986af42482d30a193a40923297a07081e3f..6ee4b52476ff3fa7a0367e999b1e73cbb38ef939 100644 (file)
@@ -76,14 +76,16 @@ struct BaseResultType {
 struct OdResultType : public BaseResultType {
        OdResultType() : BaseResultType(ResultType::OBJECT_DETECTION)
        {}
-       Rect rect;
+       unsigned int _frame_number {};
+       std::vector<Rect> rects;
        // TODO
 };
 
 struct FdResultType : public BaseResultType {
        FdResultType() : BaseResultType(ResultType::FACE_DETECTION)
        {}
-       Rect rect;
+       unsigned int _frame_number {};
+       std::vector<Rect> rects;
        // TODO
 };
 
index 21375629539279ed9a8b5312480a243dc0d81e67..fe463f78f2c0999dd2d102058e51856e8c9510e9 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "IInferenceTaskInterface.h"
 #include "mv_face_detection_internal.h"
-#include "MvFdOutputData.h"
+#include "SingleoCommonTypes.h"
 
 namespace singleo
 {
@@ -31,7 +31,7 @@ class MvFaceDetection : public IInferenceTaskInterface
 {
 private:
        mv_face_detection_h _handle {};
-       MvFdOutputData _output_data {};
+       FdResultType _output_data {};
 
 public:
        MvFaceDetection();
@@ -40,7 +40,7 @@ public:
        void configure() override;
        void prepare() override;
        void invoke(BaseDataType &input, bool async) override;
-       const SingleoOutputData &result() override;
+       BaseResultType &result() override;
 };
 
 } // backends
diff --git a/inference/backends/mediavision/include/MvFdOutputData.h b/inference/backends/mediavision/include/MvFdOutputData.h
deleted file mode 100644 (file)
index 66d894e..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __MV_FD_OUTPUT_DATA_H__
-#define __MV_FD_OUTPUT_DATA_H__
-
-#include "SingleoOutputData.h"
-
-namespace singleo
-{
-namespace inference
-{
-namespace backends
-{
-class MvFdOutputData : public SingleoOutputData
-{
-private:
-       unsigned int _frame_number {};
-       std::vector<FdResultType> _vec_result;
-
-public:
-       MvFdOutputData() {};
-       virtual ~MvFdOutputData() {};
-
-       void setFrameNumber(unsigned int frame_number)
-       {
-               _frame_number = frame_number;
-       }
-
-       void addResult(FdResultType &result)
-       {
-               _vec_result.push_back(result);
-       }
-
-       void clear() override
-       {
-               _vec_result.clear();
-       }
-
-       unsigned int getFrameNumber() const override
-       {
-               return _frame_number;
-       }
-
-       const std::vector<FdResultType> &getFdResult() const override
-       {
-               return _vec_result;
-       }
-};
-
-} // backends
-} // inference
-} // singleo
-
-#endif
\ No newline at end of file
index 33d754829e272a7ef8a8912b8c12a5f1d7b69b5e..dab3a354b9c1027c228bcc68a9445714252d3100 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "IInferenceTaskInterface.h"
 #include "mv_object_detection_internal.h"
-#include "MvOdOutputData.h"
+#include "SingleoCommonTypes.h"
 
 namespace singleo
 {
@@ -31,7 +31,7 @@ class MvObjectDetection : public IInferenceTaskInterface
 {
 private:
        mv_object_detection_h _handle {};
-       MvOdOutputData _output_data {};
+       OdResultType _output_data {};
 
 public:
        MvObjectDetection();
@@ -40,7 +40,7 @@ public:
        void configure() override;
        void prepare() override;
        void invoke(BaseDataType &input, bool async) override;
-       const SingleoOutputData &result() override;
+       BaseResultType &result() override;
 };
 
 } // backends
diff --git a/inference/backends/mediavision/include/MvOdOutputData.h b/inference/backends/mediavision/include/MvOdOutputData.h
deleted file mode 100644 (file)
index f065e0d..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __MV_OD_OUTPUT_DATA_H__
-#define __MV_OD_OUTPUT_DATA_H__
-
-#include "SingleoOutputData.h"
-
-namespace singleo
-{
-namespace inference
-{
-namespace backends
-{
-class MvOdOutputData : public SingleoOutputData
-{
-private:
-       unsigned int _frame_number {};
-       std::vector<OdResultType> _vec_result;
-
-public:
-       MvOdOutputData() {};
-       virtual ~MvOdOutputData() {};
-
-       void setFrameNumber(unsigned int frame_number)
-       {
-               _frame_number = frame_number;
-       }
-
-       void addResult(OdResultType &result)
-       {
-               _vec_result.push_back(result);
-       }
-
-       void clear() override
-       {
-               _vec_result.clear();
-       }
-
-       unsigned int getFrameNumber() const override
-       {
-               return _frame_number;
-       }
-
-       const std::vector<OdResultType> &getOdResult() const override
-       {
-               return _vec_result;
-       }
-};
-
-} // backends
-} // inference
-} // singleo
-
-#endif
\ No newline at end of file
index 362921f9a34a46b426007d3fe6fd2ba1d52ebffc..9c28e715ea6032a46d08aa66d44db23330e0fa38 100644 (file)
@@ -86,7 +86,7 @@ void MvFaceDetection::invoke(BaseDataType &input, bool async)
                throw runtime_error("Fail to destroy mv source.");
 }
 
-const SingleoOutputData &MvFaceDetection::result()
+BaseResultType &MvFaceDetection::result()
 {
        unsigned long frame_number;
        unsigned int result_cnt;
@@ -95,18 +95,17 @@ const SingleoOutputData &MvFaceDetection::result()
        if (ret != MEDIA_VISION_ERROR_NONE)
                throw runtime_error("Fail to get face detection result count.");
 
-       _output_data.clear();
-       _output_data.setFrameNumber(frame_number);
+       _output_data.rects.clear();
+       _output_data._frame_number = frame_number;
 
        for (unsigned int idx = 0; idx < result_cnt; ++idx) {
-               FdResultType result_rect;
+               Rect rect;
 
-               ret = mv_face_detection_get_bbox(_handle, idx, &result_rect.rect.left, &result_rect.rect.top,
-                                                                                &result_rect.rect.right, &result_rect.rect.bottom);
+               ret = mv_face_detection_get_bbox(_handle, idx, &rect.left, &rect.top, &rect.right, &rect.bottom);
                if (ret != MEDIA_VISION_ERROR_NONE)
                        throw runtime_error("Fail to get face detection bound box.");
 
-               _output_data.addResult(result_rect);
+               _output_data.rects.push_back(rect);
        }
 
        return _output_data;
index cf40df9e955eba29ef7a0c14cb4130f792338cf9..b7b4667e89a393b0440c433b8346badb71ad9b2e 100644 (file)
@@ -86,7 +86,7 @@ void MvObjectDetection::invoke(BaseDataType &input, bool async)
                throw runtime_error("Fail to destroy mv source.");
 }
 
-const SingleoOutputData &MvObjectDetection::result()
+BaseResultType &MvObjectDetection::result()
 {
        unsigned long frame_number;
        unsigned int result_cnt;
@@ -95,18 +95,17 @@ const SingleoOutputData &MvObjectDetection::result()
        if (ret != MEDIA_VISION_ERROR_NONE)
                throw runtime_error("Fail to get object detection result count.");
 
-       _output_data.clear();
-       _output_data.setFrameNumber(frame_number);
+       _output_data.rects.clear();
+       _output_data._frame_number = frame_number;
 
        for (unsigned int idx = 0; idx < result_cnt; ++idx) {
-               OdResultType result_rect;
+               Rect rect;
 
-               ret = mv_object_detection_get_bbox(_handle, idx, &result_rect.rect.left, &result_rect.rect.top,
-                                                                                  &result_rect.rect.right, &result_rect.rect.bottom);
+               ret = mv_object_detection_get_bbox(_handle, idx, &rect.left, &rect.top, &rect.right, &rect.bottom);
                if (ret != MEDIA_VISION_ERROR_NONE)
                        throw runtime_error("Fail to get object detection bound box.");
 
-               _output_data.addResult(result_rect);
+               _output_data.rects.push_back(rect);
        }
 
        return _output_data;
index ba9442ddcb645c4cce37db224ff5be1ff258ba84..6acd6f5586d226fdb8bfe8e6523000167c89c1fb 100644 (file)
@@ -31,7 +31,7 @@ public:
        virtual void configure() = 0;
        virtual void prepare() = 0;
        virtual void invoke(BaseDataType &input, bool async = false) = 0;
-       virtual const SingleoOutputData &result() = 0;
+       virtual BaseResultType &result() = 0;
 };
 
 } // inference
index 7d21f506622ddd835b9a08d1cfd63049598471ec..2b0aa78d412c43b8c19150362d0efe93dc77f160 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __IINFERENCE_TASK_INTERFACE_H__
 #define __IINFERENCE_TASK_INTERFACE_H__
 
-#include "SingleoOutputData.h"
+#include "SingleoCommonTypes.h"
 
 namespace singleo
 {
@@ -31,7 +31,7 @@ public:
        virtual void configure() = 0;
        virtual void prepare() = 0;
        virtual void invoke(BaseDataType &input, bool async = false) = 0;
-       virtual const SingleoOutputData &result() = 0;
+       virtual BaseResultType &result() = 0;
 };
 
 } // inference
index 92faa7c337404035a56c0250a3bdfc1fba7bc980..77d0efd692d0f413d7d7c8db00bfcb2e5c1a2a99 100644 (file)
@@ -21,6 +21,7 @@
 #include "IInferenceServiceInterface.h"
 #include "IInferenceTaskInterface.h"
 #include "SingleoInferenceTypes.h"
+#include "SingleoCommonTypes.h"
 
 namespace singleo
 {
@@ -38,7 +39,7 @@ public:
        void configure() override;
        void prepare() override;
        void invoke(BaseDataType &input, bool async = false) override;
-       const SingleoOutputData &result() override;
+       BaseResultType &result() override;
 };
 
 } // inference
index 57140c8be3ccf3f620b2b13552b2dda6bb7d3036..2df0f31e39d5f4f864b6f7be4e642858705921f2 100644 (file)
@@ -20,6 +20,7 @@
 #include "IInferenceServiceInterface.h"
 #include "IInferenceTaskInterface.h"
 #include "SingleoInferenceTypes.h"
+#include "SingleoCommonTypes.h"
 
 namespace singleo
 {
@@ -34,7 +35,7 @@ public:
        void configure() override;
        void prepare() override;
        void invoke(BaseDataType &input, bool async = false) override;
-       const SingleoOutputData &result() override;
+       BaseResultType &result() override;
 };
 
 } // inference
diff --git a/inference/include/SingleoOutputData.h b/inference/include/SingleoOutputData.h
deleted file mode 100644 (file)
index 6a8bca8..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __ISINGLEO_OUTPUT_DATA_H__
-#define __ISINGLEO_OUTPUT_DATA_H__
-
-#include "SingleoCommonTypes.h"
-#include "SingleoException.h"
-
-namespace singleo
-{
-namespace inference
-{
-class SingleoOutputData
-{
-public:
-       SingleoOutputData() = default;
-       virtual ~SingleoOutputData() = default;
-
-       virtual void clear() = 0;
-       virtual unsigned int getFrameNumber() const = 0;
-       virtual const std::vector<OdResultType> &getOdResult() const
-       {
-               throw exception::InvalidOperation("Not supported.");
-       }
-       virtual const std::vector<FdResultType> &getFdResult() const
-       {
-               throw exception::InvalidOperation("Not supported.");
-       }
-};
-
-} // inference
-} // singleo
-
-#endif
\ No newline at end of file
index aaef257fc07faa429dd6c804d3d6edbd9459ec5e..b6f058de991994434c396db518c3422b879f2d54 100644 (file)
@@ -59,7 +59,7 @@ void InferenceServiceDefault::invoke(BaseDataType &input, bool async)
        _task->invoke(input, async);
 }
 
-const SingleoOutputData &InferenceServiceDefault::result()
+BaseResultType &InferenceServiceDefault::result()
 {
        return _task->result();
 }
index a23860d85daa08959e0e5636e4dc5bdba1129862..4b7abedd63a609cab6b6cedd318f7fdd36fc7a18 100644 (file)
@@ -43,7 +43,7 @@ void InferenceServiceExternal::invoke(BaseDataType &input, bool async)
        throw runtime_error("Not support yet.");
 }
 
-const SingleoOutputData &InferenceServiceExternal::result()
+BaseResultType &InferenceServiceExternal::result()
 {
        throw runtime_error("Not support yet.");
 }
index 34a7bc4b56b6eb8a1b1158838b2038ac5af125d3..5bb817a3b4b4d1bd1f13b56dbfbdfecedaa64b48 100644 (file)
@@ -175,46 +175,34 @@ void AutoZoom::performAsync()
 void AutoZoom::updateResult(BaseDataType &in_data)
 {
        auto &output_data = _inference_service->result();
-       unsigned int frame_number = output_data.getFrameNumber();
        AutoZoomResult autozoom_result;
+       vector<Rect> rects;
 
-       if (_task_type == TaskType::OBJECT_DETECTION) {
-               const vector<OdResultType> &result = output_data.getOdResult();
-               autozoom_result.num_of_objects = result.size();
-               for (size_t idx = 0; idx < result.size(); ++idx) {
-                       SINGLEO_LOGD("%dx%d ~ %dx%d", result[idx].rect.left, result[idx].rect.top, result[idx].rect.right,
-                                                result[idx].rect.bottom);
-
-                       if (idx == 0) {
-                               autozoom_result.merged_rect = result[idx].rect;
-                               continue;
-                       }
-                       autozoom_result.merged_rect.left = min(result[idx].rect.left, autozoom_result.merged_rect.left);
-                       autozoom_result.merged_rect.top = min(result[idx].rect.top, autozoom_result.merged_rect.top);
-                       autozoom_result.merged_rect.right = max(result[idx].rect.right, autozoom_result.merged_rect.right);
-                       autozoom_result.merged_rect.bottom = max(result[idx].rect.bottom, autozoom_result.merged_rect.bottom);
-               }
-       } else {
-               const vector<FdResultType> &result = output_data.getFdResult();
-               autozoom_result.num_of_objects = result.size();
-               for (size_t idx = 0; idx < result.size(); ++idx) {
-                       SINGLEO_LOGD("%dx%d ~ %dx%d", result[idx].rect.left, result[idx].rect.top, result[idx].rect.right,
-                                                result[idx].rect.bottom);
-
-                       if (idx == 0) {
-                               autozoom_result.merged_rect = result[idx].rect;
-                               continue;
-                       }
-                       autozoom_result.merged_rect.left = min(result[idx].rect.left, autozoom_result.merged_rect.left);
-                       autozoom_result.merged_rect.top = min(result[idx].rect.top, autozoom_result.merged_rect.top);
-                       autozoom_result.merged_rect.right = max(result[idx].rect.right, autozoom_result.merged_rect.right);
-                       autozoom_result.merged_rect.bottom = max(result[idx].rect.bottom, autozoom_result.merged_rect.bottom);
-               }
+       if (output_data._type == ResultType::OBJECT_DETECTION) {
+               auto &result = static_cast<OdResultType &>(output_data);
+               rects = result.rects;
+               autozoom_result.frame_number = result._frame_number;
+       }
+       else if (output_data._type == ResultType::FACE_DETECTION) {
+               auto &result = static_cast<OdResultType &>(output_data);
+               rects = result.rects;
+               autozoom_result.frame_number = result._frame_number;
        }
 
-       autozoom_result.frame_number = frame_number;
+       autozoom_result.num_of_objects = rects.size();
 
-       // TODO. implement Postprocessor which calculates Autozoom position using above 'result' vector.
+       for (size_t idx = 0; idx < rects.size(); ++idx) {
+               SINGLEO_LOGD("%dx%d ~ %dx%d", rects[idx].left, rects[idx].top, rects[idx].right, rects[idx].bottom);
+
+               if (idx == 0) {
+                       autozoom_result.merged_rect = rects[idx];
+                       continue;
+               }
+               autozoom_result.merged_rect.left = min(rects[idx].left, autozoom_result.merged_rect.left);
+               autozoom_result.merged_rect.top = min(rects[idx].top, autozoom_result.merged_rect.top);
+               autozoom_result.merged_rect.right = max(rects[idx].right, autozoom_result.merged_rect.right);
+               autozoom_result.merged_rect.bottom = max(rects[idx].bottom, autozoom_result.merged_rect.bottom);
+       }
 
        SINGLEO_LOGD("detected object count = %zu", autozoom_result.num_of_objects);