task_manger: fix AutoZoom not working issue 01/314101/2
authorInki Dae <inki.dae@samsung.com>
Fri, 5 Jul 2024 05:55:09 +0000 (14:55 +0900)
committerInki Dae <inki.dae@samsung.com>
Mon, 8 Jul 2024 02:11:00 +0000 (11:11 +0900)
Fix an bug that AutoZoom service doesn't work since the patch,
"task_manager: introduce _status member in each node"

The problem happened when AutoZoom service is performed. AutoZoom service
can zoom in or output according to detected results. However, the patch
made zoom-in to work even no detected result.

As for this, this patch fixes the problem by clearing _results of each
node class at top of invoke() function.

Change-Id: I4509e6c17bddc84ef377283111e6f0ea02909d65
Signed-off-by: Inki Dae <inki.dae@samsung.com>
services/auto_zoom/include/DataTypes.h
services/auto_zoom/src/AutoZoom.cpp
services/task_manager/include/BridgeNode.h
services/task_manager/include/EndpointNode.h
services/task_manager/src/InferenceNode.cpp

index 9918322745c16ca839a3b07f8e8dd406fde74f83..8474b53ed40e60ed12ebf6894659ca67ff18fa0c 100644 (file)
@@ -32,6 +32,7 @@ enum class AutoZoomResultType { X, Y, WIDTH, HEIGHT };
 struct AutoZoomResult : public ServiceBaseResultType {
        AutoZoomResult() : ServiceBaseResultType(ServiceResultType::AUTO_ZOOM)
        {}
+       bool is_valid { false };
        unsigned int frame_number {};
        unsigned int num_of_objects {};
        Rect merged_rect;
index 2bae39cea429f7b11fdeb0d6daf1ddd392e62bef..8e2f1d5e1e09d7c6ec4b9149bd7c0b0f6019c70b 100644 (file)
@@ -264,15 +264,25 @@ void AutoZoom::updateResult(BaseDataType &in_data)
        AutoZoomResult autozoom_result;
 
        for (auto &output : _taskManager->output()) {
+               if (output->_is_empty)
+                       continue;
+
                if (output->_type != ResultType::OBJECT_DETECTION && output->_type != ResultType::FACE_DETECTION &&
                        output->_type != ResultType::FACE_RECOGNITION)
                        throw InvalidParameter("Invalid result type");
 
+               if (output->_type == ResultType::FACE_RECOGNITION) {
+                       auto &frResult = dynamic_cast<FrResultType &>(*output);
+                       SINGLEO_LOGD("label : %s", frResult._label.c_str());
+                       continue;
+               }
+
                if (output->_type == ResultType::OBJECT_DETECTION || output->_type == ResultType::FACE_DETECTION) {
                        vector<Rect> &rects = dynamic_cast<FdResultType &>(*output)._rects;
 
                        autozoom_result.frame_number = output->_frame_number;
                        autozoom_result.num_of_objects = rects.size();
+                       autozoom_result.is_valid = true;
 
                        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);
@@ -295,13 +305,14 @@ void AutoZoom::updateResult(BaseDataType &in_data)
                                SINGLEO_LOGW("No detected objects.");
                                return;
                        }
-
-               } else if (output->_type == ResultType::FACE_RECOGNITION) {
-                       auto &frResult = dynamic_cast<FrResultType &>(*output);
-                       SINGLEO_LOGD("label : %s", frResult._label.c_str());
                }
        }
 
+       // Do not push detected result to async manager to prevent from trying zooming-in
+       // if there is no detected objects.
+       if (!autozoom_result.is_valid)
+               return;
+
        if (_async_mode)
                _async_manager->pushOutput(autozoom_result);
        else
index dfa8a189202d43da59c8cab5d9d30ef4a063ec7c..cdc545e60f9be352d5187570d7b9c0f8e1b14fc3 100644 (file)
@@ -44,6 +44,7 @@ public:
                if (!_cb)
                        throw singleo::exception::InvalidOperation("Bridge node callback is not set");
 
+               _results.clear();
                _status = NodeStatus::INVALID;
                // If at least one dependency is valid, bridge node is valid.
                for (auto &dep : this->getDependencies()) {
@@ -52,11 +53,10 @@ public:
                                break;
                        }
                }
+
                if (_status == NodeStatus::INVALID)
                        return;
 
-               _results.clear();
-
                for (const auto &d : _dependencies)
                        std::copy(d->results().begin(), d->results().end(), std::back_inserter(_results));
 
index 0c30e3ace88ef3b48ab3697b792ee8ce3f042d89..af13aff5896c212eb5357b3c06ed0bfc303a46b5 100644 (file)
@@ -40,6 +40,7 @@ public:
 
        void invoke() final
        {
+               _results.clear();
                _status = NodeStatus::INVALID;
                // If at least one dependency is valid, endpoint node is valid.
                for (auto &dep : this->getDependencies()) {
@@ -51,8 +52,6 @@ public:
                if (_status == NodeStatus::INVALID)
                        return;
 
-               _results.clear();
-
                for (auto &d : _dependencies)
                        std::copy(d->results().begin(), d->results().end(), std::back_inserter(_results));
 
index df367a85c98bcd5491ce96b1b36c50e1b650ef2e..31aae47774bce0b637ae6902ea15c8a52ea4b36f 100644 (file)
@@ -40,6 +40,8 @@ void InferenceNode::configure()
 
 void InferenceNode::invoke()
 {
+       _results.clear();
+
        if (_status == NodeStatus::INVALID)
                return;
 
@@ -58,8 +60,6 @@ void InferenceNode::invoke()
        // Inference request has been completed so release input data.
        _inputBuffer->release();
 
-       _results.clear();
-
        _status = NodeStatus::INVALID;
        if (!_task->result()._is_empty) {
                _resultMutex.lock();