From: Hyunsoo Park Date: Wed, 16 Mar 2022 05:12:49 +0000 (+0900) Subject: Tracker internal API sets X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=be95d404f5fbdf8547800a064bc074105c20892f;p=platform%2Fcore%2Fapi%2Fmediavision.git Tracker internal API sets Change-Id: Ia985fd8a03c9cba34ef142856b6fb24f77e9b1b3 Signed-off-by: Hyunsoo Park [Version] 0.20.0-0 [Issue type] new feature --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 464149d4..aaf793e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,8 @@ set(MV_TRAINING_LIB_NAME "mv_training" CACHE STRING "Name of the library will be built for training module (without extension).") set(MV_FACE_RECOG_LIB_NAME "mv_face_recognition" CACHE STRING "Name of the library will be built for face recognition module (without extension).") +set(MV_TRACKER_LIB_NAME "mv_tracker" CACHE STRING + "Name of the library will be built for tracker module (without extension).") include(FindPkgConfig) include(GNUInstallDirs) diff --git a/include/mv_tracker.h b/include/mv_tracker.h new file mode 100644 index 00000000..4edf4cb4 --- /dev/null +++ b/include/mv_tracker.h @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2022 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 __MEDIAVISION_TRACKER_H__ +#define __MEDIAVISION_TRACKER_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @brief Creates tracker handle. + * @details Use this function to create an tracker handle. After the creation + * the handle has to be prepared with mv_tracker_prepare() function to prepare + * tracker resources. + * + * @since_tizen 7.0 + * + * @remarks The @a handle should be released using mv_tracker_destroy(). + * + * @param[out] handle The handle to the tracker to be created + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see mv_tracker_destroy() + */ +int mv_tracker_create(mv_tracker_h *handle, int x, int y, int w, int h); + +/** + * @brief Destroy tracker handle and release all its resources. + * + * @since_tizen 7.0 + * + * @param[in] handle The handle to the tracker object to be destroyed + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre Create tracker handle by using mv_tracker_create() + * + * @see mv_tracker_create() + */ +int mv_tracker_destroy(mv_tracker_h handle); + +/** + * @brief Prepare the resources for tracker. + * @details Use this function to prepare the resources for tracker. + * + * @since_tizen 7.0 + * + * @param[in] handle The handle to the inference + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE Attribute key isn't available + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre Create tracker handle by using mv_tracker_create() + */ +int mv_tracker_prepare(mv_tracker_h handle); + +/** + * @brief Register a new tracker on the @a source + * @details Use this function to register a new tracker. + * Each time when this function is called, a new tracker on the media source + * will be registered to internal database. + * + * @since_tizen 7.0 + * + * @param [in] handle The handle to the tracker object. + * @param [in] source The handle to the source of the media. + * @param [in] label The label to be registered. (the maximum length of the label array is 256 words) + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT Source colorspace + * isn't supported + * + * @pre Prepare an tracker by calling @ref mv_tracker_prepare() + */ +int mv_tracker_register(mv_tracker_h handle, mv_source_h source, const char *label); + +/** + * @brief Unregister a new tracker on the @a source + * @details Use this function to unregister a given label. + * Each time when this function is called, all data related to the label + * will be removed from internal database. + * + * @since_tizen 7.0 + * + * @param [in] handle The handle to the tracker object. + * @param [in] label The label to be unregistered. (the maximum length of the label array is 256 words) + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * + * @pre Register an new tracker by calling @ref mv_tracker_register() + */ +int mv_tracker_unregister(mv_tracker_h handle, const char *label); + +/** + * @brief Inference with a given tracker on the @a source + * @details Use this function to inference with a given source. + * This function returns an proper label string to a give source. + * + * @since_tizen 7.0 + * + * @param [in] handle The handle to the tracker object. + * @param [in] source The handle to the source of the media. + * @param [out] out_result The structure which is filled with inference result, + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT Source colorspace + * isn't supported + * + * @pre Prepare an tracker by calling @ref mv_tracker_prepare() + * @pre Register a new tracker by calling @ref mv_tracker_register() + */ +int mv_tracker_perform(mv_tracker_h handle, mv_source_h source, + mv_tracker_result_s *out_result); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __MEDIAVISION_TRACKER_H__ */ \ No newline at end of file diff --git a/include/mv_tracker_type.h b/include/mv_tracker_type.h new file mode 100644 index 00000000..fabac8f7 --- /dev/null +++ b/include/mv_tracker_type.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 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 __MEDIAVISION_TRACKER_TYPE_H__ +#define __MEDIAVISION_TRACKER_TYPE_H__ + +#include + +#define MAX_LABEL_LEN 128 +#define MAX_LABEL_CNT 100 + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @brief The tracker result structure. + * @details Contains tracker result such as label, label index, raw data + * and raw data count. + * @since_tizen 7.0 + */ +typedef struct { + int coords[4]; + bool isFound; +} mv_tracker_result_s; + +/** + * @brief The tracker handle. + * @details Contains information about location of + * detected landmarks for one or more poses. + * @since_tizen 7.0 + */ +typedef void *mv_tracker_h; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __MEDIAVISION_TRACKER_TYPE_H__ */ diff --git a/inference_engine.ini b/inference_engine.ini new file mode 100644 index 00000000..6de0a603 --- /dev/null +++ b/inference_engine.ini @@ -0,0 +1,3 @@ +[inference backend] +;/*OPENCV=0, Tensorflow-lite=1 +supported backend types = 0,1,2,3,4,5,6 diff --git a/mv_machine_learning/CMakeLists.txt b/mv_machine_learning/CMakeLists.txt index 3e997046..8761db30 100644 --- a/mv_machine_learning/CMakeLists.txt +++ b/mv_machine_learning/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(inference) add_subdirectory(training) add_subdirectory(face_recognition) +add_subdirectory(tracker) diff --git a/mv_machine_learning/tracker/CMakeLists.txt b/mv_machine_learning/tracker/CMakeLists.txt new file mode 100644 index 00000000..9ee1ce65 --- /dev/null +++ b/mv_machine_learning/tracker/CMakeLists.txt @@ -0,0 +1,21 @@ +project(${MV_TRACKER_LIB_NAME}) +cmake_minimum_required(VERSION 2.6) + +pkg_check_modules(${PROJECT_NAME}_DEP REQUIRED inference-engine-interface-common iniparser json-glib-1.0) +file(GLOB MV_TRACKER_SOURCE_LIST "${PROJECT_SOURCE_DIR}/src/*.c" "${PROJECT_SOURCE_DIR}/src/*.cpp") + +find_package(OpenCV REQUIRED dnn imgproc tracking) +if(NOT OpenCV_FOUND) + message(SEND_ERROR "OpenCV NOT FOUND") + return() +endif() + +if(FORCED_STATIC_BUILD) + add_library(${PROJECT_NAME} STATIC ${MV_TRACKER_SOURCE_LIST}) +else() + add_library(${PROJECT_NAME} SHARED ${MV_TRACKER_SOURCE_LIST}) +endif() + +target_link_libraries(${PROJECT_NAME} ${MV_COMMON_LIB_NAME} ${OpenCV_LIBS} ${${PROJECT_NAME}_DEP_LIBRARIES} mv_inference) +target_include_directories(${PROJECT_NAME} PRIVATE include ../inference/include ../common/include) +install(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) diff --git a/mv_machine_learning/tracker/include/mv_tracker_open.h b/mv_machine_learning/tracker/include/mv_tracker_open.h new file mode 100644 index 00000000..8036576e --- /dev/null +++ b/mv_machine_learning/tracker/include/mv_tracker_open.h @@ -0,0 +1,216 @@ +/** + * Copyright (c) 2022 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 __MEDIA_VISION_MV_TRACKER_OPEN_H__ +#define __MEDIA_VISION_MV_TRACKER_OPEN_H__ + +#include +#include +#include "mv_tracker.h" +#include "mv_tracker_type.h" + +/** + * @brief Defines #MV_TRACKER_BACKBONE_MODEL_FILE_PATH + * to set the backbone model file path. + * @details This model file is used to extract the feature vectors from a given face image data. + * + * @since_tizen 7.0 + * @see mv_engine_config_set_string_attribute() + * @see mv_engine_config_get_string_attribute() + */ +#define MV_TRACKER_BACKBONE_MODEL_FILE_PATH "MV_TRACKER_BACKBONE_MODEL_FILE_PATH" + +/** + * @brief Defines #MV_TRACKER_DEFAULT_PATH + * to set the path where the training relevant files are created. + * @details This path is used as a default location where the trained model, label and feature vector files are created. + * + * @since_tizen 7.0 + * @see mv_engine_config_set_string_attribute() + * @see mv_engine_config_get_string_attribute() + */ +#define MV_TRACKER_DEFAULT_PATH "MV_TRACKER_DEFAULT_PATH" + +/** + * @brief Defines #MV_TRACKER_DECISION_THRESHOLD + * to set the decision threshold file+. + * @details This file is used to determine face recognition result with a given face image data is true or false.. + * + * @since_tizen 7.0 + * @see mv_engine_config_set_string_attribute() + * @see mv_engine_config_get_string_attribute() + */ +#define MV_TRACKER_DECISION_THRESHOLD "MV_TRACKER_DECISION_THRESHOLD" + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + + /** + * @brief Create face recognition object handle. + * @details Use this function to create an face recognition object handle. + * After creation the handle has to be prepared with + * @ref mv_tracker_prepare_open() function to prepare + * an face recognition object. + * + * @since_tizen 7.0 + * + * @param [out] handle The handle to the face recognition object to be created + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * + * @post Release @a handle by using + * @ref mv_tracker_destroy_open() function when it is not needed + * anymore + * + * @see mv_tracker_destroy_open() + */ + int mv_tracker_create_open(mv_tracker_h *out_handle, int x, int y, int w, int h); + + /** + * @brief Destroy face recognition handle and releases all its resources. + * + * @since_tizen 7.0 + * + * @param [in] handle The handle to the face recognition object to be destroyed. + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre Create an face recognition handle by using @ref mv_tracker_create_open() + * + * @see mv_tracker_create_open() + */ + int mv_tracker_destroy_open(mv_tracker_h handle); + + /** + * @brief Configure face recognition. + * + * @since_tizen 7.0 + * + * @param [in] handle The handle to the face recognition object created. + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre Create an face recognition handle by using @ref mv_tracker_create_open() + * + * @see mv_tracker_create_open() + */ + int mv_tracker_configure(mv_tracker_h handle); + + /** + * @brief Prepare face recognition. + * + * @since_tizen 7.0 + * + * @param [in] handle The handle to the face recognition object to be prepared. + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre Create an face recognition handle by using @ref mv_tracker_create_open() + * + * @see mv_tracker_create_open() + */ + int mv_tracker_prepare_open(mv_tracker_h handle); + + /** + * @brief Register a new face on the @a source + * @details Use this function to register a new face. + * Each time when this function is called, a new face on the media source + * will be registered to internal database. + * + * @since_tizen 7.0 + * + * @param [in] handle The handle to the face recognition object. + * @param [in] source The handle to the source of the media. + * @param [in] label The label to be registered. (the maximum length of the label array is 256 words) + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT Source colorspace + * isn't supported + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * + * @pre Create a source handle by calling @ref mv_create_source() + * @pre Create an face recognition handle by calling @ref mv_tracker_create_open() + * @pre Prepare an face recognition by calling @ref mv_tracker_prepare_open() + */ + int mv_tracker_register_open(mv_tracker_h handle, mv_source_h source, const char *label); + + /** + * @brief Unregister a new face on the @a source + * @details Use this function to unregister a given label. + * Each time when this function is called, all data related to the label + * will be removed from internal database. + * + * @since_tizen 7.0 + * + * @param [in] handle The handle to the face recognition object. + * @param [in] label The label to be registered. (the maximum length of the label array is 256 words) + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT Source colorspace + * isn't supported + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * + * @pre Create an face recognition handle by calling @ref mv_tracker_create_open() + * @pre Prepare an face recognition by calling @ref mv_tracker_prepare_open() + */ + int mv_tracker_unregister_open(mv_tracker_h handle, const char *label); + + /** + * @brief Inference with a given face on the @a source + * @details Use this function to inference with a given source. + * This function returns an proper label string to a give source. + * + * @since_tizen 7.0 + * + * @param [in] handle The handle to the face recognition object. + * @param [in] source The handle to the source of the media. + * @param [out] out_result The structure which is filled with inference result, + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT Source colorspace + * isn't supported + * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory + * + * @pre Create a source handle by calling @ref mv_create_source() + * @pre Create an face recognition handle by calling @ref mv_tracker_create_open() + * @pre Prepare an face recognition by calling @ref mv_tracker_prepare_open() + * @pre Register a new face by calling @ref mv_tracker_register_open() + */ + int mv_tracker_perform_open(mv_tracker_h handle, mv_source_h source, + mv_tracker_result_s *out_result); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __MEDIA_VISION_INFERENCE_OPEN_H__ */ diff --git a/mv_machine_learning/tracker/include/tracker.h b/mv_machine_learning/tracker/include/tracker.h new file mode 100644 index 00000000..76f1c2e0 --- /dev/null +++ b/mv_machine_learning/tracker/include/tracker.h @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2022 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 __TRACKER_H__ +#define __TRACKER_H__ + +#include "inference_engine_common_impl.h" + +#include +#include +#include +#include + +typedef struct { + double temp; +} TrackerConfig; + +class Tracker { +private: +protected: + bool _initialized; + +public: + // decision_threshold is used to decide correct answer. Correct answer should be bigger than -0.97. + Tracker(); + ~ Tracker(); + + TrackerConfig _config; + cv::Ptr tracker; + cv::Rect boundingBox; + int coords[4]={0,0,0,0}; + bool initialized; +}; + +#endif \ No newline at end of file diff --git a/mv_machine_learning/tracker/src/mv_tracker.c b/mv_machine_learning/tracker/src/mv_tracker.c new file mode 100644 index 00000000..01e6c173 --- /dev/null +++ b/mv_machine_learning/tracker/src/mv_tracker.c @@ -0,0 +1,133 @@ +/** + * Copyright (c) 2022 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 "mv_private.h" +#include "mv_tracker.h" +#include "mv_tracker_open.h" + +int mv_tracker_create(mv_tracker_h *out_handle, int x, int y, int w, int h) +{ + MEDIA_VISION_SUPPORT_CHECK( + __mv_inference_face_check_system_info_feature_supported()); + + MEDIA_VISION_NULL_ARG_CHECK(out_handle); + + MEDIA_VISION_FUNCTION_ENTER(); + + int ret = MEDIA_VISION_ERROR_NONE; + + ret = mv_tracker_create_open(out_handle,x,y,w,h); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_tracker_destroy(mv_tracker_h handle) +{ + MEDIA_VISION_SUPPORT_CHECK( + __mv_inference_face_check_system_info_feature_supported()); + + MEDIA_VISION_INSTANCE_CHECK(handle); + + MEDIA_VISION_FUNCTION_ENTER(); + + int ret = MEDIA_VISION_ERROR_NONE; + + ret = mv_tracker_destroy_open(handle); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_tracker_prepare(mv_tracker_h handle) +{ + MEDIA_VISION_SUPPORT_CHECK( + __mv_inference_face_check_system_info_feature_supported()); + + MEDIA_VISION_INSTANCE_CHECK(handle); + + MEDIA_VISION_FUNCTION_ENTER(); + + int ret = MEDIA_VISION_ERROR_NONE; + + ret = mv_tracker_prepare_open(handle); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_tracker_register(mv_tracker_h handle, mv_source_h source, const char *label) +{ + MEDIA_VISION_SUPPORT_CHECK( + __mv_inference_face_check_system_info_feature_supported()); + + MEDIA_VISION_INSTANCE_CHECK(handle); + MEDIA_VISION_INSTANCE_CHECK(source); + MEDIA_VISION_INSTANCE_CHECK(label); + + MEDIA_VISION_FUNCTION_ENTER(); + + int ret = MEDIA_VISION_ERROR_NONE; + + ret = mv_tracker_register_open(handle, source, label); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_tracker_unregister(mv_tracker_h handle, const char *label) +{ + MEDIA_VISION_SUPPORT_CHECK( + __mv_inference_face_check_system_info_feature_supported()); + + MEDIA_VISION_INSTANCE_CHECK(handle); + MEDIA_VISION_INSTANCE_CHECK(label); + + MEDIA_VISION_FUNCTION_ENTER(); + + int ret = MEDIA_VISION_ERROR_NONE; + + ret = mv_tracker_unregister_open(handle, label); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_tracker_perform(mv_tracker_h handle, mv_source_h source, + mv_tracker_result_s *out_result) +{ + MEDIA_VISION_SUPPORT_CHECK( + __mv_inference_face_check_system_info_feature_supported()); + + MEDIA_VISION_INSTANCE_CHECK(handle); + MEDIA_VISION_INSTANCE_CHECK(source); + MEDIA_VISION_INSTANCE_CHECK(out_result); + + MEDIA_VISION_FUNCTION_ENTER(); + + int ret = MEDIA_VISION_ERROR_NONE; + + ret = mv_tracker_perform_open(handle, source, out_result); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} diff --git a/mv_machine_learning/tracker/src/mv_tracker_open.cpp b/mv_machine_learning/tracker/src/mv_tracker_open.cpp new file mode 100644 index 00000000..95dff8b7 --- /dev/null +++ b/mv_machine_learning/tracker/src/mv_tracker_open.cpp @@ -0,0 +1,227 @@ +/** + * Copyright (c) 2022 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 "tracker.h" +#include "mv_tracker_open.h" + +using namespace std; + +int mv_tracker_create_open(mv_tracker_h *handle, int x, int y, int w, int h) +{ + LOGD("ENTER"); + + //instantiates the specific Tracker + + (*handle) = static_cast(new (std::nothrow) Tracker); + Tracker *pTracker = static_cast(*handle); + pTracker->coords[0] = x; + pTracker->coords[1] = y; + pTracker->coords[2] = w; + pTracker->coords[3] = h; + if (*handle == NULL) { + LOGE("Failed to create tracker handle"); + return MEDIA_VISION_ERROR_OUT_OF_MEMORY; + } + + LOGD("Inference handle [%p] has been created", *handle); + + LOGD("LEAVE"); + return MEDIA_VISION_ERROR_NONE; +} + +int mv_tracker_destroy_open(mv_tracker_h handle) +{ + LOGD("ENTER"); + if (!handle) { + LOGE("Handle can't be destroyed because handle is NULL"); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + LOGD("Destroying tracker handle [%p]", handle); + delete static_cast(handle); + LOGD("Tracker handle has been destroyed"); + + LOGD("LEAVE"); + return MEDIA_VISION_ERROR_NONE; +} + +int mv_tracker_configure(mv_tracker_h handle) +{ + LOGD("ENTER"); + + LOGD("LEAVE"); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_tracker_prepare_open(mv_tracker_h handle) +{ + LOGD("ENTER"); + + LOGD("LEAVE"); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_tracker_register_open(mv_tracker_h handle, mv_source_h source, const char *label) +{ + LOGD("ENTER"); + + LOGD("LEAVE"); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_tracker_unregister_open(mv_tracker_h handle, const char *label) +{ + LOGD("ENTER"); + LOGD("LEAVE"); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_tracker_perform_open(mv_tracker_h handle, mv_source_h source, + mv_tracker_result_s *results) +{ + LOGD("ENTER"); + + if (!handle) { + LOGE("Handle is NULL."); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + Tracker *pTracker = static_cast(handle); + + cv::Mat frame; + cv::Mat image; + int depth = CV_8U; /* Default depth. 1 byte for channel. */ + unsigned int channelsNumber = 0; + unsigned int width = 0, height = 0; + unsigned int bufferSize = 0; + unsigned char *buffer = NULL; + mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID; + + MEDIA_VISION_ASSERT(mv_source_get_width(source, &width), + "Failed to get the width."); + MEDIA_VISION_ASSERT(mv_source_get_height(source, &height), + "Failed to get the height."); + MEDIA_VISION_ASSERT(mv_source_get_colorspace(source, &colorspace), + "Failed to get the colorspace."); + MEDIA_VISION_ASSERT(mv_source_get_buffer(source, &buffer, &bufferSize), + "Failed to get the buffer size."); + + int conversionType = -1; /* Type of conversion from given colorspace to gray */ + switch(colorspace) { + case MEDIA_VISION_COLORSPACE_Y800: + channelsNumber = 1; + /* Without convertion */ + break; + case MEDIA_VISION_COLORSPACE_I420: + channelsNumber = 1; + height *= 1.5; + conversionType = cv::COLOR_YUV2GRAY_I420; + break; + case MEDIA_VISION_COLORSPACE_NV12: + channelsNumber = 1; + height *= 1.5; + conversionType = cv::COLOR_YUV2GRAY_NV12; + break; + case MEDIA_VISION_COLORSPACE_YV12: + channelsNumber = 1; + height *= 1.5; + conversionType = cv::COLOR_YUV2GRAY_YV12; + break; + case MEDIA_VISION_COLORSPACE_NV21: + channelsNumber = 1; + height *= 1.5; + conversionType = cv::COLOR_YUV2GRAY_NV21; + break; + case MEDIA_VISION_COLORSPACE_YUYV: + channelsNumber = 2; + conversionType = cv::COLOR_YUV2GRAY_YUYV; + break; + case MEDIA_VISION_COLORSPACE_UYVY: + channelsNumber = 2; + conversionType = cv::COLOR_YUV2GRAY_UYVY; + break; + case MEDIA_VISION_COLORSPACE_422P: + channelsNumber = 2; + conversionType = cv::COLOR_YUV2GRAY_Y422; + break; + case MEDIA_VISION_COLORSPACE_RGB565: + channelsNumber = 2; + conversionType = cv::COLOR_BGR5652GRAY; + break; + case MEDIA_VISION_COLORSPACE_RGB888: + channelsNumber = 3; + conversionType = cv::COLOR_RGB2GRAY; + break; + case MEDIA_VISION_COLORSPACE_RGBA: + channelsNumber = 4; + conversionType = cv::COLOR_RGBA2GRAY; + break; + default: + LOGE("Error: mv_source has unsupported colorspace."); + return MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT; + } + + LOGD(" w: %d, h: %d, d: %d, c: %d", width, height, depth, channelsNumber); + frame = cv::Mat(cv::Size(width, height), + CV_MAKETYPE(depth, channelsNumber), buffer).clone(); + + if( !pTracker->initialized ) + { + //initializes the tracker + pTracker->boundingBox.x = pTracker->coords[0]; + pTracker->boundingBox.y = pTracker->coords[1]; + pTracker->boundingBox.width = pTracker->coords[2]; + pTracker->boundingBox.height = pTracker->coords[3]; + + pTracker->tracker->init(frame, pTracker->boundingBox); + pTracker->initialized = true; + results->coords[0] = pTracker->boundingBox.x; + results->coords[1] = pTracker->boundingBox.y ; + results->coords[2] = pTracker->boundingBox.width + results->coords[0]; + results->coords[3] = pTracker->boundingBox.height + results->coords[1]; + results->isFound = true; + } + else if( pTracker->initialized ) + { + LOGD(" pTracker->initialized "); + //updates the tracker + if( pTracker->tracker->update(frame, pTracker->boundingBox) ) + { + LOGD(" pTracker->tracker->update "); + //rectangle( image, boundingBox, Scalar( 255, 0, 0 ), 2, 1 ); + results->coords[0] = pTracker->boundingBox.x; + results->coords[1] = pTracker->boundingBox.y ; + results->coords[2] = pTracker->boundingBox.width + results->coords[0]; + results->coords[3] = pTracker->boundingBox.height + results->coords[1]; + results->isFound = true; + } + else { + results->isFound = false; + LOGD("update failed."); + } + } + + LOGD("LEAVE"); + + return MEDIA_VISION_ERROR_NONE; +} diff --git a/mv_machine_learning/tracker/src/tracker.cpp b/mv_machine_learning/tracker/src/tracker.cpp new file mode 100644 index 00000000..673fcf69 --- /dev/null +++ b/mv_machine_learning/tracker/src/tracker.cpp @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2022 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 +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include "tracker.h" + +using namespace std; + +Tracker::Tracker() +{ + tracker = cv::TrackerKCF::create(); + coords[0]={0}; + coords[1]={0}; + coords[2]={0}; + coords[3]={0}; + initialized = false; +} + +Tracker::~Tracker() +{ +} \ No newline at end of file diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 9cc6c0d9..800b1c3b 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -1,6 +1,6 @@ Name: capi-media-vision Summary: Media Vision library for Tizen Native API -Version: 0.18.0 +Version: 0.20.0 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause @@ -305,9 +305,11 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj/%{name} %{_libdir}/libmv_inference*.so %{_libdir}/libmv_training.so %{_libdir}/libmv_face_recognition.so +%{_libdir}/libmv_tracker.so %files machine_learning-devel %{_includedir}/media/mv_infer*.h +%{_includedir}/media/mv_tracker*.h %{_libdir}/pkgconfig/*inference.pc %{_libdir}/pkgconfig/*training.pc %{_libdir}/pkgconfig/*face-recognition.pc diff --git a/test/testsuites/machine_learning/CMakeLists.txt b/test/testsuites/machine_learning/CMakeLists.txt index 14ddb418..dcdbac62 100644 --- a/test/testsuites/machine_learning/CMakeLists.txt +++ b/test/testsuites/machine_learning/CMakeLists.txt @@ -2,4 +2,5 @@ project(machine_learning) cmake_minimum_required(VERSION 2.6) add_subdirectory(${PROJECT_SOURCE_DIR}/inference) -add_subdirectory(${PROJECT_SOURCE_DIR}/face_recognition) \ No newline at end of file +add_subdirectory(${PROJECT_SOURCE_DIR}/face_recognition) +add_subdirectory(${PROJECT_SOURCE_DIR}/tracker) diff --git a/test/testsuites/machine_learning/tracker/CMakeLists.txt b/test/testsuites/machine_learning/tracker/CMakeLists.txt new file mode 100644 index 00000000..8a6b37cc --- /dev/null +++ b/test/testsuites/machine_learning/tracker/CMakeLists.txt @@ -0,0 +1,12 @@ +project(mv_tracker_test_suite) +cmake_minimum_required(VERSION 2.6) + +add_executable(${PROJECT_NAME} test_tracker.cpp) + +target_link_libraries(${PROJECT_NAME} gtest gtest_main + mv_tracker + mv_image_helper + mv_video_helper + mv_testsuite_common) + +install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) \ No newline at end of file diff --git a/test/testsuites/machine_learning/tracker/test_tracker.cpp b/test/testsuites/machine_learning/tracker/test_tracker.cpp new file mode 100644 index 00000000..074413b9 --- /dev/null +++ b/test/testsuites/machine_learning/tracker/test_tracker.cpp @@ -0,0 +1,153 @@ +/** + * Copyright (c) 2021 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 + +#include "gtest/gtest.h" + +#include "ImageHelper.h" +#include "mv_tracker.h" + +using namespace testing; +using namespace std; +using namespace MediaVision::Common; + +TEST(TrackerTest, TrackerClassShouldBeOk) +{ + // mv_tracker_h handle; + int ret = MEDIA_VISION_ERROR_NONE; + // // int ret = mv_tracker_create(&handle,1,2,3,4); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + // ret = mv_tracker_prepare(handle); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + // // for (auto& image : training_images) { + // // const string image_path = string("/usr/share/capi-media-vision/face-recognition/images/training/") + image.first; + // const string image_path = string("/usr/share/capi-media-vision/face-recognition/images/training/"); + // mv_source_h mv_source = NULL; + + // ret = mv_create_source(&mv_source); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + // ret = ImageHelper::loadImageToSource(image_path.c_str(), mv_source); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + // // ret = mv_tracker_register(handle, mv_source, image.second.c_str()); + // ASSERT_EQ(ret, 0); + + // ret = mv_destroy_source(mv_source); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + // // } + + // // unsigned int image_idx = 0; + + // // for (auto& image : test_images) { + // // const string image_path = string("/usr/share/capi-media-vision/face-recognition/images/test/") + image.first; + + // ret = mv_create_source(&mv_source); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + // ret = ImageHelper::loadImageToSource(image_path.c_str(), mv_source); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + // mv_tracker_result_s result; + + // ret = mv_tracker_perform(handle, mv_source, &result); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + // ret = mv_destroy_source(mv_source); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + // // ASSERT_EQ(answers[image_idx++], string(result.label)); + // //} + + // ret = mv_tracker_destroy(handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); +} + +TEST(FaceRecognitionTest, FaceRecognitionClassWithEachLabelRemovalShouldBeOk) +{ + int ret = MEDIA_VISION_ERROR_NONE; + // mv_tracker_h handle; + // // int ret = mv_tracker_create(&handle,1,2,3,4); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + // ret = mv_tracker_prepare(handle); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + // // auto& answer = answers[label_idx++]; + // // unsigned int image_idx = 0; + + // // for (auto& image : training_images) { + // // const string image_path = string("/usr/share/capi-media-vision/face-recognition/images/training/") + image.first; + // const string image_path = string("/usr/share/capi-media-vision/face-recognition/images/training/"); + // mv_source_h mv_source = NULL; + // ret = mv_create_source(&mv_source); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + // ret = ImageHelper::loadImageToSource(image_path.c_str(), mv_source); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + // // ret = mv_tracker_register(handle, mv_source, image.second.c_str()); + // ASSERT_EQ(ret, 0); + + // ret = mv_destroy_source(mv_source); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + // // } + + + // // if (!label.empty()) { + // // ret = mv_tracker_unregister(handle, label.c_str()); + // // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + // // } + + // // for (auto& image : test_images) { + // // const string image_path = string("/usr/share/capi-media-vision/face-recognition/images/test/") + image.first; + + // ret = mv_create_source(&mv_source); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + // ret = ImageHelper::loadImageToSource(image_path.c_str(), mv_source); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + // mv_tracker_result_s result; + + // ret = mv_tracker_perform(handle, mv_source, &result); + // if (ret == MEDIA_VISION_ERROR_NO_DATA) { + // // strcpy(result.label, "none"); + // ret = MEDIA_VISION_ERROR_NONE; + // } + + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + // ret = mv_destroy_source(mv_source); + // ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + // // ASSERT_EQ(answer[image_idx++], string(result.label)); + // // } + + // // ret = mv_tracker_destroy(handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); +} + +int main(int argc, char **argv) +{ + InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}