cleanup BaseResultType
authorInki Dae <inki.dae@samsung.com>
Mon, 8 Apr 2024 00:51:23 +0000 (09:51 +0900)
committerInki Dae <inki.dae@samsung.com>
Mon, 8 Apr 2024 00:51:23 +0000 (09:51 +0900)
Clean up BaseResultType by moving common members from specific structure
to BaseResultType.

Signed-off-by: Inki Dae <inki.dae@samsung.com>
common/include/SingleoCommonTypes.h
inference/backends/mediavision/src/MvFaceDetection.cpp
inference/backends/mediavision/src/MvObjectDetection.cpp
services/auto_zoom/src/AutoZoom.cpp

index 6ee4b52476ff3fa7a0367e999b1e73cbb38ef939..cd572ebad788db96abf767198225499be60cbc34 100644 (file)
@@ -67,6 +67,7 @@ enum class ResultType { NONE, OBJECT_DETECTION, FACE_DETECTION, LANDMARK };
 struct BaseResultType {
        ResultType _type { ResultType::NONE };
        unsigned int _frame_number {};
+       std::vector<Rect> _rects;
        BaseResultType(ResultType type) : _type(type)
        {}
        virtual ~BaseResultType()
@@ -76,16 +77,12 @@ struct BaseResultType {
 struct OdResultType : public BaseResultType {
        OdResultType() : BaseResultType(ResultType::OBJECT_DETECTION)
        {}
-       unsigned int _frame_number {};
-       std::vector<Rect> rects;
        // TODO
 };
 
 struct FdResultType : public BaseResultType {
        FdResultType() : BaseResultType(ResultType::FACE_DETECTION)
        {}
-       unsigned int _frame_number {};
-       std::vector<Rect> rects;
        // TODO
 };
 
index 9c28e715ea6032a46d08aa66d44db23330e0fa38..ac2c61a87ac63626c8b33941bef71ed54db7bfef 100644 (file)
@@ -95,7 +95,7 @@ BaseResultType &MvFaceDetection::result()
        if (ret != MEDIA_VISION_ERROR_NONE)
                throw runtime_error("Fail to get face detection result count.");
 
-       _output_data.rects.clear();
+       _output_data._rects.clear();
        _output_data._frame_number = frame_number;
 
        for (unsigned int idx = 0; idx < result_cnt; ++idx) {
@@ -105,7 +105,7 @@ BaseResultType &MvFaceDetection::result()
                if (ret != MEDIA_VISION_ERROR_NONE)
                        throw runtime_error("Fail to get face detection bound box.");
 
-               _output_data.rects.push_back(rect);
+               _output_data._rects.push_back(rect);
        }
 
        return _output_data;
index b7b4667e89a393b0440c433b8346badb71ad9b2e..4a7c279a30aeb3d055e0d553b8df97402adadf80 100644 (file)
@@ -95,7 +95,7 @@ BaseResultType &MvObjectDetection::result()
        if (ret != MEDIA_VISION_ERROR_NONE)
                throw runtime_error("Fail to get object detection result count.");
 
-       _output_data.rects.clear();
+       _output_data._rects.clear();
        _output_data._frame_number = frame_number;
 
        for (unsigned int idx = 0; idx < result_cnt; ++idx) {
@@ -105,7 +105,7 @@ BaseResultType &MvObjectDetection::result()
                if (ret != MEDIA_VISION_ERROR_NONE)
                        throw runtime_error("Fail to get object detection bound box.");
 
-               _output_data.rects.push_back(rect);
+               _output_data._rects.push_back(rect);
        }
 
        return _output_data;
index 5bb817a3b4b4d1bd1f13b56dbfbdfecedaa64b48..010081fd9b3835ad5cb057ef763b88daf6810e46 100644 (file)
@@ -178,17 +178,12 @@ void AutoZoom::updateResult(BaseDataType &in_data)
        AutoZoomResult autozoom_result;
        vector<Rect> rects;
 
-       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;
-       }
+       if (output_data._type != ResultType::OBJECT_DETECTION &&
+               output_data._type != ResultType::FACE_DETECTION)
+                       throw InvalidParameter("Invalid result type");
 
+       rects = output_data._rects;
+       autozoom_result.frame_number = output_data._frame_number;
        autozoom_result.num_of_objects = rects.size();
 
        for (size_t idx = 0; idx < rects.size(); ++idx) {