Define IInferenceServiceFace which is Abstract face Service.
Define IInferenceServiceFactory which is a service factory.
Define MvInferenceServiceFactory which is a service factory
creating MediaVision based service such as MvInferenceFaceService.
The MvInferenceFaceService is Concrete face service based on
MediaVision.
If You want an external solution, Mediapipe, based face service then
add ExternalInferenceServiceFactory and ExternalInferenceFaceService.
In case of Mediapipe, MediapipeServiceFactory and MediapipeFaceService.
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
#define __SINGLEO_COMMON_TYPES_H__
#include <vector>
+#include <string>
namespace singleo
{
IF (${USE_EXTERNAL_INFERENCE_SERVICE})
SET(SINGLEO_INFERENCE_HEADER_DIRECTORY "")
- SET(SINGLEO_INFERENCE_SERVUCE_FILE "InferenceServiceExternal.cpp")
+ SET(SINGLEO_INFERENCE_SERVUCE_FILE "{PROJECT_SOURCE_DIR}/src/InferenceServiceExternal.cpp")
ELSE()
SET(SINGLEO_INFERENCE_HEADER_DIRECTORY /usr/include/media backends/mediavision/include)
- SET(SINGLEO_INFERENCE_SERVUCE_FILE "InferenceServiceMulti.cpp")
+ SET(SINGLEO_INFERENCE_SERVUCE_FILE
+ ${SINGLEO_INFERENCE_SERVUCE_FILE}
+ ${PROJECT_SOURCE_DIR}/src/MvInferenceServiceFactory.cpp
+ ${PROJECT_SOURCE_DIR}/src/MvInferenceFaceService.cpp)
ENDIF()
-FILE(GLOB SINGLEO_INFERENCE_SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/${SINGLEO_INFERENCE_SERVUCE_FILE}")
+MESSAGE("${SINGLEO_INFERENCE_SERVUCE_FILE}")
+FILE(GLOB SINGLEO_INFERENCE_SOURCE_FILES ${SINGLEO_INFERENCE_SERVUCE_FILE})
ADD_LIBRARY(${PROJECT_NAME} SHARED ${SINGLEO_INFERENCE_SOURCE_FILES})
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PRIVATE include ../common/include ../log/include ${SINGLEO_INFERENCE_HEADER_DIRECTORY})
--- /dev/null
+/**
+ * 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 __INTERFACE_MV_FACE_TASK_MANAGER_H__
+#define __INTERFACE_MV_FACE_TASK_MANAGER_H__
+
+#include <memory>
+#include "FaceResult.h"
+
+namespace singleo
+{
+namespace inference
+{
+namespace backends
+{
+class IMvFaceTaskManager
+{
+public:
+ virtual std::shared_ptr<IMvFaceTaskManager> setNext(std::shared_ptr<IMvFaceTaskManager> next) = 0;
+ virtual FaceResult& handle(unsigned char* data, unsigned int width, unsigned int height, unsigned int byte_per_pixel, FaceResult &result) = 0;
+};
+
+} // backends
+} // inference
+} // singleo
+
+#endif
--- /dev/null
+/**
+ * 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_FACE_DETECTION_TASK_H__
+#define __MV_FACE_DETECTION_TASK_H__
+
+#include <memory>
+#include "MvFaceTaskManager.h"
+#include "mv_face_detection_internal.h"
+
+namespace singleo
+{
+namespace inference
+{
+namespace backends
+{
+class MvFaceDetectionTask : public MvFaceTaskManager
+{
+private:
+ mv_face_detection_h _handle {};
+ mv_source_h _mv_src {};
+
+public:
+ MvFaceDetectionTask();
+ virtual ~MvFaceDetectionTask();
+
+ FaceResult& handle(unsigned char* data, unsigned int width, unsigned int height, unsigned int byte_per_pixel, FaceResult &result) override;
+};
+
+} // backends
+} // inference
+} // singleo
+
+#endif
--- /dev/null
+/**
+ * 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_FACE_LANDMARK_DETECTION_TASK_H__
+#define __MV_FACE_LANDMARK_DETECTION_TASK_H__
+
+#include <memory>
+#include "MvFaceTaskManager.h"
+#include "mv_facial_landmark_internal.h"
+
+namespace singleo
+{
+namespace inference
+{
+namespace backends
+{
+class MvFaceLandmarkDetectionTask : public MvFaceTaskManager
+{
+private:
+ mv_facial_landmark_h _handle {};
+ mv_source_h _mv_src {};
+
+public:
+ MvFaceLandmarkDetectionTask();
+ virtual ~MvFaceLandmarkDetectionTask();
+
+ FaceResult& handle(unsigned char* data, unsigned int width, unsigned int height, unsigned int byte_per_pixel, FaceResult &result) override;
+};
+
+} // backends
+} // inference
+} // singleo
+
+#endif
--- /dev/null
+/**
+ * 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_FACE_TASK_MANAGER_H__
+#define __MV_FACE_TASK_MANAGER_H__
+
+#include <memory>
+#include "IMvFaceTaskManager.h"
+#include "SingleoLog.h"
+
+namespace singleo
+{
+namespace inference
+{
+namespace backends
+{
+class MvFaceTaskManager : public IMvFaceTaskManager
+{
+private:
+ std::shared_ptr<IMvFaceTaskManager> _next;
+public:
+ MvFaceTaskManager();
+ virtual ~MvFaceTaskManager();
+
+ std::shared_ptr<IMvFaceTaskManager> setNext(std::shared_ptr<IMvFaceTaskManager> next) override;
+ FaceResult& handle(unsigned char* data, unsigned int width, unsigned int height, unsigned int byte_per_pixel, FaceResult &result) override;
+};
+
+} // backends
+} // inference
+} // singleo
+
+#endif
--- /dev/null
+/**
+ * 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.
+ */
+
+#include <stdexcept>
+#include "MvFaceDetectionTask.h"
+
+using namespace std;
+
+namespace singleo
+{
+namespace inference
+{
+namespace backends
+{
+MvFaceDetectionTask::MvFaceDetectionTask()
+{
+ int ret = mv_create_source(&_mv_src);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to create mv source.");
+
+ ret = mv_face_detection_create(&_handle);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to create face detection handle.");
+
+ ret = mv_face_detection_configure(_handle);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to configure face detection.");
+
+ ret = mv_face_detection_prepare(_handle);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to prepare face detection.");
+}
+
+MvFaceDetectionTask::~MvFaceDetectionTask()
+{
+ mv_face_detection_destroy(_handle);
+ mv_destroy_source(_mv_src);
+}
+
+FaceResult& MvFaceDetectionTask::handle(unsigned char* data, unsigned int width, unsigned int height, unsigned int byte_per_pixel, FaceResult &result)
+{
+ SINGLEO_LOGD("MvFaceDetectionTask::handle()");
+
+ int ret = mv_source_fill_by_buffer(_mv_src, data, width * height * byte_per_pixel, width,
+ height, MEDIA_VISION_COLORSPACE_RGB888);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to convert to mv source.");
+
+ ret = mv_face_detection_inference(_handle, _mv_src);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to invoke face detection.");
+
+ unsigned long frame_number;
+ unsigned int result_cnt;
+ ret = mv_face_detection_get_result_count(_handle, &frame_number, &result_cnt);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to get face detection result count.");
+
+ for (unsigned int idx = 0; idx < result_cnt; ++idx) {
+ Rect rect;
+
+ 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.");
+
+ result._rects.push_back(rect);
+ SINGLEO_LOGD("idx[%2zd]: (%3zd, %3zd, %3zd, %3zd)", idx, rect.left, rect.top, rect.right, rect.bottom);
+ }
+ result = MvFaceTaskManager::handle(data, width, height, byte_per_pixel, result);
+
+ return result;
+}
+
+} // backends
+} // inference
+} // singleo
\ No newline at end of file
--- /dev/null
+/**
+ * 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.
+ */
+
+#include <stdexcept>
+#include <opencv2/core.hpp>
+#include "MvFaceLandmarkDetectionTask.h"
+
+using namespace std;
+
+namespace singleo
+{
+namespace inference
+{
+namespace backends
+{
+MvFaceLandmarkDetectionTask::MvFaceLandmarkDetectionTask()
+{
+ int ret = mv_create_source(&_mv_src);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to create mv source.");
+
+ ret = mv_facial_landmark_create(&_handle);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to create face landmark detection handle.");
+
+ ret = mv_facial_landmark_configure(_handle);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to configure face landmark detection.");
+
+ ret = mv_facial_landmark_prepare(_handle);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to prepare face landmark detection.");
+}
+
+MvFaceLandmarkDetectionTask::~MvFaceLandmarkDetectionTask()
+{
+ mv_facial_landmark_destroy(_handle);
+ mv_destroy_source(_mv_src);
+}
+
+FaceResult& MvFaceLandmarkDetectionTask::handle(unsigned char* data, unsigned int width, unsigned int height, unsigned int byte_per_pixel, FaceResult &result)
+{
+ SINGLEO_LOGD("MvFaceLandmarkDetectionTask::handle()");
+
+ cv::Mat cvData(cv::Size(width, height), CV_MAKE_TYPE(CV_8U, byte_per_pixel), data);
+ cv::Mat roiCvData;
+
+ if (result._rects.empty())
+ roiCvData = cvData;
+ else{
+ for (auto &rect : result._rects) {
+ roiCvData = cvData(cv::Rect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top));
+
+ int ret = mv_source_fill_by_buffer(_mv_src, roiCvData.data, roiCvData.cols * roiCvData.rows * byte_per_pixel, roiCvData.cols,
+ roiCvData.rows, MEDIA_VISION_COLORSPACE_RGB888);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to convert to mv source.");
+
+ ret = mv_facial_landmark_inference(_handle, _mv_src);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to invoke face landmark detection.");
+
+ unsigned long frame_number;
+ unsigned int result_cnt;
+ ret = mv_facial_landmark_get_result_count(_handle, &frame_number, &result_cnt);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to get face landmark detection result count.");
+
+ Points landmarks;
+ for (unsigned int idx = 0; idx < result_cnt; ++idx) {
+ Point landmark;
+
+ ret = mv_facial_landmark_get_position(_handle, idx, &landmark.x, &landmark.y);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to get face landmark detection bound box.");
+
+ landmark.x += rect.left;
+ landmark.y += rect.top;
+ landmarks.push_back(landmark);
+ SINGLEO_LOGD("idx[%2zd]: (%3zd, %3zd)", idx, landmark.x, landmark.y);
+ }
+
+ result._landmarks.push_back(landmarks);
+ result = MvFaceTaskManager::handle(data, width, height, byte_per_pixel, result);
+ }
+ }
+ return result;
+}
+
+} // backends
+} // inference
+} // singleo
\ No newline at end of file
--- /dev/null
+/**
+ * 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.
+ */
+
+#include <stdexcept>
+#include "MvFaceTaskManager.h"
+
+using namespace std;
+
+namespace singleo
+{
+namespace inference
+{
+namespace backends
+{
+MvFaceTaskManager::MvFaceTaskManager() : _next(nullptr)
+{
+
+}
+
+MvFaceTaskManager::~MvFaceTaskManager()
+{
+
+}
+
+shared_ptr<IMvFaceTaskManager> MvFaceTaskManager::setNext(shared_ptr<IMvFaceTaskManager> next)
+{
+ _next = next;
+ return next;
+}
+
+FaceResult& MvFaceTaskManager::handle(unsigned char* data, unsigned int width, unsigned int height, unsigned int byte_per_pixel, FaceResult &result)
+{
+ if (_next)
+ return _next->handle(data, width, height, byte_per_pixel, result);
+
+ return result;
+}
+} // backends
+} // inference
+} // singleo
\ No newline at end of file
--- /dev/null
+/**
+ * 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 __INFERENCE_SERVICE_FACE_RESULT_H__
+#define __INFERENCE_SERVICE_FACE_RESULT_H__
+
+#include "SingleoCommonTypes.h"
+
+namespace singleo
+{
+namespace inference
+{
+using Points = std::vector<Point>;
+struct FaceResult {
+ unsigned int _frame_number {};
+ std::vector<Rect> _rects;
+ std::vector<Points> _landmarks;
+};
+} // inference
+} // singleo
+
+#endif
--- /dev/null
+/**
+ * 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 __IINFERENCE_FACE_SERVICE_H__
+#define __IINFERENCE_FACE_SERVICE_H__
+
+#include "FaceResult.h"
+#include "SingleoInferenceTypes.h"
+
+namespace singleo
+{
+namespace inference
+{
+class IInferenceFaceService
+{
+public:
+ virtual ~IInferenceFaceService() {};
+
+ virtual void configure() = 0;
+ virtual void prepare() = 0;
+ virtual void invoke(BaseDataType &input) = 0;
+ virtual FaceResult &result() = 0;
+};
+
+} // inference
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * 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 __IINFERENCE_SERVICE_FACTORY_H__
+#define __IINFERENCE_SERVICE_FACTORY_H__
+
+#include <memory>
+#include "IInferenceFaceService.h"
+#include "SingleoInferenceTypes.h"
+
+namespace singleo
+{
+namespace inference
+{
+class IInferenceServiceFactory
+{
+public:
+ virtual std::unique_ptr<IInferenceFaceService> createInferenceFaceService(std::vector<inference::TaskType> &tasks) = 0;
+};
+
+} // inference
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * 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_INFERENCE_FACE_SERVICE_H__
+#define __MV_INFERENCE_FACE_SERVICE_H__
+
+#include <memory>
+#include "IInferenceFaceService.h"
+#include "MvFaceTaskManager.h"
+
+using namespace singleo::inference::backends;
+
+namespace singleo
+{
+namespace inference
+{
+class MvInferenceFaceService : public IInferenceFaceService
+{
+private:
+ std::shared_ptr<MvFaceTaskManager> _taskManager;
+ FaceResult _result;
+
+public:
+ MvInferenceFaceService(std::vector<inference::TaskType> &tasks);
+ virtual ~MvInferenceFaceService() {};
+ void configure() override;
+ void prepare() override;
+ void invoke(BaseDataType &input) override;
+ FaceResult &result() override;
+};
+
+} // inference
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * 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_INFERENCE_SERVICE_FACTORY_H__
+#define __MV_INFERENCE_SERVICE_FACTORY_H__
+
+#include "IInferenceServiceFactory.h"
+
+namespace singleo
+{
+namespace inference
+{
+class MvInferenceServiceFactory : public IInferenceServiceFactory
+{
+public:
+ std::unique_ptr<IInferenceFaceService> createInferenceFaceService(std::vector<inference::TaskType> &tasks) override;
+};
+
+} // inference
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * 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.
+ */
+
+#include "SingleoCommonTypes.h"
+#include "MvInferenceFaceService.h"
+#include "MvFaceDetectionTask.h"
+#include "MvFaceLandmarkDetectionTask.h"
+
+using namespace std;
+
+namespace singleo
+{
+namespace inference
+{
+MvInferenceFaceService::MvInferenceFaceService(std::vector<inference::TaskType> &tasks)
+{
+ for (auto &task : tasks) {
+ switch (task) {
+ case TaskType::FACE_DETECTION:
+ {
+ if (_taskManager.use_count() > 0)
+ _taskManager->setNext(std::make_shared<MvFaceDetectionTask>());
+ else
+ _taskManager = std::make_shared<MvFaceDetectionTask>();
+ }
+ break;
+ case TaskType::FACE_LANDMARK_DETECTION:
+ {
+ if (_taskManager.use_count() > 0)
+ _taskManager->setNext(std::make_shared<MvFaceLandmarkDetectionTask>());
+ else
+ _taskManager = std::make_shared<MvFaceLandmarkDetectionTask>();
+ }
+ break;
+ default:
+ SINGLEO_LOGE("Not supported task type %d", tasks[0]);
+ break;
+ }
+ }
+}
+
+void MvInferenceFaceService::configure()
+{
+
+}
+
+void MvInferenceFaceService::prepare()
+{
+
+}
+
+void MvInferenceFaceService::invoke(BaseDataType &input)
+{
+ if (input._data_type != DataType::IMAGE) {
+ SINGLEO_LOGE("Invalid input type.");
+ throw invalid_argument("Input type not support.");
+ }
+
+ ImageDataType &data = dynamic_cast<ImageDataType &>(input);
+ _result = _taskManager->handle(data.ptr, data.width, data.height, data.byte_per_pixel, _result);
+}
+
+FaceResult& MvInferenceFaceService::result()
+{
+ return _result;
+}
+} // inference
+} // singleo
\ No newline at end of file
--- /dev/null
+/**
+ * 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.
+ */
+
+#include "MvInferenceServiceFactory.h"
+#include "MvInferenceFaceService.h"
+
+using namespace std;
+
+namespace singleo
+{
+namespace inference
+{
+unique_ptr<IInferenceFaceService> MvInferenceServiceFactory::createInferenceFaceService(std::vector<inference::TaskType> &tasks)
+{
+ return make_unique<MvInferenceFaceService>(tasks);
+}
+} // inference
+} // singleo
\ No newline at end of file
#define __GAZE_ESTIMATOR_H__
#include <memory>
-#include "IInferenceServiceInterface.h"
+#include "IInferenceFaceService.h"
#include "IInputService.h"
#include "SingleoInferenceTypes.h"
#include "PoseVector.h"
class GazeEstimator
{
private:
- std::unique_ptr<singleo::inference::IInferenceServiceInterface> _face_estimator;
+ std::unique_ptr<singleo::inference::IInferenceFaceService> _face_estimator;
std::unique_ptr<singleo::input::IInputService> _input_service;
- const std::vector<inference::TaskType> _tasks { inference::TaskType::FACE_DETECTION, inference::TaskType::FACE_LANDMARK_DETECTION };
+ std::vector<inference::TaskType> _tasks { inference::TaskType::FACE_DETECTION, inference::TaskType::FACE_LANDMARK_DETECTION };
public:
explicit GazeEstimator(input::InputConfigBase &config);
*/
#include "GazeEstimator.h"
-#include "InferenceServiceMulti.h"
+#include "MvInferenceServiceFactory.h"
#include "InputCamera.h"
#include "SingleoLog.h"
{
GazeEstimator::GazeEstimator(InputConfigBase& config)
{
- _face_estimator = make_unique<InferenceServiceMulti>(_tasks);
+ MvInferenceServiceFactory factory;
+ _face_estimator = factory.createInferenceFaceService(_tasks);
_face_estimator->configure();
_face_estimator->prepare();
SINGLEO_LOGD("Invoke done");
auto &result = _face_estimator->result();
SINGLEO_LOGD("Result done");
- if (!result._rects.empty())
- SINGLEO_LOGD("ROI: %d, %d, %d,%d",
- result._rects[0].top, result._rects[0].left, result._rects[0].bottom, result._rects[0].right);
+ // if (!result._rects.empty())
+ // SINGLEO_LOGD("ROI: %d, %d, %d,%d",
+ // result._rects[0].top, result._rects[0].left, result._rects[0].bottom, result._rects[0].right);
- auto &headPose = dynamic_cast<FldResultType&>(result);
- SINGLEO_LOGD("Landmark: %zd, %zd",
- headPose._landmarks[0].x, headPose._landmarks[0].y);
+ // auto &headPose = dynamic_cast<FldResultType&>(result);
+ // SINGLEO_LOGD("Landmark: %zd, %zd",
+ // headPose._landmarks[0].x, headPose._landmarks[0].y);
return PoseVector{-1, -1, -1};
}