mv_roi_tracker: api refactorying
authorHyunsoo Park <hance.park@samsung.com>
Thu, 23 Jun 2022 09:35:27 +0000 (18:35 +0900)
committerInki Dae <inki.dae@samsung.com>
Wed, 20 Jul 2022 05:16:57 +0000 (14:16 +0900)
[Issue Type] Code Refactorying

- Remove struct out parameter possible to cause ABI break.
- Add 'mv_roi_tracker_get_result_roi' api as alternative.

Change-Id: Icb4bb3225ddaa1798b886cc875e59bd93bfb9fc7
Signed-off-by: Hyunsoo Park <hance.park@samsung.com>
include/mv_roi_tracker.h
include/mv_roi_tracker_type.h
mv_roi_tracker/roi_tracker/include/ROITracker.h
mv_roi_tracker/roi_tracker/include/mv_roi_tracker_open.h
mv_roi_tracker/roi_tracker/src/ROITracker.cpp
mv_roi_tracker/roi_tracker/src/mv_roi_tracker.c
mv_roi_tracker/roi_tracker/src/mv_roi_tracker_open.cpp
test/testsuites/tracker/test_tracker.cpp

index d072eb209ceb298943aac2a14051e8616d647c9d..998f7b618033f6fac65c431e8fb93a4388704223 100644 (file)
 extern "C" {
 #endif /* __cplusplus */
 
+/**
+ * @file   mv_roi_tracker.h
+ * @brief  This file contains the ROI tracker based Media Vision API.
+ */
+
+/**
+ * @addtogroup CAPI_MEDIA_VISION_ROI_TRACKER_MODULE
+ * @{
+ */
+
 /**
  * @brief Creates tracker handle.
- * @details Use this function to create an tracker handle.
+ * @details Use this function to create a tracker handle.
  *
  * @since_tizen 7.0
  *
@@ -45,7 +55,7 @@ extern "C" {
 int mv_roi_tracker_create(mv_roi_tracker_h *handle);
 
 /**
- * @brief Destroy tracker handle and release all its resources.
+ * @brief Destroys tracker handle and release all its resources.
  *
  * @since_tizen 7.0
  *
@@ -56,20 +66,17 @@ int mv_roi_tracker_create(mv_roi_tracker_h *handle);
  * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
  *
  * @pre Create tracker handle by using mv_roi_tracker_create()
- *
- * @see mv_roi_tracker_create()
  */
 int mv_roi_tracker_destroy(mv_roi_tracker_h handle);
 
 /**
- * @brief Sets initial roi coordinates to roi tracker object handle.
- * @details Use this function to set the coordinates to the tracker object handle(for the tracking).
+ * @brief Sets initial ROI coordinates to tracker object handle.
  *
  * @since_tizen 7.0
  *
  * @param[in] handle    The tracker handle to set coordinates.
- * @param[in] x         The x coordiante to set initial ROI to be tracked
- * @param[in] y         The y coordiante to set initial ROI to be tracked
+ * @param[in] x         The x coordinate to set initial ROI to be tracked
+ * @param[in] y         The y coordinate to set initial ROI to be tracked
  * @param[in] width     The width to set initial ROI to be tracked
  * @param[in] height    The height to set initial ROI to be tracked
  *
@@ -83,13 +90,12 @@ int mv_roi_tracker_destroy(mv_roi_tracker_h handle);
 int mv_roi_tracker_set_coordinate(mv_roi_tracker_h handle, int x, int y, int width, int height);
 
 /**
- * @brief Sets tracker type to roi tracker object handle.
- * @details Use this function to set the tracker type to the tracker object handle(for the tracking).
+ * @brief Sets tracker type to ROI tracker object handle.
  *
  * @since_tizen 7.0
  *
  * @param[in] handle          The tracker handle to set tracker type.
- * @param[in] type            The tracker type to set default tracker type to be set
+ * @param[in] type            The tracker type option to be set
  *
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIA_VISION_ERROR_NONE Successful
@@ -103,13 +109,12 @@ int mv_roi_tracker_set_tracker_type(mv_roi_tracker_h handle, mv_roi_tracker_type
 /**
  * @brief Tracks with a given tracker on the @a source.
  * @details Use this function to track with a given source.
- *          This function returns a proper label string to a given source.
+ *          This function returns a proper ROI coordinates of the tracked region inside given 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] result    The structure which is filled with result.
+ * @param[in]  handle     The handle to the tracker 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
@@ -122,8 +127,33 @@ int mv_roi_tracker_set_tracker_type(mv_roi_tracker_h handle, mv_roi_tracker_type
  *
  * @pre Create a new tracker handle by calling @ref mv_roi_tracker_create()
  */
-int mv_roi_tracker_perform(mv_roi_tracker_h handle, mv_source_h source,
-                                                                 mv_roi_tracker_result_s *result);
+int mv_roi_tracker_perform(mv_roi_tracker_h handle, mv_source_h source);
+
+/**
+ * @brief Gets ROI result
+ * @details Use this function to get ROI result after calling mv_roi_tracker_perform function.
+ *          This function returns a proper ROI coordinates and size result of the tracked region.
+ *
+ * @since_tizen 7.0
+ *
+ * @param[in] handle     The handle to the tracker object.
+ * @param[out] x         The x coordinate of ROI result.
+ * @param[out] y         The y coordinate of ROI result.
+ * @param[out] width     The width of ROI result.
+ * @param[out] height    The height of ROI 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_INVALID_PARAMETER Invalid parameter
+ *
+ * @pre Perform tracking action by calling @ref mv_roi_tracker_perform()
+ */
+int mv_roi_tracker_get_result(mv_roi_tracker_h handle,
+                                                                 int *x, int *y, int *width, int *height);
+/**
+ * @}
+ */
 
 #ifdef __cplusplus
 }
index b7a22efaf952767481ee19351912caf4ef56c7b4..1f01b75b3a883c33390f03786c98f39b541bed39 100644 (file)
@@ -28,29 +28,43 @@ extern "C" {
 #endif /* __cplusplus */
 
 /**
- * @brief The roi tracker result structure.
+ * @file  mv_roi_tracker_type.h
+ * @brief This file contains enumerations and a handle required by
+ *        MediaVision ROI tracker API.
+ */
+
+/**
+ * @addtogroup CAPI_MEDIA_VISION_ROI_TRACKER_MODULE
+ * @{
+ */
+
+/**
+ * @brief The ROI tracker result structure.
  * @details Contains roi tracker result such as coordinates.
  * @since_tizen 7.0
  */
 typedef struct {
-       int x;
-       int y;
-       int width;
-       int height;
+       int x;          /**< Left-top x coordinate of tracked region */
+       int y;          /**< Left-top y coordinate of tracked region */
+       int width;      /**< Width of tracked region */
+       int height;     /**< Height of tracked region */
 } mv_roi_tracker_result_s;
 
 /**
- * @brief The roi tracker handle.
+ * @brief The ROI tracker handle.
  * @since_tizen 7.0
  */
 typedef void *mv_roi_tracker_h;
 
 typedef enum {
-       MV_ROI_TRACKER_TYPE_NONE = 0,
-       MV_ROI_TRACKER_TYPE_SPEED,
-       MV_ROI_TRACKER_TYPE_BALANCE,
-       MV_ROI_TRACKER_TYPE_ACCURACY
+       MV_ROI_TRACKER_TYPE_NONE = 0,   /**< None */
+       MV_ROI_TRACKER_TYPE_SPEED,              /**< Tracker type focused on speed */
+       MV_ROI_TRACKER_TYPE_BALANCE,    /**< Tracker type focused on balance */
+       MV_ROI_TRACKER_TYPE_ACCURACY    /**< Tracker type focused on accuracy */
 } mv_roi_tracker_type_e;
+/**
+ * @}
+ */
 
 #ifdef __cplusplus
 }
index 5c5f403222567bf0f179864d6e79d88c78bc6fa0..377b03dd1efbc47e17b5511aa408c518c5372a8c 100644 (file)
@@ -38,6 +38,7 @@ public:
        cv::Rect boundingBox;
        bool initialized;
        mv_roi_tracker_type_e type;
+       mv_roi_tracker_result_s result;
 };
 
 } /* ROITracker */
index 0ae2c2f7e32d05a2b46edfe5516470bed5756550..8821c0ea5777a14e367185600d13cf904707ca63 100644 (file)
@@ -100,8 +100,8 @@ int mv_roi_tracker_set_coordinate_open(mv_roi_tracker_h handle, int x, int y, in
  *
  * @since_tizen 7.0
  *
- * @param [in] handle         The handle to the tracker object
- * @param [in] type The tracker to set default tracker to be set
+ * @param [in] handle  The handle to the tracker object
+ * @param [in] type    The tracker to set default tracker to be set
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIA_VISION_ERROR_NONE Successful
  * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
@@ -114,17 +114,17 @@ int mv_roi_tracker_set_tracker_type_open(mv_roi_tracker_h handle, mv_roi_tracker
 /**
  * @brief Track with a given roi on the @a source.
  * @details Use this function to track with a given source.
- *          This function returns an proper roi to a given out_result.
+ *          This function returns an proper roi to a given result.
  *
  * @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] result    The structure which is filled with track 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_INVALID_OPERATION Invalid operation
  * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT Source colorspace
  *                                                  isn't supported
  * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory
@@ -132,9 +132,29 @@ int mv_roi_tracker_set_tracker_type_open(mv_roi_tracker_h handle, mv_roi_tracker
  * @pre Create a source handle by calling @ref mv_create_source()
  * @pre Create an tracker handle by calling @ref mv_roi_tracker_create_open()
  */
-int mv_roi_tracker_perform_open(mv_roi_tracker_h handle, mv_source_h source,
-                                                                               mv_roi_tracker_result_s *result);
+int mv_roi_tracker_perform_open(mv_roi_tracker_h handle, mv_source_h source);
 
+/**
+ * @brief Gets ROI result
+ * @details Use this function to get ROI result after calling mv_roi_tracker_perform function.
+ *          This function returns a proper ROI coordinates and size result of the tracked region.
+ *
+ * @since_tizen 7.0
+ *
+ * @param[in] handle     The handle to the tracker object.
+ * @param[out] x         The x coordinate to set initial ROI to be tracked
+ * @param[out] y         The y coordinate to set initial ROI to be tracked
+ * @param[out] width     The width to set initial ROI to be tracked
+ * @param[out] height    The height to set initial ROI to be tracked
+ *
+ * @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 Perform tracking action by calling @ref mv_roi_tracker_perform_open()
+ */
+int mv_roi_tracker_get_result_open(mv_roi_tracker_h handle, int *x, int *y, int *width, int *height);
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 521f4f254389f747774cf3841df14ce61e20eb02..24ccd68fccd90da13085fbc1c11792c285f828d5 100644 (file)
@@ -41,7 +41,8 @@ namespace MediaVision {
 namespace ROITracker {
 ROITracker::ROITracker()
        : initialized(false),
-       type(MV_ROI_TRACKER_TYPE_BALANCE)
+       type(MV_ROI_TRACKER_TYPE_BALANCE),
+       result()
 {
 }
 
index 0eff2b95c245167303fc7fdc16c9b82094da0ead..3d6e66a9d8c255cc388ce09a5ea65164dcbafb30 100644 (file)
@@ -82,19 +82,38 @@ int mv_roi_tracker_set_tracker_type(mv_roi_tracker_h handle, mv_roi_tracker_type
        return ret;
 }
 
-int mv_roi_tracker_perform(mv_roi_tracker_h handle, mv_source_h source,
-                                                                 mv_roi_tracker_result_s *result)
+int mv_roi_tracker_perform(mv_roi_tracker_h handle, mv_source_h source)
 {
        MEDIA_VISION_SUPPORT_CHECK(
                __mv_roi_tracking_check_system_info_feature_supported());
 
        MEDIA_VISION_INSTANCE_CHECK(handle);
        MEDIA_VISION_INSTANCE_CHECK(source);
-       MEDIA_VISION_NULL_ARG_CHECK(result);
 
        MEDIA_VISION_FUNCTION_ENTER();
 
-       int ret = mv_roi_tracker_perform_open(handle, source, result);
+       int ret = mv_roi_tracker_perform_open(handle, source);
+
+       MEDIA_VISION_FUNCTION_LEAVE();
+
+       return ret;
+}
+
+int mv_roi_tracker_get_result(mv_roi_tracker_h handle,
+                                                                 int *x, int *y, int *width, int *height)
+{
+       MEDIA_VISION_SUPPORT_CHECK(
+               __mv_roi_tracking_check_system_info_feature_supported());
+
+       MEDIA_VISION_INSTANCE_CHECK(handle);
+       MEDIA_VISION_NULL_ARG_CHECK(x);
+       MEDIA_VISION_NULL_ARG_CHECK(y);
+       MEDIA_VISION_NULL_ARG_CHECK(width);
+       MEDIA_VISION_NULL_ARG_CHECK(height);
+
+       MEDIA_VISION_FUNCTION_ENTER();
+
+       int ret = mv_roi_tracker_get_result_open(handle, x, y, width, height);
 
        MEDIA_VISION_FUNCTION_LEAVE();
 
index b01ef5bb7f1dfc2285757720483a9fc7988c92f4..03cf73382d71d81876812a01a3ff72eca6a8d314 100644 (file)
@@ -126,8 +126,7 @@ int mv_roi_tracker_set_tracker_type_open(mv_roi_tracker_h handle, mv_roi_tracker
        return MEDIA_VISION_ERROR_NONE;
 }
 
-int mv_roi_tracker_perform_open(mv_roi_tracker_h handle, mv_source_h source,
-                                                                          mv_roi_tracker_result_s *result)
+int mv_roi_tracker_perform_open(mv_roi_tracker_h handle, mv_source_h source)
 {
        LOGD("ENTER");
        if (!handle) {
@@ -156,14 +155,40 @@ int mv_roi_tracker_perform_open(mv_roi_tracker_h handle, mv_source_h source,
        try {
                cv::Mat frame = getTrackerFrame(colorspace, channels, width, height, buffer);
                if (!pTracker->initialized) {
-                       *result = pTracker->Initialize(frame);
+                       pTracker->result = pTracker->Initialize(frame);
                        return MEDIA_VISION_ERROR_NONE;
                }
-               *result = pTracker->Update(frame);
+               pTracker->result = pTracker->Update(frame);
        } catch (const std::exception &e) {
                LOGE("Failed : %s", e.what());
                return MEDIA_VISION_ERROR_INVALID_OPERATION;
        }
+       LOGD("LEAVE");
+       return MEDIA_VISION_ERROR_NONE;
+}
+
+int mv_roi_tracker_get_result_open(mv_roi_tracker_h handle,
+                                                                          int *x, int *y, int *width, int *height)
+{
+       LOGD("ENTER");
+       if (!handle) {
+               LOGE("Handle is NULL.");
+               return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+       }
+
+       auto *pTracker = static_cast<ROITracker *>(handle);
+
+       if (!pTracker->initialized) {
+               LOGE("ROI Tracker dosn't performed yet.");
+               return MEDIA_VISION_ERROR_INVALID_OPERATION;
+       }
+       *x = pTracker->result.x;
+       *y = pTracker->result.y;
+       *width = pTracker->result.width;
+       *height = pTracker->result.height;
+
+       LOGD("x:%d, y:%d w: %d, h: %d", *x, *y, *width, *height);
+
        LOGD("LEAVE");
        return MEDIA_VISION_ERROR_NONE;
 }
\ No newline at end of file
index eddb8c7ca5590d49c4157ec8214ab2deaf7256d0..7c8436402559d79316fc9ebecbd5133905dc2451 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ * 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.
@@ -49,8 +49,17 @@ TEST(TrackerTest, TrackerClassShouldBeOk)
        ret = ImageHelper::loadImageToSource(image_path.c_str(), mv_source);
        ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
-       mv_roi_tracker_result_s result;
-       ret = mv_roi_tracker_perform(handle, mv_source, &result);
+       ret = mv_roi_tracker_perform(handle, mv_source);
+       ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+       int x, y, width, height;
+       ret = mv_roi_tracker_get_result(handle, &x, &y, &width, &height);
+       ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+       ret = mv_roi_tracker_perform(handle, mv_source);
+       ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+       ret = mv_roi_tracker_get_result(handle, &x, &y, &width, &height);
        ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
        ret = mv_roi_tracker_destroy(handle);