From: Tae-Young Chung Date: Thu, 18 Apr 2024 09:27:05 +0000 (+0900) Subject: [WIP-03] Refactoring: IInferenceServiceInterface X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5f3a0e830967a0803259bc89d9f7d5b00d75e261;p=platform%2Fcore%2Fapi%2Fsingleo.git [WIP-03] Refactoring: IInferenceServiceInterface 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 --- diff --git a/common/include/SingleoCommonTypes.h b/common/include/SingleoCommonTypes.h index d969929..02480e6 100644 --- a/common/include/SingleoCommonTypes.h +++ b/common/include/SingleoCommonTypes.h @@ -18,6 +18,7 @@ #define __SINGLEO_COMMON_TYPES_H__ #include +#include namespace singleo { diff --git a/cvFace.png b/cvFace.png deleted file mode 100644 index d6c6bae..0000000 Binary files a/cvFace.png and /dev/null differ diff --git a/inference/CMakeLists.txt b/inference/CMakeLists.txt index ebf300f..5cc74b1 100644 --- a/inference/CMakeLists.txt +++ b/inference/CMakeLists.txt @@ -5,13 +5,17 @@ ADD_SUBDIRECTORY(backends) 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}) diff --git a/inference/backends/mediavision/include/IMvFaceTaskManager.h b/inference/backends/mediavision/include/IMvFaceTaskManager.h new file mode 100644 index 0000000..cb60261 --- /dev/null +++ b/inference/backends/mediavision/include/IMvFaceTaskManager.h @@ -0,0 +1,40 @@ +/** + * 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 +#include "FaceResult.h" + +namespace singleo +{ +namespace inference +{ +namespace backends +{ +class IMvFaceTaskManager +{ +public: + virtual std::shared_ptr setNext(std::shared_ptr 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 diff --git a/inference/backends/mediavision/include/MvFaceDetectionTask.h b/inference/backends/mediavision/include/MvFaceDetectionTask.h new file mode 100644 index 0000000..82ff98e --- /dev/null +++ b/inference/backends/mediavision/include/MvFaceDetectionTask.h @@ -0,0 +1,47 @@ +/** + * 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 +#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 diff --git a/inference/backends/mediavision/include/MvFaceLandmarkDetectionTask.h b/inference/backends/mediavision/include/MvFaceLandmarkDetectionTask.h new file mode 100644 index 0000000..a7ce8b7 --- /dev/null +++ b/inference/backends/mediavision/include/MvFaceLandmarkDetectionTask.h @@ -0,0 +1,47 @@ +/** + * 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 +#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 diff --git a/inference/backends/mediavision/include/MvFaceTaskManager.h b/inference/backends/mediavision/include/MvFaceTaskManager.h new file mode 100644 index 0000000..bb7c83e --- /dev/null +++ b/inference/backends/mediavision/include/MvFaceTaskManager.h @@ -0,0 +1,46 @@ +/** + * 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 +#include "IMvFaceTaskManager.h" +#include "SingleoLog.h" + +namespace singleo +{ +namespace inference +{ +namespace backends +{ +class MvFaceTaskManager : public IMvFaceTaskManager +{ +private: + std::shared_ptr _next; +public: + MvFaceTaskManager(); + virtual ~MvFaceTaskManager(); + + std::shared_ptr setNext(std::shared_ptr 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 diff --git a/inference/backends/mediavision/src/MvFaceDetectionTask.cpp b/inference/backends/mediavision/src/MvFaceDetectionTask.cpp new file mode 100644 index 0000000..6d66755 --- /dev/null +++ b/inference/backends/mediavision/src/MvFaceDetectionTask.cpp @@ -0,0 +1,89 @@ +/** + * 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 +#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 diff --git a/inference/backends/mediavision/src/MvFaceLandmarkDetectionTask.cpp b/inference/backends/mediavision/src/MvFaceLandmarkDetectionTask.cpp new file mode 100644 index 0000000..08dc8dd --- /dev/null +++ b/inference/backends/mediavision/src/MvFaceLandmarkDetectionTask.cpp @@ -0,0 +1,105 @@ +/** + * 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 +#include +#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 diff --git a/inference/backends/mediavision/src/MvFaceTaskManager.cpp b/inference/backends/mediavision/src/MvFaceTaskManager.cpp new file mode 100644 index 0000000..cb2cdad --- /dev/null +++ b/inference/backends/mediavision/src/MvFaceTaskManager.cpp @@ -0,0 +1,53 @@ +/** + * 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 +#include "MvFaceTaskManager.h" + +using namespace std; + +namespace singleo +{ +namespace inference +{ +namespace backends +{ +MvFaceTaskManager::MvFaceTaskManager() : _next(nullptr) +{ + +} + +MvFaceTaskManager::~MvFaceTaskManager() +{ + +} + +shared_ptr MvFaceTaskManager::setNext(shared_ptr 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 diff --git a/inference/include/FaceResult.h b/inference/include/FaceResult.h new file mode 100644 index 0000000..eb7d5b2 --- /dev/null +++ b/inference/include/FaceResult.h @@ -0,0 +1,35 @@ +/** + * 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; +struct FaceResult { + unsigned int _frame_number {}; + std::vector _rects; + std::vector _landmarks; +}; +} // inference +} // singleo + +#endif diff --git a/inference/include/IInferenceFaceService.h b/inference/include/IInferenceFaceService.h new file mode 100644 index 0000000..744f262 --- /dev/null +++ b/inference/include/IInferenceFaceService.h @@ -0,0 +1,41 @@ +/** + * 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 diff --git a/inference/include/IInferenceServiceFactory.h b/inference/include/IInferenceServiceFactory.h new file mode 100644 index 0000000..b24cad3 --- /dev/null +++ b/inference/include/IInferenceServiceFactory.h @@ -0,0 +1,37 @@ +/** + * 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 +#include "IInferenceFaceService.h" +#include "SingleoInferenceTypes.h" + +namespace singleo +{ +namespace inference +{ +class IInferenceServiceFactory +{ +public: + virtual std::unique_ptr createInferenceFaceService(std::vector &tasks) = 0; +}; + +} // inference +} // singleo + +#endif \ No newline at end of file diff --git a/inference/include/MvInferenceFaceService.h b/inference/include/MvInferenceFaceService.h new file mode 100644 index 0000000..f332596 --- /dev/null +++ b/inference/include/MvInferenceFaceService.h @@ -0,0 +1,48 @@ +/** + * 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 +#include "IInferenceFaceService.h" +#include "MvFaceTaskManager.h" + +using namespace singleo::inference::backends; + +namespace singleo +{ +namespace inference +{ +class MvInferenceFaceService : public IInferenceFaceService +{ +private: + std::shared_ptr _taskManager; + FaceResult _result; + +public: + MvInferenceFaceService(std::vector &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 diff --git a/inference/include/MvInferenceServiceFactory.h b/inference/include/MvInferenceServiceFactory.h new file mode 100644 index 0000000..1db0e99 --- /dev/null +++ b/inference/include/MvInferenceServiceFactory.h @@ -0,0 +1,35 @@ +/** + * 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 createInferenceFaceService(std::vector &tasks) override; +}; + +} // inference +} // singleo + +#endif \ No newline at end of file diff --git a/inference/src/MvInferenceFaceService.cpp b/inference/src/MvInferenceFaceService.cpp new file mode 100644 index 0000000..759dff3 --- /dev/null +++ b/inference/src/MvInferenceFaceService.cpp @@ -0,0 +1,81 @@ +/** + * 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 &tasks) +{ + for (auto &task : tasks) { + switch (task) { + case TaskType::FACE_DETECTION: + { + if (_taskManager.use_count() > 0) + _taskManager->setNext(std::make_shared()); + else + _taskManager = std::make_shared(); + } + break; + case TaskType::FACE_LANDMARK_DETECTION: + { + if (_taskManager.use_count() > 0) + _taskManager->setNext(std::make_shared()); + else + _taskManager = std::make_shared(); + } + 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(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 diff --git a/inference/src/MvInferenceServiceFactory.cpp b/inference/src/MvInferenceServiceFactory.cpp new file mode 100644 index 0000000..b7f2967 --- /dev/null +++ b/inference/src/MvInferenceServiceFactory.cpp @@ -0,0 +1,31 @@ +/** + * 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 MvInferenceServiceFactory::createInferenceFaceService(std::vector &tasks) +{ + return make_unique(tasks); +} +} // inference +} // singleo \ No newline at end of file diff --git a/services/smart_pointer/include/GazeEstimator.h b/services/smart_pointer/include/GazeEstimator.h index 4a0439d..09786a8 100644 --- a/services/smart_pointer/include/GazeEstimator.h +++ b/services/smart_pointer/include/GazeEstimator.h @@ -18,7 +18,7 @@ #define __GAZE_ESTIMATOR_H__ #include -#include "IInferenceServiceInterface.h" +#include "IInferenceFaceService.h" #include "IInputService.h" #include "SingleoInferenceTypes.h" #include "PoseVector.h" @@ -32,10 +32,10 @@ namespace smartpointer class GazeEstimator { private: - std::unique_ptr _face_estimator; + std::unique_ptr _face_estimator; std::unique_ptr _input_service; - const std::vector _tasks { inference::TaskType::FACE_DETECTION, inference::TaskType::FACE_LANDMARK_DETECTION }; + std::vector _tasks { inference::TaskType::FACE_DETECTION, inference::TaskType::FACE_LANDMARK_DETECTION }; public: explicit GazeEstimator(input::InputConfigBase &config); diff --git a/services/smart_pointer/src/GazeEstimator.cpp b/services/smart_pointer/src/GazeEstimator.cpp index 7fab6ff..a8b03af 100644 --- a/services/smart_pointer/src/GazeEstimator.cpp +++ b/services/smart_pointer/src/GazeEstimator.cpp @@ -15,7 +15,7 @@ */ #include "GazeEstimator.h" -#include "InferenceServiceMulti.h" +#include "MvInferenceServiceFactory.h" #include "InputCamera.h" #include "SingleoLog.h" @@ -31,7 +31,8 @@ namespace smartpointer { GazeEstimator::GazeEstimator(InputConfigBase& config) { - _face_estimator = make_unique(_tasks); + MvInferenceServiceFactory factory; + _face_estimator = factory.createInferenceFaceService(_tasks); _face_estimator->configure(); _face_estimator->prepare(); @@ -49,13 +50,13 @@ PoseVector GazeEstimator::estimateHeadpose(BaseDataType &input) 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(result); - SINGLEO_LOGD("Landmark: %zd, %zd", - headPose._landmarks[0].x, headPose._landmarks[0].y); + // auto &headPose = dynamic_cast(result); + // SINGLEO_LOGD("Landmark: %zd, %zd", + // headPose._landmarks[0].x, headPose._landmarks[0].y); return PoseVector{-1, -1, -1}; }