From: Inki Dae Date: Fri, 5 Apr 2024 09:06:23 +0000 (+0900) Subject: drop SingleoOutputData class X-Git-Tag: accepted/tizen/unified/20240903.110722~76^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b5864b5358b6b1fe049873b485ec7e3d8215371c;p=platform%2Fcore%2Fapi%2Fsingleo.git drop SingleoOutputData class Drop SingleoOuputData and its child classes, and use BaseResultType and its child structures instead. Signed-off-by: Inki Dae --- diff --git a/common/include/SingleoCommonTypes.h b/common/include/SingleoCommonTypes.h index a125c98..6ee4b52 100644 --- a/common/include/SingleoCommonTypes.h +++ b/common/include/SingleoCommonTypes.h @@ -76,14 +76,16 @@ struct BaseResultType { struct OdResultType : public BaseResultType { OdResultType() : BaseResultType(ResultType::OBJECT_DETECTION) {} - Rect rect; + unsigned int _frame_number {}; + std::vector rects; // TODO }; struct FdResultType : public BaseResultType { FdResultType() : BaseResultType(ResultType::FACE_DETECTION) {} - Rect rect; + unsigned int _frame_number {}; + std::vector rects; // TODO }; diff --git a/inference/backends/mediavision/include/MvFaceDetection.h b/inference/backends/mediavision/include/MvFaceDetection.h index 2137562..fe463f7 100644 --- a/inference/backends/mediavision/include/MvFaceDetection.h +++ b/inference/backends/mediavision/include/MvFaceDetection.h @@ -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 index 66d894e..0000000 --- a/inference/backends/mediavision/include/MvFdOutputData.h +++ /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 _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 &getFdResult() const override - { - return _vec_result; - } -}; - -} // backends -} // inference -} // singleo - -#endif \ No newline at end of file diff --git a/inference/backends/mediavision/include/MvObjectDetection.h b/inference/backends/mediavision/include/MvObjectDetection.h index 33d7548..dab3a35 100644 --- a/inference/backends/mediavision/include/MvObjectDetection.h +++ b/inference/backends/mediavision/include/MvObjectDetection.h @@ -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 index f065e0d..0000000 --- a/inference/backends/mediavision/include/MvOdOutputData.h +++ /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 _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 &getOdResult() const override - { - return _vec_result; - } -}; - -} // backends -} // inference -} // singleo - -#endif \ No newline at end of file diff --git a/inference/backends/mediavision/src/MvFaceDetection.cpp b/inference/backends/mediavision/src/MvFaceDetection.cpp index 362921f..9c28e71 100644 --- a/inference/backends/mediavision/src/MvFaceDetection.cpp +++ b/inference/backends/mediavision/src/MvFaceDetection.cpp @@ -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; diff --git a/inference/backends/mediavision/src/MvObjectDetection.cpp b/inference/backends/mediavision/src/MvObjectDetection.cpp index cf40df9..b7b4667 100644 --- a/inference/backends/mediavision/src/MvObjectDetection.cpp +++ b/inference/backends/mediavision/src/MvObjectDetection.cpp @@ -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; diff --git a/inference/include/IInferenceServiceInterface.h b/inference/include/IInferenceServiceInterface.h index ba9442d..6acd6f5 100644 --- a/inference/include/IInferenceServiceInterface.h +++ b/inference/include/IInferenceServiceInterface.h @@ -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 diff --git a/inference/include/IInferenceTaskInterface.h b/inference/include/IInferenceTaskInterface.h index 7d21f50..2b0aa78 100644 --- a/inference/include/IInferenceTaskInterface.h +++ b/inference/include/IInferenceTaskInterface.h @@ -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 diff --git a/inference/include/InferenceServiceDefault.h b/inference/include/InferenceServiceDefault.h index 92faa7c..77d0efd 100644 --- a/inference/include/InferenceServiceDefault.h +++ b/inference/include/InferenceServiceDefault.h @@ -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 diff --git a/inference/include/InferenceServiceExternal.h b/inference/include/InferenceServiceExternal.h index 57140c8..2df0f31 100644 --- a/inference/include/InferenceServiceExternal.h +++ b/inference/include/InferenceServiceExternal.h @@ -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 index 6a8bca8..0000000 --- a/inference/include/SingleoOutputData.h +++ /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 &getOdResult() const - { - throw exception::InvalidOperation("Not supported."); - } - virtual const std::vector &getFdResult() const - { - throw exception::InvalidOperation("Not supported."); - } -}; - -} // inference -} // singleo - -#endif \ No newline at end of file diff --git a/inference/src/InferenceServiceDefault.cpp b/inference/src/InferenceServiceDefault.cpp index aaef257..b6f058d 100644 --- a/inference/src/InferenceServiceDefault.cpp +++ b/inference/src/InferenceServiceDefault.cpp @@ -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(); } diff --git a/inference/src/InferenceServiceExternal.cpp b/inference/src/InferenceServiceExternal.cpp index a23860d..4b7abed 100644 --- a/inference/src/InferenceServiceExternal.cpp +++ b/inference/src/InferenceServiceExternal.cpp @@ -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."); } diff --git a/services/auto_zoom/src/AutoZoom.cpp b/services/auto_zoom/src/AutoZoom.cpp index 34a7bc4..5bb817a 100644 --- a/services/auto_zoom/src/AutoZoom.cpp +++ b/services/auto_zoom/src/AutoZoom.cpp @@ -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 rects; - if (_task_type == TaskType::OBJECT_DETECTION) { - const vector &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 &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(output_data); + rects = result.rects; + autozoom_result.frame_number = result._frame_number; + } + else if (output_data._type == ResultType::FACE_DETECTION) { + auto &result = static_cast(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);