mv_machine_learning: introduce IObjectDetection class
authorInki Dae <inki.dae@samsung.com>
Fri, 9 Jun 2023 07:40:40 +0000 (16:40 +0900)
committerKwanghoon Son <k.son@samsung.com>
Tue, 4 Jul 2023 05:08:39 +0000 (14:08 +0900)
[Issue type] : new feature

Introduce IObjectDetection class which needs to support plugin base behavior
class. With this patch, the internal behavior class, ObjectDetection,
is derived from IObjectDetection.

On top of this patch, I will introduce a wrapper class derived from
IObjectDetection again. The wrapper class will be used to deploy plugin based
behavior class using dlsym function.

Change-Id: I0d66ceab010e66fab6d45bb8e55a042f9f9a1403
Signed-off-by: Inki Dae <inki.dae@samsung.com>
mv_machine_learning/object_detection/include/face_detection_adapter.h
mv_machine_learning/object_detection/include/iobject_detection.h [new file with mode: 0644]
mv_machine_learning/object_detection/include/object_detection.h
mv_machine_learning/object_detection/include/object_detection_adapter.h
mv_machine_learning/object_detection/src/face_detection_adapter.cpp
mv_machine_learning/object_detection/src/object_detection.cpp
mv_machine_learning/object_detection/src/object_detection_adapter.cpp

index ec2536d782638a1472e12a6eea7e6b81c797328e..d71bbe38bd33ef52fb03e68dd483bc0eb5f74e19 100644 (file)
@@ -30,7 +30,7 @@ namespace machine_learning
 template<typename T, typename V> class FaceDetectionAdapter : public mediavision::common::ITask<T, V>
 {
 private:
-       std::unique_ptr<ObjectDetection> _object_detection;
+       std::unique_ptr<IObjectDetection> _object_detection;
        T _source;
        std::string _model_name;
        std::string _model_file;
diff --git a/mv_machine_learning/object_detection/include/iobject_detection.h b/mv_machine_learning/object_detection/include/iobject_detection.h
new file mode 100644 (file)
index 0000000..ccc735c
--- /dev/null
@@ -0,0 +1,50 @@
+/**
+ * Copyright (c) 2023 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 __IOBJECT_DETECTION_H__
+#define __IOBJECT_DETECTION_H__
+
+#include <mv_common.h>
+
+#include "object_detection_type.h"
+
+namespace mediavision
+{
+namespace machine_learning
+{
+class IObjectDetection
+{
+public:
+       virtual ~IObjectDetection() {};
+       virtual void preDestroy() = 0;
+       virtual ObjectDetectionTaskType getTaskType() = 0;
+       virtual void setUserModel(std::string model_file, std::string meta_file, std::string label_file) = 0;
+       virtual void setEngineInfo(std::string engine_type, std::string device_type) = 0;
+       virtual void getNumberOfEngines(unsigned int *number_of_engines) = 0;
+       virtual void getEngineType(unsigned int engine_index, char **engine_type) = 0;
+       virtual void getNumberOfDevices(const char *engine_type, unsigned int *number_of_devices) = 0;
+       virtual void getDeviceType(const char *engine_type, const unsigned int device_index, char **device_type) = 0;
+       virtual void configure(std::string configFile) = 0;
+       virtual void prepare() = 0;
+       virtual void perform(mv_source_h &mv_src) = 0;
+       virtual void performAsync(ObjectDetectionInput &input) = 0;
+       virtual ObjectDetectionResult &getOutput() = 0;
+};
+
+} // machine_learning
+} // mediavision
+
+#endif
\ No newline at end of file
index 561a42f9be3faa24f4b33666b4e1a34478e9cebd..c552427c09fc4c2db4827cedc0608c87cc7a2a0f 100644 (file)
 #include "object_detection_type.h"
 #include "ObjectDetectionParser.h"
 #include "Preprocess.h"
+#include "iobject_detection.h"
 
 namespace mediavision
 {
 namespace machine_learning
 {
-class ObjectDetection
+class ObjectDetection : public IObjectDetection
 {
 private:
        ObjectDetectionTaskType _task_type;
@@ -91,19 +92,19 @@ protected:
 public:
        ObjectDetection(ObjectDetectionTaskType task_type);
        virtual ~ObjectDetection() = default;
-       void preDestroy();
-       ObjectDetectionTaskType getTaskType();
-       void setUserModel(std::string model_file, std::string meta_file, std::string label_file);
-       void setEngineInfo(std::string engine_type, std::string device_type);
-       void getNumberOfEngines(unsigned int *number_of_engines);
-       void getEngineType(unsigned int engine_index, char **engine_type);
-       void getNumberOfDevices(const char *engine_type, unsigned int *number_of_devices);
-       void getDeviceType(const char *engine_type, const unsigned int device_index, char **device_type);
-       void configure(std::string configFile);
-       void prepare();
-       void perform(mv_source_h &mv_src);
-       void performAsync(ObjectDetectionInput &input);
-       template<typename V> V &getOutput();
+       void preDestroy() override;
+       ObjectDetectionTaskType getTaskType() override;
+       void setUserModel(std::string model_file, std::string meta_file, std::string label_file) override;
+       void setEngineInfo(std::string engine_type, std::string device_type) override;
+       void getNumberOfEngines(unsigned int *number_of_engines) override;
+       void getEngineType(unsigned int engine_index, char **engine_type) override;
+       void getNumberOfDevices(const char *engine_type, unsigned int *number_of_devices) override;
+       void getDeviceType(const char *engine_type, const unsigned int device_index, char **device_type) override;
+       void configure(std::string configFile) override;
+       void prepare() override;
+       void perform(mv_source_h &mv_src) override;
+       void performAsync(ObjectDetectionInput &input) override;
+       ObjectDetectionResult &getOutput() override;
 };
 
 } // machine_learning
index 17bd909994402c266d2b6ff4db6db97f9e5ac8b6..5975c6868f40db097bbd8197a095cbe76d8670b5 100644 (file)
@@ -31,7 +31,7 @@ namespace machine_learning
 template<typename T, typename V> class ObjectDetectionAdapter : public mediavision::common::ITask<T, V>
 {
 private:
-       std::unique_ptr<ObjectDetection> _object_detection;
+       std::unique_ptr<IObjectDetection> _object_detection;
        T _source;
        std::string _model_name;
        std::string _model_file;
index 530cfc97e50e470a037a5341b05c20d4ff731b3b..9ee8d6c9a9d669e63e65ca7c5582f8f0b6d61fcb 100644 (file)
@@ -140,7 +140,7 @@ template<typename T, typename V> void FaceDetectionAdapter<T, V>::performAsync(T
 
 template<typename T, typename V> V &FaceDetectionAdapter<T, V>::getOutput()
 {
-       return _object_detection->getOutput<V>();
+       return _object_detection->getOutput();
 }
 
 template class FaceDetectionAdapter<ObjectDetectionInput, ObjectDetectionResult>;
index 6dc943367d507f43c78b211082f6828139df7f60..a84b730e68b4e563363cac6da0a23b9638c4804e 100644 (file)
@@ -395,7 +395,7 @@ void ObjectDetection::updateResult(ObjectDetectionResult &result)
        _current_result.is_valid = true;
 }
 
-template<typename V> V &ObjectDetection::getOutput()
+ObjectDetectionResult &ObjectDetection::getOutput()
 {
        if (_thread_handle) {
                // There may be two or more Native APIs which utilize getOutput() function.
@@ -406,7 +406,7 @@ template<typename V> V &ObjectDetection::getOutput()
                if (isOutputQueueEmpty())
                        throw InvalidOperation("Output queue is empty.");
 
-               V result = popFromOutput();
+               ObjectDetectionResult result = popFromOutput();
                updateResult(result);
 
                return _current_result;
@@ -500,7 +500,5 @@ template bool ObjectDetection::isInputQueueEmpty<unsigned char>();
 
 template void ObjectDetection::performAsync<unsigned char>(ObjectDetectionInput &input, shared_ptr<MetaInfo> metaInfo);
 
-template ObjectDetectionResult &ObjectDetection::getOutput();
-
 }
 }
\ No newline at end of file
index ca285c02477c3d860f563d5fa8add97d3c46aba7..d53250fe5a6d2841f028cef0bd3e89f67d9a2248 100644 (file)
@@ -141,7 +141,7 @@ template<typename T, typename V> void ObjectDetectionAdapter<T, V>::perform()
 
 template<typename T, typename V> V &ObjectDetectionAdapter<T, V>::getOutput()
 {
-       return _object_detection->getOutput<V>();
+       return _object_detection->getOutput();
 }
 
 template<typename T, typename V> void ObjectDetectionAdapter<T, V>::performAsync(T &t)