"Name of the library will be built for tracker module (without extension).")
set(MV_OBJECT_DETECTION_LIB_NAME "mv_object_detection" CACHE STRING
"Name of the library will be built for object detection module (without extension).")
+set(MV_OBJECT_DETECTION_3D_LIB_NAME "mv_object_detection_3d" CACHE STRING
+ "Name of the library will be built for object detection 3d module (without extension).")
set(MV_IMAGE_CLASSIFICATION_LIB_NAME "mv_image_classification" CACHE STRING
"Name of the library will be built for image classification module (without extension).")
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}-object-detection.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mv_machine_learning/object_detection/meta/object_detection.json DESTINATION ${CMAKE_INSTALL_DATADIR}/${fw_name})
+set(PC_NAME ${fw_name}-object-detection-3d)
+set(PC_LDFLAGS "-l${MV_OBJECT_DETECTION_3D_LIB_NAME} -l${MV_COMMON_LIB_NAME}")
+configure_file(
+ ${fw_name}.pc.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}-object-detection-3d.pc
+ @ONLY
+)
+install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}-object-detection-3d.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mv_machine_learning/object_detection_3d/meta/object_detection_3d.json DESTINATION ${CMAKE_INSTALL_DATADIR}/${fw_name})
+
set(PC_NAME ${fw_name}-image-classification)
set(PC_LDFLAGS "-l${MV_IMAGE_CLASSIFICATION_LIB_NAME} -l${MV_COMMON_LIB_NAME}")
configure_file(
--- /dev/null
+/*
+ * 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 __TIZEN_MEDIAVISION_OBJECT_DETECT_3D_INTERNAL_H__
+#define __TIZEN_MEDIAVISION_OBJECT_DETECT_3D_INTERNAL_H__
+
+#include <mv_common.h>
+#include <mv_object_detection_3d_type.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @file mv_object_detection_3d.h
+ * @brief This file contains the Inference based Media Vision API.
+ */
+
+/**
+ * @addtogroup CAPI_MEDIA_VISION_INFERENCE_MODULE
+ * @{
+ */
+
+/**
+ * @brief Creates a inference handle for object detection 3d object.
+ * @details Use this function to create a inference handle. After the creation
+ * the object detection 3d task has to be prepared with
+ * mv_object_detection_3d_prepare() function to prepare a network
+ * for the inference.
+ *
+ * @since_tizen 7.0
+ *
+ * @remarks The @a infer should be released using mv_object_detection_3d_destroy().
+ *
+ * @param[out] infer The handle to the inference to be created.
+ *
+ * @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_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @see mv_object_detection_3d_destroy()
+ * @see mv_object_detection_3d_prepare()
+ */
+int mv_object_detection_3d_create(mv_object_detection_3d_h *infer);
+
+/**
+ * @brief Destroys inference handle and releases all its resources.
+ *
+ * @since_tizen 7.0
+ *
+ * @param[in] infer The handle to the inference to be destroyed.
+ *
+ * @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_INVALID_PARAMETER Invalid parameter
+ *
+ * @pre Create inference handle by using mv_object_detection_3d_create()
+ *
+ * @see mv_object_detection_3d_create()
+ */
+int mv_object_detection_3d_destroy(mv_object_detection_3d_h infer);
+
+/**
+ * @brief Configures the backend for the object detection inference.
+ *
+ * @since_tizen 7.0
+ *
+ * @param [in] infer 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_OUT_OF_MEMORY Out of memory
+ * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported
+ */
+int mv_object_detection_3d_configure(mv_object_detection_3d_h infer);
+
+/**
+ * @brief Prepares the object detection inference
+ * @details Use this function to prepare the object detection inference based on
+ * the configured network.
+ *
+ * @since_tizen 7.0
+ *
+ * @param[in] infer 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_PERMISSION_DENIED Permission denied
+ * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_VISION_ERROR_INVALID_DATA Invalid model data
+ * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT Not supported format
+ */
+int mv_object_detection_3d_prepare(mv_object_detection_3d_h infer);
+
+/**
+ * @brief Performs the object detection 3d inference on the @a source.
+ *
+ * @since_tizen 7.0
+ * @remarks This function is synchronous and may take considerable time to run.
+ *
+ * @param[in] source The handle to the source of the media
+ * @param[in] infer 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_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_VISION_ERROR_INTERNAL Internal error
+ * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT Source colorspace
+ * isn't supported
+ *
+ * @pre Create a source handle by calling mv_create_source()
+ * @pre Create an inference handle by calling mv_object_detect_3d_create()
+ * @pre Prepare an inference by calling mv_object_detect_3d_prepare()
+ * @post
+ *
+ * @see mv_object_detect_result_s structure
+ */
+int mv_object_detection_3d_inference(mv_object_detection_3d_h infer, mv_source_h source);
+
+/**
+ * @brief Gets the probability value to the detected object.
+ * @details Use this function to get the probability value after calling @ref mv_object_detection_3d_inference().
+ *
+ * @since_tizen 7.0
+ *
+ * @remarks The @a result must NOT be released using free()
+ *
+ * @param[in] handle The handle to the face recognition object.
+ * @param[out] out_probability A pointer to probability array.
+ *
+ * @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_INVALID_OPERATION Invalid operation
+ *
+ * @pre Request an inference by calling @ref mv_object_detection_3d_inference()
+ */
+int mv_object_detection_3d_get_probability(mv_object_detection_3d_h handle, unsigned int *out_probability);
+
+/**
+ * @brief Gets the number of points to the 3D bounding box of the detected object.
+ * @details Use this function to get the number of points after calling @ref mv_object_detection_3d_inference().
+ *
+ * @since_tizen 7.0
+ *
+ * @remarks The @a result must NOT be released using free()
+ *
+ * @param[in] handle The handle to the face recognition object.
+ * @param[out] out_num_of_points Number of points.
+ *
+ * @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_INVALID_OPERATION Invalid operation
+ *
+ * @pre Request an inference by calling @ref mv_object_detection_3d_inference()
+ */
+int mv_object_detection_3d_get_num_of_points(mv_object_detection_3d_h handle, unsigned int *out_num_of_points);
+
+/**
+ * @brief Gets the x and y coordinates values to the 3D bounding box of the detected object.
+ * @details Use this function to get the coordinates values after calling @ref mv_object_detection_3d_inference().
+ *
+ * @since_tizen 7.0
+ *
+ * @remarks The @a result must NOT be released using free()
+ *
+ * @param[in] handle The handle to the face recognition object.
+ * @param[out] out_x A pointer to x coordinates array.
+ * @param[out] out_y A pointer to y coordinates array.
+ *
+ * @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_INVALID_OPERATION Invalid operation
+ *
+ * @pre Request an inference by calling @ref mv_object_detection_3d_inference()
+ */
+int mv_object_detection_3d_get_points(mv_object_detection_3d_h handle, unsigned int **out_x, unsigned int **out_y);
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __TIZEN_MEDIAVISION_OBJECT_DETECT_3D_INTERNAL_H__ */
--- /dev/null
+/*
+ * 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 __TIZEN_MEDIAVISION_MV_OBJECT_DETECTION_3D_TYPE_H__
+#define __TIZEN_MEDIAVISION_MV_OBJECT_DETECTION_3D_TYPE_H__
+
+#include <mv_common.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @file mv_object_detection_3d_type.h
+ * @brief This file contains the object detection 3d handle for Mediavision.
+ */
+
+/**
+ * @addtogroup CAPI_MEDIA_VISION_OBJECT_DETECT_3D_MODULE
+ * @{
+ */
+
+/**
+ * @brief The object detection 3d handle.
+ *
+ * @since_tizen 7.0
+ */
+typedef void *mv_object_detection_3d_h;
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __TIZEN_MEDIAVISION_MV_OBJECT_DETECTION_3D_TYPE_H__ */
*/
int mv_object_detection_inference(mv_object_detection_h infer, mv_source_h source);
-/**
- * @brief Gets the probability value to the detected object.
- * @details Use this function to get the probability value after calling @ref mv_object_detection_inference().
- *
- * @since_tizen 7.0
- *
- * @remarks The @a result must NOT be released using free()
- *
- * @param[in] handle The handle to the face recognition object.
- * @param[out] out_probability A pointer to probability array.
- *
- * @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_INVALID_OPERATION Invalid operation
- *
- * @pre Request an inference by calling @ref mv_object_detection_inference()
- */
-int mv_object_detection_3d_get_probability(mv_object_detection_h handle, unsigned int *out_probability);
-
-/**
- * @brief Gets the number of points to the 3D bounding box of the detected object.
- * @details Use this function to get the number of points after calling @ref mv_object_detection_inference().
- *
- * @since_tizen 7.0
- *
- * @remarks The @a result must NOT be released using free()
- *
- * @param[in] handle The handle to the face recognition object.
- * @param[out] out_num_of_points Number of points.
- *
- * @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_INVALID_OPERATION Invalid operation
- *
- * @pre Request an inference by calling @ref mv_object_detection_inference()
- */
-int mv_object_detection_3d_get_num_of_points(mv_object_detection_h handle, unsigned int *out_num_of_points);
-
-/**
- * @brief Gets the x and y coordinates values to the 3D bounding box of the detected object.
- * @details Use this function to get the coordinates values after calling @ref mv_object_detection_inference().
- *
- * @since_tizen 7.0
- *
- * @remarks The @a result must NOT be released using free()
- *
- * @param[in] handle The handle to the face recognition object.
- * @param[out] out_x A pointer to x coordinates array.
- * @param[out] out_y A pointer to y coordinates array.
- *
- * @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_INVALID_OPERATION Invalid operation
- *
- * @pre Request an inference by calling @ref mv_object_detection_inference()
- */
-int mv_object_detection_3d_get_points(mv_object_detection_h handle, unsigned int **out_x, unsigned int **out_y);
-/**
- * @}
- */
-
#ifdef __cplusplus
}
#endif /* __cplusplus */
add_subdirectory(inference)
add_subdirectory(image_classification)
add_subdirectory(object_detection)
+add_subdirectory(object_detection_3d)
if (${ENABLE_ML_FACE_RECOGNITION})
message("Enabled machine learning face recognition feature.")
* limitations under the License.
*/
-#ifndef __OBJECTRON_H__
-#define __OBJECTRON_H__
+#ifndef __MOBILENET_SSD_H__
+#define __MOBILENET_SSD_H__
+#include <string>
#include <memory>
#include <mv_common.h>
#include "mv_private.h"
{
namespace machine_learning
{
-class Objectron : public ObjectDetection
+class MobilenetSsd : public ObjectDetection
{
private:
object_detection_result_s _result;
public:
- Objectron();
- ~Objectron();
+ MobilenetSsd();
+ ~MobilenetSsd();
+
object_detection_result_s &result() override;
};
*/
#define MV_OBJECT_DETECTION_MODEL_META_FILE_PATH "META_FILE_NAME"
+#define MV_OBJECT_DETECTION_LABEL_FILE_NAME "LABEL_FILE_NAME"
+
/**
* @brief Defines #MV_OBJECT_DETECT_BACKEND_TYPE
* to set inference backend engine type. In default, tensorflow lite is used.
*/
#define MV_OBJECT_DETECTION_TARGET_DEVICE_TYPE "TARGET_DEVICE_TYPE"
-#define MV_OBJECT_DETECTION_3D_MAX_NUM_OF_POINTS "MAX_NUM_OF_POINTS"
-
-#define MV_OBJECT_DETECTION_3D_MAX_NUM_OF_EDGES "MAX_NUM_OF_EDGES"
-
#define MV_OBJECT_DETECTION_META_FILE_NAME "object_detection.json"
#endif /* __MEDIA_VISION_INFERENCE_OPEN_H__ */
#endif /* __cplusplus */
/**
- * @brief Create face recognition object handle.
- * @details Use this function to create an face recognition object handle.
+ * @brief Create object detection object handle.
+ * @details Use this function to create an object detection object handle.
* After creation the handle has to be prepared with
* @ref mv_object_detection_prepare_open() function to prepare
- * an face recognition object.
+ * an object detection object.
*
* @since_tizen 7.0
*
- * @param[out] out_handle The handle to the face recognition object to be created
+ * @param[out] out_handle The handle to the object detection object to be created
*
* @return @c 0 on success, otherwise a negative error value
* @retval #MEDIA_VISION_ERROR_NONE Successful
int mv_object_detection_create_open(mv_object_detection_h *out_handle);
/**
- * @brief Destroy face recognition handle and releases all its resources.
+ * @brief Destroy object detection handle and releases all its resources.
*
* @since_tizen 7.0
*
- * @param[in] handle The handle to the face recognition object to be destroyed.
+ * @param[in] handle The handle to the object detection 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_object_detection_create_open()
+ * @pre Create an object detection handle by using @ref mv_object_detection_create_open()
*
* @see mv_object_detection_create_open()
*/
*
* @since_tizen 7.0
*
- * @param[in] handle The handle to the face recognition object.
+ * @param[in] handle The handle to the object detection object.
* @param[in] source The handle to the source of the media.
*
* @return @c 0 on success, otherwise a negative error value
* @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_object_detection_create_open()
- * @pre Prepare an face recognition by calling @ref mv_object_detection_prepare_open()
+ * @pre Create an object detection handle by calling @ref mv_object_detection_create_open()
+ * @pre Prepare an object detection by calling @ref mv_object_detection_prepare_open()
* @pre Register a new face by calling @ref mv_object_detection_register_open()
*/
int mv_object_detection_inference_open(mv_object_detection_h handle, mv_source_h source);
-/**
- * @brief Gets the probability value to the detected object.
- * @details Use this function to get the probability value after calling @ref mv_object_detection_inference().
- *
- * @since_tizen 7.0
- *
- * @remarks The @a result must NOT be released using free()
- *
- * @param[in] handle The handle to the face recognition object.
- * @param[out] out_probability A pointer to probability array.
- *
- * @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_INVALID_OPERATION Invalid operation
- *
- * @pre Request an inference by calling @ref mv_object_detection_inference()
- */
-int mv_object_detection_3d_get_probability_open(mv_object_detection_h handle, unsigned int *out_probability);
-
-/**
- * @brief Gets the number of points to the 3D bounding box of the detected object.
- * @details Use this function to get the number of points after calling @ref mv_object_detection_inference().
- *
- * @since_tizen 7.0
- *
- * @remarks The @a result must NOT be released using free()
- *
- * @param[in] handle The handle to the face recognition object.
- * @param[out] out_num_of_points Number of points.
- *
- * @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_INVALID_OPERATION Invalid operation
- *
- * @pre Request an inference by calling @ref mv_object_detection_3d_inference()
- */
-int mv_object_detection_3d_get_num_of_points_open(mv_object_detection_h handle, unsigned int *out_num_of_points);
-
-/**
- * @brief Gets the x and y coordinates values to the 3D bounding box of the detected object.
- * @details Use this function to get the coordinates values after calling @ref mv_object_detection_inference().
- *
- * @since_tizen 7.0
- *
- * @remarks The @a result must NOT be released using free()
- *
- * @param[in] handle The handle to the face recognition object.
- * @param[out] out_x A pointer to x coordinates array.
- * @param[out] out_y A pointer to y coordinates array.
- *
- * @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_INVALID_OPERATION Invalid operation
- *
- * @pre Request an inference by calling @ref mv_object_detection_inference()
- */
-int mv_object_detection_3d_get_points_open(mv_object_detection_h handle, unsigned int **out_x, unsigned int **out_y);
-
#ifdef __cplusplus
}
#endif /* __cplusplus */
Preprocess _preprocess;
std::string _modelFilePath;
std::string _modelMetaFilePath;
+ std::string _modelDefaultPath;
+ std::string _modelLabelFilePath;
int _backendType;
int _targetDeviceType;
#include "EngineConfig.h"
#include "itask.h"
-#include "objectron.h"
+#include "mobilenet_ssd.h"
namespace mediavision
{
mv_source_h inference_src;
};
-struct edge_index_s {
- unsigned int start;
- unsigned int end;
-};
-
/**
* @brief The object detection result structure.
* @details Contains object detection result.
*/
struct object_detection_result_s {
- unsigned int probability;
- unsigned int number_of_points;
std::vector<unsigned int> x_vec;
std::vector<unsigned int> y_vec;
- unsigned int number_of_edges;
- std::vector<edge_index_s> edge_index_vec;
};
enum class object_detection_task_type_e {
OBJECT_DETECTION_TASK_NONE = 0,
- OBJECTRON
+ MOBILENET_SSD_V1
// TODO
};
"value" : "/usr/share/capi-media-vision/models/OD/tflite/"
},
{
- "name" : "OBJECT_NAME",
- "type" : "string",
- "value" : "cup"
- },
- {
"name" : "MODEL_FILE_NAME",
"type" : "string",
- "value" : "object_detection_3d_cup.tflite"
+ "value" : "od_mobilenet_v1_ssd_postop_300x300.tflite"
},
- {
+ {
"name" : "META_FILE_NAME",
"type" : "string",
- "value" : "object_detection_3d_cup.json"
+ "value" : "od_mobilenet_v1_ssd_postop_300x300.json"
+ },
+ {
+ "name" : "LABEL_FILE_NAME",
+ "type" : "string",
+ "value" : "od_mobilenet_v1_ssd_postop_label.txt"
},
{
"name" : "BACKEND_TYPE",
--- /dev/null
+/**
+ * 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 <string.h>
+#include <map>
+#include <algorithm>
+
+#include "machine_learning_exception.h"
+#include "mv_object_detection_config.h"
+#include "mobilenet_ssd.h"
+#include "Postprocess.h"
+
+using namespace std;
+using namespace mediavision::inference;
+using namespace mediavision::machine_learning::exception;
+
+namespace mediavision
+{
+namespace machine_learning
+{
+MobilenetSsd::MobilenetSsd() : _result()
+{}
+
+MobilenetSsd::~MobilenetSsd()
+{}
+
+object_detection_result_s &MobilenetSsd::result()
+{
+ vector<string> names;
+
+ ObjectDetection::getOutputNames(names);
+
+ vector<float> output_tensor;
+
+ ObjectDetection::getOutputTensor(names[1], output_tensor);
+
+ // TODO.
+
+ return _result;
+}
+
+}
+}
MEDIA_VISION_FUNCTION_LEAVE();
return ret;
-}
-
-int mv_object_detection_3d_get_probability(mv_object_detection_h handle, unsigned int *out_probability)
-{
- MEDIA_VISION_SUPPORT_CHECK(_mv_inference_face_check_system_info_feature_supported());
-
- MEDIA_VISION_INSTANCE_CHECK(handle);
- MEDIA_VISION_NULL_ARG_CHECK(out_probability);
-
- MEDIA_VISION_FUNCTION_ENTER();
-
- int ret = MEDIA_VISION_ERROR_NONE;
-
- ret = mv_object_detection_3d_get_probability_open(handle, out_probability);
-
- MEDIA_VISION_FUNCTION_LEAVE();
-
- return ret;
-}
-
-int mv_object_detection_3d_get_num_of_points(mv_object_detection_h handle, unsigned int *out_num_of_points)
-{
- MEDIA_VISION_SUPPORT_CHECK(_mv_inference_face_check_system_info_feature_supported());
-
- MEDIA_VISION_INSTANCE_CHECK(handle);
- MEDIA_VISION_NULL_ARG_CHECK(out_num_of_points);
-
- MEDIA_VISION_FUNCTION_ENTER();
-
- int ret = MEDIA_VISION_ERROR_NONE;
-
- ret = mv_object_detection_3d_get_num_of_points_open(handle, out_num_of_points);
-
- MEDIA_VISION_FUNCTION_LEAVE();
-
- return ret;
-}
-
-int mv_object_detection_3d_get_points(mv_object_detection_h handle, unsigned int **out_x, unsigned int **out_y)
-{
- MEDIA_VISION_SUPPORT_CHECK(_mv_inference_face_check_system_info_feature_supported());
-
- MEDIA_VISION_INSTANCE_CHECK(handle);
- MEDIA_VISION_NULL_ARG_CHECK(out_x);
- MEDIA_VISION_NULL_ARG_CHECK(out_y);
-
- MEDIA_VISION_FUNCTION_ENTER();
-
- int ret = MEDIA_VISION_ERROR_NONE;
-
- ret = mv_object_detection_3d_get_points_open(handle, out_x, out_y);
-
- MEDIA_VISION_FUNCTION_LEAVE();
-
- return ret;
-}
+}
\ No newline at end of file
return MEDIA_VISION_ERROR_INVALID_PARAMETER;
}
- Context *context = new (nothrow) Context();
- if (!context) {
- LOGE("Fail to allocate a context.");
- return MEDIA_VISION_ERROR_OUT_OF_MEMORY;
- }
-
- ObjectDetectionTask *task = new (nothrow)
- ObjectDetectionAdapter<object_detection_input_s, object_detection_result_s>();
- if (!task) {
- delete context;
- LOGE("Fail to allocate a task.");
- return MEDIA_VISION_ERROR_OUT_OF_MEMORY;
- }
+ Context *context = nullptr;
+ ObjectDetectionTask *task = nullptr;
try {
- task->create(static_cast<int>(object_detection_task_type_e::OBJECTRON));
+ context = new Context();
+ task = new ObjectDetectionAdapter<object_detection_input_s, object_detection_result_s>();
+ task->create(static_cast<int>(object_detection_task_type_e::MOBILENET_SSD_V1));
+
+ context->__tasks.insert(make_pair("object_detection", task));
+ *out_handle = static_cast<mv_object_detection_h>(context);
} catch (const BaseException &e) {
+ delete task;
+ delete context;
return e.getError();
}
- context->__tasks.insert(make_pair("object_detection", task));
- *out_handle = static_cast<mv_object_detection_h>(context);
-
LOGD("object detection 3d handle [%p] has been created", *out_handle);
return MEDIA_VISION_ERROR_NONE;
LOGD("LEAVE");
return MEDIA_VISION_ERROR_NONE;
-}
-
-int mv_object_detection_3d_get_probability_open(mv_object_detection_h handle, unsigned int *out_probability)
-{
- LOGD("ENTER");
-
- if (!handle) {
- LOGE("Handle is NULL.");
- return MEDIA_VISION_ERROR_INVALID_PARAMETER;
- }
-
- try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<ObjectDetectionTask *>(context->__tasks.at("object_detection"));
-
- object_detection_result_s &result = task->getOutput();
-
- *out_probability = result.probability;
- } catch (const BaseException &e) {
- LOGE("%s", e.what());
- return e.getError();
- }
-
- LOGD("LEAVE");
-
- return MEDIA_VISION_ERROR_NONE;
-}
-
-int mv_object_detection_3d_get_num_of_points_open(mv_object_detection_h handle, unsigned int *out_num_of_points)
-{
- LOGD("ENTER");
-
- if (!handle) {
- LOGE("Handle is NULL.");
- return MEDIA_VISION_ERROR_INVALID_PARAMETER;
- }
-
- try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<ObjectDetectionTask *>(context->__tasks.at("object_detection"));
-
- object_detection_result_s &result = task->getOutput();
-
- *out_num_of_points = result.number_of_points;
- } catch (const BaseException &e) {
- LOGE("%s", e.what());
- return e.getError();
- }
-
- LOGD("LEAVE");
-
- return MEDIA_VISION_ERROR_NONE;
-}
-
-int mv_object_detection_3d_get_points_open(mv_object_detection_h handle, unsigned int **out_x, unsigned int **out_y)
-{
- LOGD("ENTER");
-
- if (!handle) {
- LOGE("Handle is NULL.");
- return MEDIA_VISION_ERROR_INVALID_PARAMETER;
- }
-
- try {
- Context *context = static_cast<Context *>(handle);
- auto task = static_cast<ObjectDetectionTask *>(context->__tasks.at("object_detection"));
-
- object_detection_result_s &result = task->getOutput();
-
- *out_x = result.x_vec.data();
- *out_y = result.y_vec.data();
-
- for (auto &edge : result.edge_index_vec)
- LOGI("%d,%d ", edge.start, edge.end);
-
- for (unsigned int i = 0; i < result.number_of_points; ++i)
- LOGI("%d %d", (*out_x)[i], (*out_y)[i]);
- } catch (const BaseException &e) {
- LOGE("%s", e.what());
- return e.getError();
- }
-
- LOGD("LEAVE");
-
- return MEDIA_VISION_ERROR_NONE;
}
\ No newline at end of file
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to get target device type.");
- string modelDefaultPath;
-
- ret = _config->getStringAttribute(MV_OBJECT_DETECTION_MODEL_DEFAULT_PATH, &modelDefaultPath);
+ ret = _config->getStringAttribute(MV_OBJECT_DETECTION_MODEL_DEFAULT_PATH, &_modelDefaultPath);
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to get model default path");
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to get model file path");
- _modelFilePath = modelDefaultPath + _modelFilePath;
+ _modelFilePath = _modelDefaultPath + _modelFilePath;
ret = _config->getStringAttribute(MV_OBJECT_DETECTION_MODEL_META_FILE_PATH, &_modelMetaFilePath);
if (ret != MEDIA_VISION_ERROR_NONE)
if (!IsJsonFile(_modelMetaFilePath))
throw InvalidOperation("Model meta file should be json");
- _modelMetaFilePath = modelDefaultPath + _modelMetaFilePath;
+ _modelMetaFilePath = _modelDefaultPath + _modelMetaFilePath;
_parser->load(_modelMetaFilePath);
+
+ ret = _config->getStringAttribute(MV_OBJECT_DETECTION_LABEL_FILE_NAME, &_modelLabelFilePath);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw InvalidOperation("Fail to get label file path");
+
+ _modelLabelFilePath = _modelDefaultPath + _modelLabelFilePath;
}
void ObjectDetection::configure()
template<typename T, typename V> void ObjectDetectionAdapter<T, V>::create(int type)
{
switch (static_cast<object_detection_task_type_e>(type)) {
- case object_detection_task_type_e::OBJECTRON:
- _object_detection = make_unique<Objectron>();
+ case object_detection_task_type_e::MOBILENET_SSD_V1:
+ _object_detection = make_unique<MobilenetSsd>();
break;
default:
throw InvalidParameter("Invalid object detection task type.");
--- /dev/null
+project(${MV_OBJECT_DETECTION_3D_LIB_NAME})
+cmake_minimum_required(VERSION 2.6...3.13)
+
+pkg_check_modules(${PROJECT_NAME}_DEP REQUIRED inference-engine-interface-common iniparser json-glib-1.0)
+file(GLOB MV_OBJECT_DETECTION_3D_SOURCE_LIST "${PROJECT_SOURCE_DIR}/src/*.c" "${PROJECT_SOURCE_DIR}/src/*.cpp" "${PROJECT_SOURCE_DIR}/../meta/src/*.cpp")
+
+find_package(OpenCV REQUIRED dnn imgproc)
+if(NOT OpenCV_FOUND)
+ message(SEND_ERROR "OpenCV NOT FOUND")
+ return()
+endif()
+
+if(FORCED_STATIC_BUILD)
+ add_library(${PROJECT_NAME} STATIC ${MV_OBJECT_DETECTION_3D_SOURCE_LIST})
+else()
+ add_library(${PROJECT_NAME} SHARED ${MV_OBJECT_DETECTION_3D_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 ../meta/include)
+install(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
--- /dev/null
+/**
+ * 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 __OBJECT_DETECTION_3D_PARSER_H__
+#define __OBJECT_DETECTION_3D_PARSER_H__
+
+#include "MetaParser.h"
+#include "PostprocessParser.h"
+
+namespace mediavision
+{
+namespace machine_learning
+{
+class ObjectDetection3dParser : public MetaParser
+{
+private:
+ PostprocessParser _postprocessParser;
+
+protected:
+ void parsePostprocess(std::shared_ptr<MetaInfo> meta_info, JsonObject *in_obj) override;
+
+public:
+ ObjectDetection3dParser();
+ ~ObjectDetection3dParser();
+};
+
+}
+}
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * 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_OBJECT_DETECTION_3D_CONFIG_H__
+#define __MEDIA_VISION_OBJECT_DETECTION_3D_CONFIG_H__
+
+/**
+ * @brief Defines #MV_OBJECT_DETECTION_3D_MODEL_DEFAULT_PATH
+ * to set the object detection default path.
+ *
+ * @since_tizen 7.5
+ */
+#define MV_OBJECT_DETECTION_3D_MODEL_DEFAULT_PATH "MODEL_DEFAULT_PATH"
+
+/**
+ * @brief Defines #MV_OBJECT_DETECTION_3D_MODEL_FILE_PATH
+ * to set the object detection model file path.
+ *
+ * @since_tizen 7.0
+ */
+#define MV_OBJECT_DETECTION_3D_MODEL_FILE_PATH "MODEL_FILE_NAME"
+
+/**
+ * @brief Defines #MV_OBJECT_DETECTION_3D_3D_MODEL_META_FILE_PATH to set inference
+ * models's metadata file attribute of the engine configuration.
+ * @details The file includes inference model's metadata such as input and output
+ * node names, input tensor's width and height,
+ * mean and standard deviation values for pre-processing.
+ *
+ * @since_tizen 7.0
+ */
+#define MV_OBJECT_DETECTION_3D_MODEL_META_FILE_PATH "META_FILE_NAME"
+
+/**
+ * @brief Defines #MV_OBJECT_DETECT_BACKEND_TYPE
+ * to set inference backend engine type. In default, tensorflow lite is used.
+ *
+ * @since_tizen 7.0
+ */
+#define MV_OBJECT_DETECTION_3D_BACKEND_TYPE "BACKEND_TYPE"
+
+/**
+ * @brief Defines #MV_OBJECT_DETECT_TARGET_DEVICE_TYPE
+ * to set inference target device type. In default, CPU device is used.
+ *
+ * @since_tizen 7.0
+ */
+#define MV_OBJECT_DETECTION_3D_TARGET_DEVICE_TYPE "TARGET_DEVICE_TYPE"
+
+#define MV_OBJECT_DETECTION_3D_3D_MAX_NUM_OF_POINTS "MAX_NUM_OF_POINTS"
+
+#define MV_OBJECT_DETECTION_3D_3D_MAX_NUM_OF_EDGES "MAX_NUM_OF_EDGES"
+
+#define MV_OBJECT_DETECTION_3D_META_FILE_NAME "object_detection_3d.json"
+
+#endif /* __MEDIA_VISION_INFERENCE_OPEN_H__ */
--- /dev/null
+/**
+ * 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_OBJECT_DETECTION_3D_OPEN_H__
+#define __MEDIA_VISION_OBJECT_DETECTION_3D_OPEN_H__
+
+#include <mv_common.h>
+#include <mv_private.h>
+#include <mv_object_detection_3d_type.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @brief Create object detection 3d object handle.
+ * @details Use this function to create an face recognition object handle.
+ * After creation the handle has to be prepared with
+ * @ref mv_object_detection_3d_prepare_open() function to prepare
+ * an face recognition object.
+ *
+ * @since_tizen 7.0
+ *
+ * @param[out] out_handle The handle to the object detection 3d 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_object_detection_3d_destroy_open() function when it is not needed
+ * anymore
+ *
+ * @see mv_object_detection_3d_destroy_open()
+ */
+int mv_object_detection_3d_create_open(mv_object_detection_3d_h *out_handle);
+
+/**
+ * @brief Destroy object detection 3d handle and releases all its resources.
+ *
+ * @since_tizen 7.0
+ *
+ * @param[in] handle The handle to the object detection 3d 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 object detection 3d handle by using @ref mv_object_detection_3d_create_open()
+ *
+ * @see mv_object_detection_3d_create_open()
+ */
+int mv_object_detection_3d_destroy_open(mv_object_detection_3d_h handle);
+
+/**
+ * @brief Configure the backend to the inference handle
+ *
+ * @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_OUT_OF_MEMORY Out of memory
+ * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported
+ */
+int mv_object_detection_3d_configure_open(mv_object_detection_3d_h handle);
+
+/**
+ * @brief Prepare inference.
+ * @details Use this function to prepare inference based on
+ * the configured network.
+ *
+ * @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_INVALID_DATA Invalid model data
+ * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory
+ */
+int mv_object_detection_3d_prepare_open(mv_object_detection_3d_h handle);
+
+/**
+ *
+ * @brief Inference with a given image on the @a source
+ * @details Use this function to inference with a given source.
+ *
+ *
+ * @since_tizen 7.0
+ *
+ * @param[in] handle The handle to the object detection 3d object.
+ * @param[in] source The handle to the source of the media.
+ *
+ * @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 object detection 3d handle by calling @ref mv_object_detection_3d_create_open()
+ * @pre Prepare an object detection 3d by calling @ref mv_object_detection_3d_prepare_open()
+ */
+int mv_object_detection_3d_inference_open(mv_object_detection_3d_h handle, mv_source_h source);
+
+/**
+ * @brief Gets the probability value to the detected object.
+ * @details Use this function to get the probability value after calling @ref mv_object_detection_3d_inference().
+ *
+ * @since_tizen 7.0
+ *
+ * @remarks The @a result must NOT be released using free()
+ *
+ * @param[in] handle The handle to the face recognition object.
+ * @param[out] out_probability A pointer to probability array.
+ *
+ * @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_INVALID_OPERATION Invalid operation
+ *
+ * @pre Request an inference by calling @ref mv_object_detection_3d_inference()
+ */
+int mv_object_detection_3d_get_probability_open(mv_object_detection_3d_h handle, unsigned int *out_probability);
+
+/**
+ * @brief Gets the number of points to the 3D bounding box of the detected object.
+ * @details Use this function to get the number of points after calling @ref mv_object_detection_3d_inference().
+ *
+ * @since_tizen 7.0
+ *
+ * @remarks The @a result must NOT be released using free()
+ *
+ * @param[in] handle The handle to the object detection 3d object.
+ * @param[out] out_num_of_points Number of points.
+ *
+ * @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_INVALID_OPERATION Invalid operation
+ *
+ * @pre Request an inference by calling @ref mv_object_detection_3d_inference()
+ */
+int mv_object_detection_3d_get_num_of_points_open(mv_object_detection_3d_h handle, unsigned int *out_num_of_points);
+
+/**
+ * @brief Gets the x and y coordinates values to the 3D bounding box of the detected object.
+ * @details Use this function to get the coordinates values after calling @ref mv_object_detection_3d_inference().
+ *
+ * @since_tizen 7.0
+ *
+ * @remarks The @a result must NOT be released using free()
+ *
+ * @param[in] handle The handle to the object detection 3d object.
+ * @param[out] out_x A pointer to x coordinates array.
+ * @param[out] out_y A pointer to y coordinates array.
+ *
+ * @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_INVALID_OPERATION Invalid operation
+ *
+ * @pre Request an inference by calling @ref mv_object_detection_3d_inference()
+ */
+int mv_object_detection_3d_get_points_open(mv_object_detection_3d_h handle, unsigned int **out_x, unsigned int **out_y);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __MEDIA_VISION_INFERENCE_3D_OPEN_H__ */
--- /dev/null
+/**
+ * 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 __OBJECT_DETECTION_3D_H__
+#define __OBJECT_DETECTION_3D_H__
+
+#include <mv_common.h>
+#include <mv_inference_type.h>
+#include "mv_private.h"
+
+#include "EngineConfig.h"
+#include "inference_engine_common_impl.h"
+#include "Inference.h"
+#include "object_detection_3d_type.h"
+#include "ObjectDetection3dParser.h"
+#include "Preprocess.h"
+
+namespace mediavision
+{
+namespace machine_learning
+{
+class ObjectDetection3d
+{
+protected:
+ std::unique_ptr<mediavision::inference::Inference> _inference;
+ std::unique_ptr<MediaVision::Common::EngineConfig> _config;
+ std::unique_ptr<MetaParser> _parser;
+ Preprocess _preprocess;
+ std::string _modelFilePath;
+ std::string _modelMetaFilePath;
+ int _backendType;
+ int _targetDeviceType;
+
+ void getOutputNames(std::vector<std::string> &names);
+ void getOutputTensor(std::string &target_name, std::vector<float> &tensor);
+
+public:
+ ObjectDetection3d();
+ virtual ~ObjectDetection3d() = default;
+ void parseMetaFile();
+ void configure();
+ void prepare();
+ void preprocess(mv_source_h &mv_src);
+ void inference(mv_source_h source);
+ virtual object_detection_3d_result_s &result() = 0;
+};
+
+} // machine_learning
+} // mediavision
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * 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 __OBJECT_DETECTION_3D_ADAPTER_H__
+#define __OBJECT_DETECTION_3D_ADAPTER_H__
+
+#include <dlog.h>
+
+#include "EngineConfig.h"
+#include "itask.h"
+#include "objectron.h"
+
+namespace mediavision
+{
+namespace machine_learning
+{
+template<typename T, typename V> class ObjectDetection3dAdapter : public mediavision::common::ITask<T, V>
+{
+private:
+ std::unique_ptr<ObjectDetection3d> _object_detection_3d;
+ T _source;
+
+public:
+ ObjectDetection3dAdapter();
+ ~ObjectDetection3dAdapter();
+
+ void create(int type) override;
+
+ void configure() override;
+ void prepare() override;
+ void setInput(T &t) override;
+ void perform() override;
+ V &getOutput() override;
+};
+
+} // machine_learning
+} // mediavision
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * 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 __OBJECT_DETECTION_3D_TYPE_H__
+#define __OBJECT_DETECTION_3D_TYPE_H__
+
+#include <mv_common.h>
+#include <mv_inference_type.h>
+
+namespace mediavision
+{
+namespace machine_learning
+{
+struct object_detection_3d_input_s {
+ mv_source_h inference_src;
+};
+
+struct edge_index_s {
+ unsigned int start {};
+ unsigned int end {};
+};
+
+/**
+ * @brief The object detection 3d result structure.
+ * @details Contains object detection 3d result.
+ */
+struct object_detection_3d_result_s {
+ unsigned int probability {};
+ unsigned int number_of_points {};
+ std::vector<unsigned int> x_vec;
+ std::vector<unsigned int> y_vec;
+ unsigned int number_of_edges {};
+ std::vector<edge_index_s> edge_index_vec;
+};
+
+enum class object_detection_3d_task_type_e {
+ OBJECT_DETECTION_3D_TASK_NONE = 0,
+ OBJECTRON
+ // TODO
+};
+
+}
+}
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * 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 __OBJECTRON_H__
+#define __OBJECTRON_H__
+
+#include <memory>
+#include <mv_common.h>
+#include "mv_private.h"
+
+#include "object_detection_3d.h"
+#include <mv_inference_type.h>
+
+namespace mediavision
+{
+namespace machine_learning
+{
+class Objectron : public ObjectDetection3d
+{
+private:
+ object_detection_3d_result_s _result;
+
+public:
+ Objectron();
+ ~Objectron();
+ object_detection_3d_result_s &result() override;
+};
+
+} // machine_learning
+} // mediavision
+
+#endif
\ No newline at end of file
--- /dev/null
+{
+ "attributes":
+ [
+ {
+ "name" : "MODEL_DEFAULT_PATH",
+ "type" : "string",
+ "value" : "/usr/share/capi-media-vision/models/OD3D/tflite/"
+ },
+ {
+ "name" : "OBJECT_NAME",
+ "type" : "string",
+ "value" : "cup"
+ },
+ {
+ "name" : "MODEL_FILE_NAME",
+ "type" : "string",
+ "value" : "object_detection_3d_cup.tflite"
+ },
+ {
+ "name" : "META_FILE_NAME",
+ "type" : "string",
+ "value" : "object_detection_3d_cup.json"
+ },
+ {
+ "name" : "BACKEND_TYPE",
+ "type" : "integer",
+ "value" : 1
+ },
+ {
+ "name" : "TARGET_DEVICE_TYPE",
+ "type" : "integer",
+ "value" : 1
+ }
+ ]
+}
--- /dev/null
+/**
+ * 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 <iostream>
+#include "machine_learning_exception.h"
+#include "ObjectDetection3dParser.h"
+
+using namespace std;
+using namespace mediavision::machine_learning::exception;
+
+namespace mediavision
+{
+namespace machine_learning
+{
+ObjectDetection3dParser::ObjectDetection3dParser()
+{
+ LOGI("ENTER");
+ LOGI("LEAVE");
+}
+
+ObjectDetection3dParser::~ObjectDetection3dParser()
+{}
+
+void ObjectDetection3dParser::parsePostprocess(shared_ptr<MetaInfo> meta_info, JsonObject *in_obj)
+{
+ LOGI("ENTER");
+
+ LOGI("tensor name : %s", meta_info->name.c_str());
+
+ if (json_object_has_member(in_obj, "box"))
+ _postprocessParser.parseBox(meta_info, in_obj);
+
+ LOGI("LEAVE");
+}
+
+}
+}
\ No newline at end of file
--- /dev/null
+/**
+ * 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_object_detection_3d_internal.h"
+#include "mv_object_detection_3d_open.h"
+
+/**
+ * @file mv_object_detection_3d.c
+ * @brief This file contains Media Vision inference module.
+ */
+
+int mv_object_detection_3d_create(mv_object_detection_3d_h *infer)
+{
+ MEDIA_VISION_SUPPORT_CHECK(_mv_inference_check_system_info_feature_supported());
+ MEDIA_VISION_NULL_ARG_CHECK(infer);
+
+ MEDIA_VISION_FUNCTION_ENTER();
+
+ int ret = mv_object_detection_3d_create_open(infer);
+
+ MEDIA_VISION_FUNCTION_LEAVE();
+ return ret;
+}
+
+int mv_object_detection_3d_destroy(mv_object_detection_3d_h infer)
+{
+ MEDIA_VISION_SUPPORT_CHECK(_mv_inference_check_system_info_feature_supported());
+ MEDIA_VISION_INSTANCE_CHECK(infer);
+
+ MEDIA_VISION_FUNCTION_ENTER();
+
+ int ret = mv_object_detection_3d_destroy_open(infer);
+
+ MEDIA_VISION_FUNCTION_LEAVE();
+ return ret;
+}
+
+int mv_object_detection_3d_configure(mv_object_detection_3d_h infer)
+{
+ MEDIA_VISION_SUPPORT_CHECK(_mv_inference_check_system_info_feature_supported());
+ MEDIA_VISION_INSTANCE_CHECK(infer);
+
+ MEDIA_VISION_FUNCTION_ENTER();
+
+ int ret = mv_object_detection_3d_configure_open(infer);
+
+ MEDIA_VISION_FUNCTION_LEAVE();
+ return ret;
+}
+
+int mv_object_detection_3d_prepare(mv_object_detection_3d_h infer)
+{
+ MEDIA_VISION_SUPPORT_CHECK(_mv_inference_check_system_info_feature_supported());
+ MEDIA_VISION_INSTANCE_CHECK(infer);
+
+ MEDIA_VISION_FUNCTION_ENTER();
+
+ int ret = mv_object_detection_3d_prepare_open(infer);
+
+ MEDIA_VISION_FUNCTION_LEAVE();
+ return ret;
+}
+
+int mv_object_detection_3d_inference(mv_object_detection_3d_h infer, mv_source_h source)
+{
+ MEDIA_VISION_SUPPORT_CHECK(_mv_inference_image_check_system_info_feature_supported());
+ MEDIA_VISION_INSTANCE_CHECK(source);
+ MEDIA_VISION_INSTANCE_CHECK(infer);
+
+ MEDIA_VISION_FUNCTION_ENTER();
+
+ int ret = mv_object_detection_3d_inference_open(infer, source);
+
+ MEDIA_VISION_FUNCTION_LEAVE();
+
+ return ret;
+}
+
+int mv_object_detection_3d_get_probability(mv_object_detection_3d_h handle, unsigned int *out_probability)
+{
+ MEDIA_VISION_SUPPORT_CHECK(_mv_inference_face_check_system_info_feature_supported());
+
+ MEDIA_VISION_INSTANCE_CHECK(handle);
+ MEDIA_VISION_NULL_ARG_CHECK(out_probability);
+
+ MEDIA_VISION_FUNCTION_ENTER();
+
+ int ret = mv_object_detection_3d_get_probability_open(handle, out_probability);
+
+ MEDIA_VISION_FUNCTION_LEAVE();
+
+ return ret;
+}
+
+int mv_object_detection_3d_get_num_of_points(mv_object_detection_3d_h handle, unsigned int *out_num_of_points)
+{
+ MEDIA_VISION_SUPPORT_CHECK(_mv_inference_face_check_system_info_feature_supported());
+
+ MEDIA_VISION_INSTANCE_CHECK(handle);
+ MEDIA_VISION_NULL_ARG_CHECK(out_num_of_points);
+
+ MEDIA_VISION_FUNCTION_ENTER();
+
+ int ret = mv_object_detection_3d_get_num_of_points_open(handle, out_num_of_points);
+
+ MEDIA_VISION_FUNCTION_LEAVE();
+
+ return ret;
+}
+
+int mv_object_detection_3d_get_points(mv_object_detection_3d_h handle, unsigned int **out_x, unsigned int **out_y)
+{
+ MEDIA_VISION_SUPPORT_CHECK(_mv_inference_face_check_system_info_feature_supported());
+
+ MEDIA_VISION_INSTANCE_CHECK(handle);
+ MEDIA_VISION_NULL_ARG_CHECK(out_x);
+ MEDIA_VISION_NULL_ARG_CHECK(out_y);
+
+ MEDIA_VISION_FUNCTION_ENTER();
+
+ int ret = mv_object_detection_3d_get_points_open(handle, out_x, out_y);
+
+ MEDIA_VISION_FUNCTION_LEAVE();
+
+ return ret;
+}
--- /dev/null
+/**
+ * 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 "itask.h"
+#include "mv_object_detection_3d_open.h"
+#include "object_detection_3d_adapter.h"
+#include "machine_learning_exception.h"
+#include "object_detection_3d_type.h"
+#include "context.h"
+
+#include <new>
+#include <unistd.h>
+#include <string>
+#include <algorithm>
+
+using namespace std;
+using namespace mediavision::inference;
+using namespace mediavision::common;
+using namespace mediavision::machine_learning;
+using namespace MediaVision::Common;
+using namespace mediavision::machine_learning::exception;
+using ObjectDetection3dTask = ITask<object_detection_3d_input_s, object_detection_3d_result_s>;
+
+int mv_object_detection_3d_create_open(mv_object_detection_3d_h *out_handle)
+{
+ if (!out_handle) {
+ LOGE("Handle can't be created because handle pointer is NULL");
+ return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ }
+
+ Context *context = nullptr;
+ ObjectDetection3dTask *task = nullptr;
+
+ try {
+ context = new Context();
+ task = new ObjectDetection3dAdapter<object_detection_3d_input_s, object_detection_3d_result_s>();
+ task->create(static_cast<int>(object_detection_3d_task_type_e::OBJECTRON));
+
+ context->__tasks.insert(make_pair("object_detection_3d", task));
+ *out_handle = static_cast<mv_object_detection_3d_h>(context);
+ } catch (const BaseException &e) {
+ delete task;
+ delete context;
+ return e.getError();
+ }
+
+ LOGD("object detection 3d handle [%p] has been created", *out_handle);
+
+ return MEDIA_VISION_ERROR_NONE;
+}
+
+int mv_object_detection_3d_destroy_open(mv_object_detection_3d_h handle)
+{
+ if (!handle) {
+ LOGE("Handle is NULL.");
+ return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ }
+
+ auto context = static_cast<Context *>(handle);
+
+ for (auto &m : context->__tasks)
+ delete static_cast<ObjectDetection3dTask *>(m.second);
+
+ delete context;
+
+ LOGD("Object detection 3d handle has been destroyed.");
+
+ return MEDIA_VISION_ERROR_NONE;
+}
+
+int mv_object_detection_3d_configure_open(mv_object_detection_3d_h handle)
+{
+ LOGD("ENTER");
+
+ if (!handle) {
+ LOGE("Handle is NULL.");
+ return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ }
+
+ try {
+ auto context = static_cast<Context *>(handle);
+ auto task = static_cast<ObjectDetection3dTask *>(context->__tasks.at("object_detection_3d"));
+
+ task->configure();
+ } catch (const BaseException &e) {
+ LOGE("%s", e.what());
+ return e.getError();
+ }
+
+ LOGD("LEAVE");
+
+ return MEDIA_VISION_ERROR_NONE;
+}
+
+int mv_object_detection_3d_prepare_open(mv_object_detection_3d_h handle)
+{
+ LOGD("ENTER");
+
+ if (!handle) {
+ LOGE("Handle is NULL.");
+ return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ }
+
+ try {
+ auto context = static_cast<Context *>(handle);
+ auto task = static_cast<ObjectDetection3dTask *>(context->__tasks.at("object_detection_3d"));
+
+ task->prepare();
+ } catch (const BaseException &e) {
+ LOGE("%s", e.what());
+ return e.getError();
+ }
+
+ LOGD("LEAVE");
+
+ return MEDIA_VISION_ERROR_NONE;
+}
+
+int mv_object_detection_3d_inference_open(mv_object_detection_3d_h handle, mv_source_h source)
+{
+ LOGD("ENTER");
+
+ if (!handle) {
+ LOGE("Handle is NULL.");
+ return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ }
+
+ try {
+ auto context = static_cast<Context *>(handle);
+ auto task = static_cast<ObjectDetection3dTask *>(context->__tasks.at("object_detection_3d"));
+
+ object_detection_3d_input_s input = { source };
+
+ task->setInput(input);
+ task->perform();
+ } catch (const BaseException &e) {
+ LOGE("%s", e.what());
+ return e.getError();
+ }
+
+ LOGD("LEAVE");
+
+ return MEDIA_VISION_ERROR_NONE;
+}
+
+int mv_object_detection_3d_get_probability_open(mv_object_detection_3d_h handle, unsigned int *out_probability)
+{
+ LOGD("ENTER");
+
+ if (!handle) {
+ LOGE("Handle is NULL.");
+ return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ }
+
+ try {
+ auto context = static_cast<Context *>(handle);
+ auto task = static_cast<ObjectDetection3dTask *>(context->__tasks.at("object_detection_3d"));
+
+ object_detection_3d_result_s &result = task->getOutput();
+
+ *out_probability = result.probability;
+ } catch (const BaseException &e) {
+ LOGE("%s", e.what());
+ return e.getError();
+ }
+
+ LOGD("LEAVE");
+
+ return MEDIA_VISION_ERROR_NONE;
+}
+
+int mv_object_detection_3d_get_num_of_points_open(mv_object_detection_3d_h handle, unsigned int *out_num_of_points)
+{
+ LOGD("ENTER");
+
+ if (!handle) {
+ LOGE("Handle is NULL.");
+ return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ }
+
+ try {
+ auto context = static_cast<Context *>(handle);
+ auto task = static_cast<ObjectDetection3dTask *>(context->__tasks.at("object_detection_3d"));
+
+ object_detection_3d_result_s &result = task->getOutput();
+
+ *out_num_of_points = result.number_of_points;
+ } catch (const BaseException &e) {
+ LOGE("%s", e.what());
+ return e.getError();
+ }
+
+ LOGD("LEAVE");
+
+ return MEDIA_VISION_ERROR_NONE;
+}
+
+int mv_object_detection_3d_get_points_open(mv_object_detection_3d_h handle, unsigned int **out_x, unsigned int **out_y)
+{
+ LOGD("ENTER");
+
+ if (!handle) {
+ LOGE("Handle is NULL.");
+ return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ }
+
+ try {
+ Context *context = static_cast<Context *>(handle);
+ auto task = static_cast<ObjectDetection3dTask *>(context->__tasks.at("object_detection_3d"));
+
+ object_detection_3d_result_s &result = task->getOutput();
+
+ *out_x = result.x_vec.data();
+ *out_y = result.y_vec.data();
+
+ for (auto &edge : result.edge_index_vec)
+ LOGI("%d,%d ", edge.start, edge.end);
+
+ for (unsigned int i = 0; i < result.number_of_points; ++i)
+ LOGI("%d %d", (*out_x)[i], (*out_y)[i]);
+ } catch (const BaseException &e) {
+ LOGE("%s", e.what());
+ return e.getError();
+ }
+
+ LOGD("LEAVE");
+
+ return MEDIA_VISION_ERROR_NONE;
+}
\ No newline at end of file
--- /dev/null
+/**
+ * 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 <string.h>
+#include <map>
+#include <memory>
+#include <algorithm>
+
+#include "machine_learning_exception.h"
+#include "mv_object_detection_3d_config.h"
+#include "object_detection_3d.h"
+
+using namespace std;
+using namespace mediavision::inference;
+using namespace MediaVision::Common;
+using namespace mediavision::machine_learning::exception;
+
+namespace mediavision
+{
+namespace machine_learning
+{
+ObjectDetection3d::ObjectDetection3d() : _backendType(), _targetDeviceType()
+{
+ _inference = make_unique<Inference>();
+ _parser = make_unique<ObjectDetection3dParser>();
+}
+
+static bool IsJsonFile(const string &fileName)
+{
+ return (!fileName.substr(fileName.find_last_of(".") + 1).compare("json"));
+}
+
+void ObjectDetection3d::parseMetaFile()
+{
+ _config = make_unique<EngineConfig>(string(MV_CONFIG_PATH) + string(MV_OBJECT_DETECTION_3D_META_FILE_NAME));
+
+ int ret = _config->getIntegerAttribute(string(MV_OBJECT_DETECTION_3D_BACKEND_TYPE), &_backendType);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw InvalidOperation("Fail to get backend engine type.");
+
+ ret = _config->getIntegerAttribute(string(MV_OBJECT_DETECTION_3D_TARGET_DEVICE_TYPE), &_targetDeviceType);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw InvalidOperation("Fail to get target device type.");
+
+ string modelDefaultPath;
+
+ ret = _config->getStringAttribute(MV_OBJECT_DETECTION_3D_MODEL_DEFAULT_PATH, &modelDefaultPath);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw InvalidOperation("Fail to get model default path");
+
+ ret = _config->getStringAttribute(MV_OBJECT_DETECTION_3D_MODEL_FILE_PATH, &_modelFilePath);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw InvalidOperation("Fail to get model file path");
+
+ _modelFilePath = modelDefaultPath + _modelFilePath;
+
+ ret = _config->getStringAttribute(MV_OBJECT_DETECTION_3D_MODEL_META_FILE_PATH, &_modelMetaFilePath);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw InvalidOperation("Fail to get model meta file path");
+
+ if (_modelMetaFilePath.empty())
+ throw InvalidOperation("Model meta file doesn't exist.");
+
+ if (!IsJsonFile(_modelMetaFilePath))
+ throw InvalidOperation("Model meta file should be json");
+
+ _modelMetaFilePath = modelDefaultPath + _modelMetaFilePath;
+
+ _parser->load(_modelMetaFilePath);
+}
+
+void ObjectDetection3d::configure()
+{
+ int ret = _inference->bind(_backendType, _targetDeviceType);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw InvalidOperation("Fail to bind a backend engine.");
+}
+
+void ObjectDetection3d::prepare()
+{
+ int ret = _inference->configureInputMetaInfo(_parser->getInputMetaMap());
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw InvalidOperation("Fail to configure input tensor info from meta file.");
+
+ ret = _inference->configureOutputMetaInfo(_parser->getOutputMetaMap());
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw InvalidOperation("Fail to configure output tensor info from meta file.");
+
+ _inference->configureModelFiles("", _modelFilePath, "");
+
+ // Request to load model files to a backend engine.
+ ret = _inference->load();
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw InvalidOperation("Fail to load model files.");
+}
+void ObjectDetection3d::preprocess(mv_source_h &mv_src)
+{
+ LOGI("ENTER");
+
+ TensorBuffer &tensor_buffer_obj = _inference->getInputTensorBuffer();
+ IETensorBuffer &ie_tensor_buffer = tensor_buffer_obj.getIETensorBuffer();
+ vector<mv_source_h> mv_srcs = { mv_src };
+
+ _preprocess.run(mv_srcs, _parser->getInputMetaMap(), ie_tensor_buffer);
+
+ LOGI("LEAVE");
+}
+
+void ObjectDetection3d::inference(mv_source_h source)
+{
+ LOGI("ENTER");
+
+ vector<mv_source_h> sources;
+
+ sources.push_back(source);
+
+ int ret = _inference->run();
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw InvalidOperation("Fail to run inference");
+
+ LOGI("LEAVE");
+}
+
+void ObjectDetection3d::getOutputNames(vector<string> &names)
+{
+ TensorBuffer &tensor_buffer_obj = _inference->getOutputTensorBuffer();
+ IETensorBuffer &ie_tensor_buffer = tensor_buffer_obj.getIETensorBuffer();
+
+ for (IETensorBuffer::iterator it = ie_tensor_buffer.begin(); it != ie_tensor_buffer.end(); it++)
+ names.push_back(it->first);
+}
+
+void ObjectDetection3d::getOutputTensor(string &target_name, vector<float> &tensor)
+{
+ LOGI("ENTER");
+
+ TensorBuffer &tensor_buffer_obj = _inference->getOutputTensorBuffer();
+
+ inference_engine_tensor_buffer *tensor_buffer = tensor_buffer_obj.getTensorBuffer(target_name);
+ if (!tensor_buffer)
+ throw InvalidOperation("Fail to get tensor buffer.");
+
+ auto raw_buffer = static_cast<float *>(tensor_buffer->buffer);
+
+ copy(&raw_buffer[0], &raw_buffer[tensor_buffer->size / sizeof(float)], back_inserter(tensor));
+
+ LOGI("LEAVE");
+}
+
+}
+}
\ No newline at end of file
--- /dev/null
+/**
+ * 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 "machine_learning_exception.h"
+#include "object_detection_3d_adapter.h"
+
+using namespace std;
+using namespace MediaVision::Common;
+using namespace mediavision::machine_learning;
+using namespace mediavision::machine_learning::exception;
+
+namespace mediavision
+{
+namespace machine_learning
+{
+template<typename T, typename V> ObjectDetection3dAdapter<T, V>::ObjectDetection3dAdapter() : _source()
+{}
+
+template<typename T, typename V> ObjectDetection3dAdapter<T, V>::~ObjectDetection3dAdapter()
+{}
+
+template<typename T, typename V> void ObjectDetection3dAdapter<T, V>::create(int type)
+{
+ switch (static_cast<object_detection_3d_task_type_e>(type)) {
+ case object_detection_3d_task_type_e::OBJECTRON:
+ _object_detection_3d = make_unique<Objectron>();
+ break;
+ default:
+ throw InvalidParameter("Invalid object detection task type.");
+ }
+}
+
+template<typename T, typename V> void ObjectDetection3dAdapter<T, V>::configure()
+{
+ _object_detection_3d->parseMetaFile();
+ _object_detection_3d->configure();
+}
+
+template<typename T, typename V> void ObjectDetection3dAdapter<T, V>::prepare()
+{
+ _object_detection_3d->prepare();
+}
+
+template<typename T, typename V> void ObjectDetection3dAdapter<T, V>::setInput(T &t)
+{
+ _source = t;
+}
+
+template<typename T, typename V> void ObjectDetection3dAdapter<T, V>::perform()
+{
+ _object_detection_3d->preprocess(_source.inference_src);
+ _object_detection_3d->inference(_source.inference_src);
+}
+
+template<typename T, typename V> V &ObjectDetection3dAdapter<T, V>::getOutput()
+{
+ return _object_detection_3d->result();
+}
+
+template class ObjectDetection3dAdapter<object_detection_3d_input_s, object_detection_3d_result_s>;
+}
+}
\ No newline at end of file
Objectron::~Objectron()
{}
-object_detection_result_s &Objectron::result()
+object_detection_3d_result_s &Objectron::result()
{
vector<string> names;
- ObjectDetection::getOutputNames(names);
+ ObjectDetection3d::getOutputNames(names);
vector<float> keypoints;
- ObjectDetection::getOutputTensor(names[1], keypoints);
+ ObjectDetection3d::getOutputTensor(names[1], keypoints);
size_t output_size = keypoints.size();
vector<float> probability_vec;
// names[0] is "Identity"
- ObjectDetection::getOutputTensor(names[0], probability_vec);
+ ObjectDetection3d::getOutputTensor(names[0], probability_vec);
_result.probability = static_cast<unsigned int>(probability_vec[0] * 100);
%{_libdir}/libmv_inference*.so
%{_datadir}/%{name}/object_detection.json
%{_libdir}/libmv_object_detection*.so
+%{_datadir}/%{name}/object_detection_3d.json
+%{_libdir}/libmv_object_detection_3d*.so
%{_datadir}/%{name}/image_classification.json
%{_libdir}/libmv_image_classification*.so
%if "%{enable_ml_face_recognition}" == "1"
%files machine_learning-devel
%{_includedir}/media/mv_infer*.h
%{_includedir}/media/mv_object_detection*.h
+%{_includedir}/media/mv_object_detection_3d*.h
%{_includedir}/media/mv_image_classification*.h
%{_libdir}/pkgconfig/*inference.pc
%{_libdir}/pkgconfig/*object-detection.pc
+%{_libdir}/pkgconfig/*object-detection-3d.pc
%{_libdir}/pkgconfig/*image-classification.pc
%if "%{enable_ml_face_recognition}" == "1"
%{_includedir}/media/mv_face_recognition*.h
%{_bindir}/mv_*
%{_bindir}/test_image_classification
%{_bindir}/test_object_detection
+%{_bindir}/test_object_detection_3d
%if "%{enable_ml_face_recognition}" == "1"
%{_bindir}/test_face_recognition
%{_bindir}/test_face_recognition_multi_threads
add_subdirectory(${PROJECT_SOURCE_DIR}/inference)
add_subdirectory(${PROJECT_SOURCE_DIR}/image_classification)
add_subdirectory(${PROJECT_SOURCE_DIR}/object_detection)
+add_subdirectory(${PROJECT_SOURCE_DIR}/object_detection_3d)
if (${ENABLE_ML_FACE_RECOGNITION})
message("Enabled machine learning face recognition test cases.")
#include "ImageHelper.h"
#include "mv_object_detection_internal.h"
-#define IMAGE_PATH MV_CONFIG_PATH "/res/object_detection/cup.jpeg"
+#define IMAGE_PATH MV_CONFIG_PATH "res/inference/images/dog2.jpg"
using namespace testing;
using namespace std;
using namespace MediaVision::Common;
-TEST(ObjectDetection3DTest, InferenceShouldBeOk)
+TEST(ObjectDetectionTest, InferenceShouldBeOk)
{
mv_object_detection_h handle;
ret = mv_object_detection_inference(handle, mv_source);
ASSERT_EQ(ret, 0);
- unsigned int probability;
-
- ret = mv_object_detection_3d_get_probability(handle, &probability);
- ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
-
- std::cout << "Probability = " << probability << std::endl;
-
- unsigned int num_of_points;
-
- ret = mv_object_detection_3d_get_num_of_points(handle, &num_of_points);
- ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
-
- unsigned int *x_array, *y_array;
-
- ret = mv_object_detection_3d_get_points(handle, &x_array, &y_array);
- ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
-
- for (unsigned int idx = 0; idx < num_of_points; ++idx) {
- std::cout << "index = " << idx + 1 << " : " << x_array[idx] << " x " << y_array[idx] << std::endl;
- }
-
ret = mv_destroy_source(mv_source);
ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
--- /dev/null
+project(mv_object_detection_3d_suite)
+cmake_minimum_required(VERSION 2.6...3.13)
+
+set(TEST_OBJECT_DETECTION_3D test_object_detection_3d)
+
+add_executable(${TEST_OBJECT_DETECTION_3D} test_object_detection_3d.cpp)
+
+target_link_libraries(${TEST_OBJECT_DETECTION_3D} gtest gtest_main
+ mv_inference
+ mv_object_detection_3d
+ mv_image_helper
+)
+
+install(TARGETS ${TEST_OBJECT_DETECTION_3D} DESTINATION ${CMAKE_INSTALL_BINDIR})
\ No newline at end of file
--- /dev/null
+/**
+ * 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 <iostream>
+#include <string.h>
+#include <map>
+
+#include "gtest/gtest.h"
+
+#include "ImageHelper.h"
+#include "mv_object_detection_3d_internal.h"
+
+#define IMAGE_PATH MV_CONFIG_PATH "res/object_detection_3d/cup.jpeg"
+
+using namespace testing;
+using namespace std;
+
+using namespace MediaVision::Common;
+
+TEST(ObjectDetection3DTest, InferenceShouldBeOk)
+{
+ mv_object_detection_3d_h handle;
+
+ int ret = mv_object_detection_3d_create(&handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_object_detection_3d_configure(handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_object_detection_3d_prepare(handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ const string image_path = IMAGE_PATH;
+ 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_object_detection_3d_inference(handle, mv_source);
+ ASSERT_EQ(ret, 0);
+
+ unsigned int probability;
+
+ ret = mv_object_detection_3d_get_probability(handle, &probability);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ std::cout << "Probability = " << probability << std::endl;
+
+ unsigned int num_of_points;
+
+ ret = mv_object_detection_3d_get_num_of_points(handle, &num_of_points);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ unsigned int *x_array, *y_array;
+
+ ret = mv_object_detection_3d_get_points(handle, &x_array, &y_array);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ for (unsigned int idx = 0; idx < num_of_points; ++idx) {
+ std::cout << "index = " << idx + 1 << " : " << x_array[idx] << " x " << y_array[idx] << std::endl;
+ }
+
+ ret = mv_destroy_source(mv_source);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_object_detection_3d_destroy(handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+}