*/
/**
+ * @brief Defines #MV_ROI_TRACKER_TYPE to set the type used
+ * for tracker type attribute of the engine configuration.
+ * @details Switches between SPEED, BALANCED, or ACCURACY\n
+ * #MV_ROI_TRACKER_TYPE_ACCURACY,\n
+ * #MV_ROI_TRACKER_TYPE_BALANCE,\n
+ * #MV_ROI_TRACKER_TYPE_SPEED.\n
+ *
+ * The default type is MV_ROI_TRACKER_TYPE_BALANCE.
+ *
+ * @since_tizen 7.0
+ * @see mv_engine_config_set_int_attribute()
+ * @see mv_engine_config_get_int_attribute()
+ */
+#define MV_ROI_TRACKER_TYPE "MV_ROI_TRACKER_TYPE"
+
+/**
* @brief Creates tracker handle.
* @details Use this function to create a tracker handle.
*
int mv_roi_tracker_destroy(mv_roi_tracker_h handle);
/**
- * @brief Sets initial ROI coordinates to tracker object handle.
+ * @brief Configures the attributes of the roi tracker.
+ * @details Use this function to configure the attributes of the roi tracker
+ * which is set to @a engine_config.
*
* @since_tizen 7.0
*
- * @param[in] handle The tracker handle to set coordinates.
- * @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
+ * @param[in] handle The handle to the roi tracker
+ * @param[in] engine_config The handle to the configuration of
+ * engine.
*
* @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
- *
- * @see mv_roi_tracker_create()
+ * in @a engine_config
*/
-int mv_roi_tracker_set_coordinate(mv_roi_tracker_h handle, int x, int y, int width, int height);
+int mv_roi_tracker_configure(mv_roi_tracker_h handle,
+ mv_engine_config_h engine_config);
/**
- * @brief Sets tracker type to ROI tracker object handle.
+ * @brief Prepares roi tracker.
+ * @details Use this function to prepare roi tracker based on
+ * the configurtion.
*
* @since_tizen 7.0
*
- * @param[in] handle The tracker handle to set tracker type.
- * @param[in] type The tracker type option to be set
- *
+ * @param[in] handle The handle to the roi tracker
+ * @param[in] x The x coordinate to set ROI to be tracked
+ * @param[in] y The y coordinate to set ROI to be tracked
+ * @param[in] width The width to set ROI to be tracked
+ * @param[in] height The height to set ROI to be tracked
* @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
+ */
+int mv_roi_tracker_prepare(mv_roi_tracker_h handle, int x, int y, int width, int height);
+
+/**
+ * @brief Called when roi in @a source are detected.
+ * @details This type callback is invoked each time when
+ * mv_roi_tracker_perform() is called to provide
+ * the results of the tracked roi.
+ *
+ * @since_tizen 7.0
+ * @remarks The @a roi should not be released by app. They can be used only in the callback.
+ *
+ * @param[in] source The handle to the source of the media where
+ * roi tracker were performed. @a source is the same object
+ * for which mv_roi_tracker_perform() was called.
+ * It should be released by calling mv_destroy_source()
+ * when it's not needed anymore.
+ * @param[in] roi Roi of the tracked result.
+ * @param[in] user_data The user data passed from callback invoking code
*
- * @see mv_roi_tracker_create()
+ * @see mv_roi_tracker_perform()
*/
-int mv_roi_tracker_set_tracker_type(mv_roi_tracker_h handle, mv_roi_tracker_type_e type);
+typedef void (*mv_roi_tracker_tracked_cb)(
+ mv_source_h source,
+ mv_rectangle_s roi,
+ void *user_data);
+
/**
* @brief Tracks with a given tracker on the @a source.
*
* @param[in] handle The handle to the tracker object.
* @param[in] source The handle to the source of the media.
- *
+ * @param[in] tracked_cb The callback which will receive the tracked results.
+ * @param[in] user_data The user data passed from the code where
+ * mv_roi_tracker_perform() is invoked.
+ * This data will be accessible in @a tracked_cb callback.
* @return @c 0 on success, otherwise a negative error value
* @retval #MEDIA_VISION_ERROR_NONE Successful
* @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported
*
* @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);
+int mv_roi_tracker_perform(
+ mv_roi_tracker_h handle,
+ mv_source_h source,
+ mv_roi_tracker_tracked_cb tracked_cb,
+ void *user_data);
/**
- * @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);
-/**
* @}
*/
* @since_tizen 7.0
*/
typedef struct {
- 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 */
+ 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 */
+ bool initialized; /**< flag that struct is initialized or not */
} mv_roi_tracker_result_s;
/**
typedef enum {
MV_ROI_TRACKER_TYPE_NONE = 0, /**< None */
- MV_ROI_TRACKER_TYPE_SPEED, /**< Tracker type focused on speed */
+ MV_ROI_TRACKER_TYPE_ACCURACY, /**< Tracker type focused on accuracy */
MV_ROI_TRACKER_TYPE_BALANCE, /**< Tracker type focused on balance */
- MV_ROI_TRACKER_TYPE_ACCURACY /**< Tracker type focused on accuracy */
+ MV_ROI_TRACKER_TYPE_SPEED /**< Tracker type focused on speed */
} mv_roi_tracker_type_e;
/**
* @}
"name" : "MV_FACE_RECOGNITION_DECISION_THRESHOLD",
"type" : "double",
"value" : -0.85
+ },
+ {
+ "name" : "MV_ROI_TRACKER_TYPE",
+ "type" : "integer",
+ "value" : 2
}
]
}
ROITracker();
~ ROITracker() = default;
- mv_roi_tracker_result_s Initialize(cv::Mat &frame);
- mv_roi_tracker_result_s Update(cv::Mat &frame);
+ void perform(cv::Mat frame);
+ void getResult(int *x, int *y, int *width, int *height);
+ bool initialized();
+ int setConfiguration(mv_engine_config_h engine_config);
+ int setRoi(int x, int y, int width, int height);
+private:
+ void initialize(cv::Mat &frame);
+ void update(cv::Mat &frame);
+
cv::Ptr<cv::Tracker> cvTracker;
cv::Rect boundingBox;
- bool initialized;
mv_roi_tracker_type_e type;
mv_roi_tracker_result_s result;
};
} /* ROITracker */
} /* MediaVision */
-#endif /* __ROI_TRACKER_H__ */
\ No newline at end of file
+#endif /* __ROI_TRACKER_H__ */
* @brief Create tracker object handle.
* @details Use this function to create an tracker object handle.
* After creation the handle has to be performed with
- * @ref mv_roi_tracker_set_coordinate_open() function and
* @ref mv_roi_tracker_perform_open() function to perform
* an tracker object.
*
int mv_roi_tracker_destroy_open(mv_roi_tracker_h handle);
/**
- * @brief Set initial roi coordinates to roi tracker object handle.
- * @details Use this function to set coordinates want to track to an tracker object handle.
- * After setting coordinates, handle has to be performed with
- * @ref mv_roi_tracker_perform_open() function to perform
- * an tracker object.
+ * @brief Configure attributes to the roi tracker handle
*
* @since_tizen 7.0
*
- * @param [in] handle The handle to the tracker object to be created
- * @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] width The width to set initial ROI to be tracked
- * @param [in] height The height to set initial ROI to be tracked
+ * @param [in] handle The handle to the roi tracker
+ * @param [in] engine_config The handle to the configuration of
+ * engine.
+ *
* @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 tracker handle by calling @ref mv_roi_tracker_create_open()
- *
- * @see mv_roi_tracker_create_open()
+ * in @a engine_config
+ * @retval #MEDIA_VISION_ERROR_INVALID_PATH Invalid path of model data
+ * in @a engine_config
+ * @retval #MEDIA_VISION_ERROR_INVALID_DATA Invalid model data
+ * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported
*/
-int mv_roi_tracker_set_coordinate_open(mv_roi_tracker_h handle, int x, int y, int width, int height);
+int mv_roi_tracker_configure_engine_open(mv_roi_tracker_h handle,
+ mv_engine_config_h engine_config);
/**
- * @brief Sets default tracker to roi tracker object handle.
- * @details Use this function to set tracker want to set to an tracker object handle.
- * After setting tracker, handle has to be performed with
- * @ref mv_roi_tracker_perform_open() function to perform
- * an tracker object.
+ * @brief Prepare roi tracker.
+ * @details Use this function to prepare roi tracker based on
+ * the configured attributes.
*
* @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 roi tracker
+ * @param[in] x The x coordinate to set ROI to be tracked
+ * @param[in] y The y coordinate to set ROI to be tracked
+ * @param[in] width The width to set ROI to be tracked
+ * @param[in] height The height to set 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
- * @pre Create an tracker handle by calling @ref mv_roi_tracker_create_open()
- *
- * @see mv_roi_tracker_create_open()
*/
-int mv_roi_tracker_set_tracker_type_open(mv_roi_tracker_h handle, mv_roi_tracker_type_e type);
+int mv_roi_tracker_prepare_open(mv_roi_tracker_h handle, int x, int y, int width, int height);
/**
* @brief Track with a given roi on the @a 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 [in] handle The handle to the tracker object.
+ * @param [in] source The handle to the source of the media.
+ * @param [in] tracked_cb The callback which will be called for
+ * tracked roi on media source.
+ * This callback will receive the tracked roi.
+ * @param [in] user_data The user data passed from the code where
+ * @ref mv_roi_tracker_perform_open() is invoked. This data will
+ * be accessible from @a tracked_cb callback.
* @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 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);
+int mv_roi_tracker_perform_open(mv_roi_tracker_h handle, mv_source_h source, mv_roi_tracker_tracked_cb tracked_cb, void *user_data);
-/**
- * @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 */
namespace MediaVision {
namespace ROITracker {
+
+
ROITracker::ROITracker()
- : initialized(false),
- type(MV_ROI_TRACKER_TYPE_BALANCE),
- result()
+ : type(MV_ROI_TRACKER_TYPE_BALANCE)
{
+ result = (mv_roi_tracker_result_s) {
+ .x = -1,
+ .y = -1,
+ .width = -1,
+ .height = -1,
+ .initialized = false
+ };
}
-mv_roi_tracker_result_s ROITracker::Initialize(cv::Mat &frame)
+void ROITracker::initialize(cv::Mat &frame)
{
LOGI("ENTER");
boundingBox.width,
boundingBox.height);
+ if (cvTracker) {
+ LOGE("cvTracker already exists. 'mv_roi_tracker_destroy' should be called for removing cvTracker.");
+ throw std::runtime_error("tracker Initialize failed.");
+ }
+
cvTracker = createTrackerByName(type);
cvTracker->init(frame, boundingBox);
- initialized = true;
- LOGI("LEAVE");
- return mv_roi_tracker_result_s {
- boundingBox.x,
- boundingBox.y,
- boundingBox.width,
- boundingBox.height
+ result = (mv_roi_tracker_result_s) {
+ .x = boundingBox.x,
+ .y = boundingBox.y,
+ .width = boundingBox.width,
+ .height = boundingBox.height,
+ .initialized = true
};
+ LOGI("LEAVE");
}
-mv_roi_tracker_result_s ROITracker::Update(cv::Mat &frame)
+void ROITracker::update(cv::Mat &frame)
{
LOGI("ENTER");
//updates the tracker
if (cvTracker->update(frame, boundingBox)) {
+ result = (mv_roi_tracker_result_s) {
+ .x = boundingBox.x,
+ .y = boundingBox.y,
+ .width = boundingBox.width,
+ .height = boundingBox.height,
+ .initialized = true
+ };
LOGD(" Updated: x: %d, y: %d, w: %d, h: %d",
- boundingBox.x,
- boundingBox.y,
- boundingBox.width,
- boundingBox.height);
+ result.x,
+ result.y,
+ result.width,
+ result.height);
+
} else {
LOGE("update failed.");
+ result.initialized = false;
throw std::runtime_error("tracker update failed.");
}
LOGI("LEAVE");
- return mv_roi_tracker_result_s {
- boundingBox.x,
- boundingBox.y,
- boundingBox.width,
- boundingBox.height
- };
+}
+
+void ROITracker::perform(cv::Mat frame)
+{
+ if (!result.initialized)
+ initialize(frame);
+ else
+ update(frame);
+}
+
+void ROITracker::getResult(int *x, int *y, int *width, int *height)
+{
+ if (!result.initialized)
+ throw std::runtime_error("tracker getResult failed.");
+
+ *x = result.x;
+ *y = result.y;
+ *width = result.width;
+ *height = result.height;
+}
+
+int ROITracker::setConfiguration(mv_engine_config_h engine_config)
+{
+ int tracker_type = 0;
+ int ret = mv_engine_config_get_int_attribute(
+ engine_config, MV_ROI_TRACKER_TYPE, &tracker_type);
+ if (ret != MEDIA_VISION_ERROR_NONE) {
+ LOGE("Fail to get roi tracker type");
+ return MEDIA_VISION_ERROR_INVALID_OPERATION;
+ }
+
+ type = static_cast<mv_roi_tracker_type_e>(tracker_type);
+ LOGD("tracker_type: [%d] is set.", type);
+
+ return MEDIA_VISION_ERROR_NONE;
+}
+
+int ROITracker::setRoi(int x, int y, int width, int height)
+{
+ boundingBox = { x, y, width, height };
+
+ LOGD("ROI : x:%d, y:%d, w:%d, h:%d is set.",
+ boundingBox.x,
+ boundingBox.y,
+ boundingBox.width,
+ boundingBox.height);
+
+ LOGD("LEAVE");
+
+ return MEDIA_VISION_ERROR_NONE;
+}
+
+bool ROITracker::initialized()
+{
+ return result.initialized;
}
} /* ROITracker */
-} /* MediaVision */
\ No newline at end of file
+} /* MediaVision */
return ret;
}
-int mv_roi_tracker_set_coordinate(mv_roi_tracker_h handle, int x, int y, int width, int height)
+int mv_roi_tracker_configure(mv_roi_tracker_h handle,
+ mv_engine_config_h engine_config)
{
MEDIA_VISION_SUPPORT_CHECK(
- __mv_roi_tracking_check_system_info_feature_supported());
-
+ __mv_roi_tracking_check_system_info_feature_supported());
MEDIA_VISION_INSTANCE_CHECK(handle);
+ MEDIA_VISION_INSTANCE_CHECK(engine_config);
MEDIA_VISION_FUNCTION_ENTER();
- int ret = mv_roi_tracker_set_coordinate_open(handle, x, y, width, height);
-
- MEDIA_VISION_FUNCTION_LEAVE();
-
- return ret;
-}
-
-int mv_roi_tracker_set_tracker_type(mv_roi_tracker_h handle, mv_roi_tracker_type_e type)
-{
- MEDIA_VISION_SUPPORT_CHECK(
- __mv_roi_tracking_check_system_info_feature_supported());
-
- MEDIA_VISION_INSTANCE_CHECK(handle);
-
- MEDIA_VISION_FUNCTION_ENTER();
+ int ret = MEDIA_VISION_ERROR_NONE;
- int ret = mv_roi_tracker_set_tracker_type_open(handle, type);
+ ret = mv_roi_tracker_configure_engine_open(handle, engine_config);
+ if (ret != MEDIA_VISION_ERROR_NONE) {
+ LOGE("Fail to configure engine and target");
+ return ret;
+ }
MEDIA_VISION_FUNCTION_LEAVE();
-
return ret;
}
-int mv_roi_tracker_perform(mv_roi_tracker_h handle, mv_source_h source)
+int mv_roi_tracker_prepare(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());
-
+ __mv_roi_tracking_check_system_info_feature_supported());
MEDIA_VISION_INSTANCE_CHECK(handle);
- MEDIA_VISION_INSTANCE_CHECK(source);
+ 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_perform_open(handle, source);
+ int ret = MEDIA_VISION_ERROR_NONE;
- MEDIA_VISION_FUNCTION_LEAVE();
+ ret = mv_roi_tracker_prepare_open(handle, x, y, width, height);
+ 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)
+int mv_roi_tracker_perform(mv_roi_tracker_h handle, mv_source_h source, mv_roi_tracker_tracked_cb tracked_cb, void *user_data)
{
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_INSTANCE_CHECK(source);
MEDIA_VISION_FUNCTION_ENTER();
- int ret = mv_roi_tracker_get_result_open(handle, x, y, width, height);
+ int ret = mv_roi_tracker_perform_open(handle, source, tracked_cb, user_data);
MEDIA_VISION_FUNCTION_LEAVE();
LOGD("Destroying tracker handle [%p]", handle);
delete static_cast<ROITracker *>(handle);
- LOGD("Tracker handle has been destroyed");
LOGD("LEAVE");
return MEDIA_VISION_ERROR_NONE;
}
-int mv_roi_tracker_set_coordinate_open(mv_roi_tracker_h handle, int x, int y, int width, int height)
+int mv_roi_tracker_configure_engine_open(mv_roi_tracker_h handle,
+ mv_engine_config_h engine_config)
{
- LOGD("ENTER");
+ LOGI("ENTER");
if (!handle) {
LOGE("Handle is NULL.");
auto pTracker = static_cast<ROITracker *>(handle);
- pTracker->boundingBox = { x, y, width, height };
- LOGD("Init pos : x:%d, y:%d, w:%d, h:%d is set.",
- pTracker->boundingBox.x,
- pTracker->boundingBox.y,
- pTracker->boundingBox.width,
- pTracker->boundingBox.height);
+ int ret = pTracker->setConfiguration(engine_config);
+ if (ret != MEDIA_VISION_ERROR_NONE) {
+ LOGE("Fail to set configuration");
+ return ret;
+ }
+ LOGI("LEAVE");
- LOGD("LEAVE");
return MEDIA_VISION_ERROR_NONE;
}
-int mv_roi_tracker_set_tracker_type_open(mv_roi_tracker_h handle, mv_roi_tracker_type_e type)
+int mv_roi_tracker_prepare_open(mv_roi_tracker_h handle, int x, int y, int width, int height)
{
- LOGD("ENTER");
+ LOGI("ENTER");
if (!handle) {
LOGE("Handle is NULL.");
}
auto pTracker = static_cast<ROITracker *>(handle);
-
- if (!pTracker->initialized) {
- pTracker->type = type;
- LOGD("tracker_type: [%d] is set.", pTracker->type);
- } else {
- LOGW("This function is valid only in case that tracker isn't initialized.");
+ int ret = pTracker->setRoi(x, y, width, height);
+ if (ret != MEDIA_VISION_ERROR_NONE) {
+ LOGE("Fail to set roi");
+ return ret;
}
- LOGD("LEAVE");
+
+ LOGI("LEAVE");
+
return MEDIA_VISION_ERROR_NONE;
}
-int mv_roi_tracker_perform_open(mv_roi_tracker_h handle, mv_source_h source)
+int mv_roi_tracker_perform_open(mv_roi_tracker_h handle, mv_source_h source, mv_roi_tracker_tracked_cb tracked_cb, void *user_data)
{
LOGD("ENTER");
if (!handle) {
return MEDIA_VISION_ERROR_INVALID_PARAMETER;
}
- ROITracker *pTracker = static_cast<ROITracker *>(handle);
+ auto pTracker = static_cast<ROITracker *>(handle);
unsigned int channels = 0;
unsigned int width = 0, height = 0;
LOGD(" w: %d, h: %d, c: %d", width, height, channels);
try {
- cv::Mat frame = getTrackerFrame(colorspace, channels, width, height, buffer);
- if (!pTracker->initialized) {
- pTracker->result = pTracker->Initialize(frame);
- return MEDIA_VISION_ERROR_NONE;
- }
- pTracker->result = pTracker->Update(frame);
+ pTracker->perform(getTrackerFrame(colorspace, channels, width, height, buffer));
} 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;
- }
+ mv_rectangle_s roi;
+ pTracker->getResult(&roi.point.x, &roi.point.y, &roi.width, &roi.height);
- 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);
+ tracked_cb(source, roi, user_data);
LOGD("LEAVE");
return MEDIA_VISION_ERROR_NONE;
-}
\ No newline at end of file
+}
using namespace std;
using namespace MediaVision::Common;
+void _tracked_cb(mv_source_h source,
+ mv_rectangle_s roi,
+ void *user_data)
+{
+ printf("In callback: roi.x y width height : %d %d %d %d\n", roi.point.x, roi.point.y, roi.width, roi.height);
+}
+
+int perform_tracker_configure(mv_engine_config_h engine_cfg)
+{
+ int ret = mv_engine_config_set_int_attribute(
+ engine_cfg, MV_ROI_TRACKER_TYPE, (int)MV_ROI_TRACKER_TYPE_BALANCE);
+ if (ret != MEDIA_VISION_ERROR_NONE) {
+ printf("Fail to set roi tracker type");
+ return MEDIA_VISION_ERROR_INVALID_OPERATION;
+ }
+
+ return ret;
+}
+
TEST(TrackerTest, TrackerClassShouldBeOk)
{
mv_roi_tracker_h handle;
int ret = mv_roi_tracker_create(&handle);
ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
- ret = mv_roi_tracker_set_tracker_type(handle, MV_ROI_TRACKER_TYPE_BALANCE);
+ mv_engine_config_h config = NULL;
+ ret = mv_create_engine_config(&config);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = perform_tracker_configure(config);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_roi_tracker_configure(handle, config);
ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
- ret = mv_roi_tracker_set_coordinate(handle, 50, 50, 70, 70);
+ ret = mv_roi_tracker_prepare(handle, 50, 50, 50, 50);
ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
const string image_path = string("/usr/share/capi-media-vision/roi-tracker/tracker-test.jpeg");
ret = ImageHelper::loadImageToSource(image_path.c_str(), mv_source);
ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
- 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);
+ ret = mv_roi_tracker_perform(handle, mv_source, _tracked_cb, NULL);
ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
- ret = mv_roi_tracker_get_result(handle, &x, &y, &width, &height);
+ ret = mv_roi_tracker_perform(handle, mv_source, _tracked_cb, NULL);
ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
ret = mv_roi_tracker_destroy(handle);