/**
* @internal
- * @brief Gets the facial landmark positions on the @a source.
+ * @brief Gets the result count to objects.
+ *
+ * @since_tizen 9.0
+ *
+ * @param[in] handle The handle to the inference
+ * @param[out] result_cnt A number of results.
+ *
+ * @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
+ *
+ * @pre Create a source handle by calling mv_create_source()
+ * @pre Create an inference handle by calling mv_facial_landmark_create()
+ * @pre Prepare an inference by calling mv_facial_landmark_configure()
+ * @pre Prepare an inference by calling mv_facial_landmark_prepare()
+ * @pre Request an inference by calling mv_facial_landmark_inference()
+ */
+int mv_facial_landmark_get_result_count(mv_facial_landmark_h handle, unsigned int *result_cnt);
+
+/**
+ * @internal
+ * @brief Gets the facial landmark position values to a given index.
*
* @since_tizen 9.0
* @remarks pos_x and pos_y arrays are allocated internally by the framework and will remain valid
* in asynchronous mode until the handle is released.
*
* @param[in] handle The handle to the inference
- * @param[out] number_of_landmarks A number of landmarks detected.
+ * @param[in] index A result index.
+ * @param[out] frame_number A frame number inferenced.
* @param[out] pos_x An array containing x-coordinate values.
* @param[out] pos_y An array containing y-coordinate values.
*
* @pre Prepare an inference by calling mv_facial_landmark_configure()
* @pre Prepare an inference by calling mv_facial_landmark_prepare()
* @pre Prepare an inference by calling mv_facial_landmark_inference()
+ * @pre Get result count by calling mv_facial_landmark_get_result_count()
*/
-int mv_facial_landmark_get_positions(mv_facial_landmark_h handle, unsigned int *number_of_landmarks,
- unsigned int **pos_x, unsigned int **pos_y);
+int mv_facial_landmark_get_result(mv_facial_landmark_h handle, unsigned int index, unsigned long *frame_number,
+ unsigned int *pos_x, unsigned int *pos_y);
/**
* @internal
int mv_pose_landmark_inference_async(mv_pose_landmark_h handle, mv_source_h source);
/**
- * @brief Gets the pose landmark positions on the @a source.
+ * @internal
+ * @brief Gets the result count to objects.
+ *
+ * @since_tizen 9.0
+ *
+ * @param[in] handle The handle to the inference
+ * @param[out] result_cnt A number of results.
+ *
+ * @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
+ *
+ * @pre Create a source handle by calling mv_create_source()
+ * @pre Create an inference handle by calling mv_pose_landmark_create()
+ * @pre Prepare an inference by calling mv_pose_landmark_configure()
+ * @pre Prepare an inference by calling mv_pose_landmark_prepare()
+ * @pre Request an inference by calling mv_pose_landmark_inference()
+ */
+int mv_pose_landmark_get_result_count(mv_pose_landmark_h handle, unsigned int *result_cnt);
+
+/**
+ * @internal
+ * @brief Gets the pose landmark position values to a given index.
*
* @since_tizen 9.0
* @remarks pos_x and pos_y arrays are allocated internally by the framework and will remain valid
* please copy them to user memory and use the copy.
*
* This function operates differently depending on the inference request method.
- * - After mv_pose_landmark_inference() calls, this function returns pose landmark positions immediately.
- * - After mv_pose_landmark_inference_async() calls, this function can be blocked until the asynchronous inference request is completed
- * or, the timeout occurs if no result within 3 seconds.
+ * - After mv_facial_landmark_inference() calls, this function returns facial landmark positions immediately.
+ * - After mv_facial_landmark_inference_async() calls, this function can be blocked until the asynchronous inference request is completed
+ * or the timeout occurs if no result within 3 seconds.
*
- * Additionally, after calling the mv_pose_landmark_inference_async function, the function operates
+ * Additionally, after calling the mv_facial_landmark_inference_async function, the function operates
* in asynchronous mode until the handle is released.
*
* @param[in] handle The handle to the inference
- * @param[out] number_of_landmarks A number of landmarks detected.
+ * @param[in] index A result index.
+ * @param[out] frame_number A frame number inferenced.
* @param[out] pos_x An array containing x-coordinate values.
* @param[out] pos_y An array containing y-coordinate values.
*
* @pre Prepare an inference by calling mv_pose_landmark_configure()
* @pre Prepare an inference by calling mv_pose_landmark_prepare()
* @pre Prepare an inference by calling mv_pose_landmark_inference()
+ * @pre Get result count by calling mv_pose_landmark_get_result_count()
*/
-int mv_pose_landmark_get_pos(mv_pose_landmark_h handle, unsigned int *number_of_landmarks, unsigned int **pos_x,
- unsigned int **pos_y);
+int mv_pose_landmark_get_result(mv_pose_landmark_h handle, unsigned int index, unsigned long *frame_number,
+ unsigned int *pos_x, unsigned int *pos_y);
/**
* @brief Set user-given backend and device types for inference.
virtual void perform(mv_source_h &mv_src) = 0;
virtual void performAsync(LandmarkDetectionInput &input) = 0;
virtual LandmarkDetectionResult &getOutput() = 0;
+ virtual LandmarkDetectionResult &getOutputCache() = 0;
};
} // machine_learning
public:
LandmarkDetection(LandmarkDetectionTaskType task_type, std::shared_ptr<Config> config);
virtual ~LandmarkDetection() = default;
- void preDestroy();
- LandmarkDetectionTaskType getTaskType();
- void setEngineInfo(std::string engine_type_name, std::string device_type_name);
- unsigned int getNumberOfEngines();
- const std::string &getEngineType(unsigned int engine_index);
- unsigned int getNumberOfDevices(const std::string &engine_type);
- const std::string &getDeviceType(const std::string &engine_type, unsigned int device_index);
- void configure();
- void prepare();
- void perform(mv_source_h &mv_src);
- void performAsync(LandmarkDetectionInput &input);
- LandmarkDetectionResult &getOutput();
+ void preDestroy() override;
+ LandmarkDetectionTaskType getTaskType() override;
+ void setEngineInfo(std::string engine_type_name, std::string device_type_name) override;
+ unsigned int getNumberOfEngines() override;
+ const std::string &getEngineType(unsigned int engine_index) override;
+ unsigned int getNumberOfDevices(const std::string &engine_type) override;
+ const std::string &getDeviceType(const std::string &engine_type, unsigned int device_index) override;
+ void configure() override;
+ void prepare() override;
+ void perform(mv_source_h &mv_src) override;
+ void performAsync(LandmarkDetectionInput &input) override;
+ LandmarkDetectionResult &getOutput() override;
+ LandmarkDetectionResult &getOutputCache() override;
};
} // machine_learning
OutputBaseType &FacialLandmarkAdapter::getOutputCache()
{
- throw InvalidOperation("Not support yet.");
+ return _landmark_detection->getOutputCache();
}
}
return _current_result;
}
+template<typename T> LandmarkDetectionResult &LandmarkDetection<T>::getOutputCache()
+{
+ return _current_result;
+}
+
template<typename T> void LandmarkDetection<T>::performAsync(LandmarkDetectionInput &input)
{
if (!_async_manager) {
OutputBaseType &PoseLandmarkAdapter::getOutputCache()
{
- throw InvalidOperation("Not support yet.");
+ return _landmark_detection->getOutputCache();
}
}
return MEDIA_VISION_ERROR_NONE;
}
-int mv_facial_landmark_get_positions(mv_facial_landmark_h handle, unsigned int *number_of_landmarks,
- unsigned int **pos_x, unsigned int **pos_y)
+int mv_facial_landmark_get_result_count(mv_facial_landmark_h handle, unsigned int *result_cnt)
{
MEDIA_VISION_SUPPORT_CHECK(mv_check_feature_key(feature_keys, num_keys, true));
MEDIA_VISION_INSTANCE_CHECK(handle);
- MEDIA_VISION_INSTANCE_CHECK(number_of_landmarks);
- MEDIA_VISION_INSTANCE_CHECK(pos_x);
- MEDIA_VISION_INSTANCE_CHECK(pos_y);
+ MEDIA_VISION_INSTANCE_CHECK(result_cnt);
MEDIA_VISION_FUNCTION_ENTER();
try {
auto &result = static_cast<LandmarkDetectionResult &>(machine_learning_native_get_result(handle, TASK_NAME));
- *number_of_landmarks = result.number_of_landmarks;
- *pos_x = result.x_pos.data();
- *pos_y = result.y_pos.data();
+ *result_cnt = result.number_of_landmarks;
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
return MEDIA_VISION_ERROR_NONE;
}
+
+int mv_facial_landmark_get_result(mv_facial_landmark_h handle, unsigned int index, unsigned long *frame_number,
+ unsigned int *pos_x, unsigned int *pos_y)
+{
+ MEDIA_VISION_SUPPORT_CHECK(mv_check_feature_key(feature_keys, num_keys, true));
+ MEDIA_VISION_INSTANCE_CHECK(handle);
+ MEDIA_VISION_INSTANCE_CHECK(frame_number);
+ MEDIA_VISION_INSTANCE_CHECK(pos_x);
+ MEDIA_VISION_INSTANCE_CHECK(pos_y);
+
+ MEDIA_VISION_FUNCTION_ENTER();
+
+ try {
+ auto &result =
+ static_cast<LandmarkDetectionResult &>(machine_learning_native_get_result_cache(handle, TASK_NAME));
+ if (index >= result.number_of_landmarks) {
+ LOGE("Invalid index(index = %u, result count = %u).", index, result.number_of_landmarks);
+ return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ }
+
+ *frame_number = result.frame_number;
+ *pos_x = result.x_pos[index];
+ *pos_y = result.y_pos[index];
+ } catch (const BaseException &e) {
+ LOGE("%s", e.what());
+ return e.getError();
+ }
+
+ MEDIA_VISION_FUNCTION_LEAVE();
+
+ return MEDIA_VISION_ERROR_NONE;
+}
\ No newline at end of file
return MEDIA_VISION_ERROR_NONE;
}
-int mv_pose_landmark_get_pos(mv_pose_landmark_h handle, unsigned int *number_of_landmarks, unsigned int **pos_x,
- unsigned int **pos_y)
+int mv_pose_landmark_get_result_count(mv_pose_landmark_h handle, unsigned int *result_cnt)
{
MEDIA_VISION_SUPPORT_CHECK(mv_check_feature_key(feature_keys, num_keys, true));
MEDIA_VISION_INSTANCE_CHECK(handle);
- MEDIA_VISION_INSTANCE_CHECK(number_of_landmarks);
- MEDIA_VISION_INSTANCE_CHECK(pos_x);
- MEDIA_VISION_INSTANCE_CHECK(pos_y);
+ MEDIA_VISION_INSTANCE_CHECK(result_cnt);
MEDIA_VISION_FUNCTION_ENTER();
try {
auto &result = static_cast<LandmarkDetectionResult &>(machine_learning_native_get_result(handle, TASK_NAME));
- *number_of_landmarks = result.number_of_landmarks;
- *pos_x = result.x_pos.data();
- *pos_y = result.y_pos.data();
+ *result_cnt = result.number_of_landmarks;
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
return MEDIA_VISION_ERROR_NONE;
}
+
+int mv_pose_landmark_get_result(mv_pose_landmark_h handle, unsigned int index, unsigned long *frame_number,
+ unsigned int *pos_x, unsigned int *pos_y)
+{
+ MEDIA_VISION_SUPPORT_CHECK(mv_check_feature_key(feature_keys, num_keys, true));
+ MEDIA_VISION_INSTANCE_CHECK(handle);
+ MEDIA_VISION_INSTANCE_CHECK(frame_number);
+ MEDIA_VISION_INSTANCE_CHECK(pos_x);
+ MEDIA_VISION_INSTANCE_CHECK(pos_y);
+
+ MEDIA_VISION_FUNCTION_ENTER();
+
+ try {
+ auto &result =
+ static_cast<LandmarkDetectionResult &>(machine_learning_native_get_result_cache(handle, TASK_NAME));
+ if (index >= result.number_of_landmarks) {
+ LOGE("Invalid index(index = %u, result count = %u).", index, result.number_of_landmarks);
+ return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ }
+
+ *frame_number = result.frame_number;
+ *pos_x = result.x_pos[index];
+ *pos_y = result.y_pos[index];
+ } catch (const BaseException &e) {
+ LOGE("%s", e.what());
+ return e.getError();
+ }
+
+ MEDIA_VISION_FUNCTION_LEAVE();
+
+ return MEDIA_VISION_ERROR_NONE;
+}
\ No newline at end of file
// TODO.
};
- const unsigned int answer[][5] = { { 42, 87, 63, 48, 83 }, { 32, 31, 53, 75, 76 } };
+ const unsigned int coordinate_answers[][5] = { { 42, 87, 63, 48, 83 }, { 32, 31, 53, 75, 76 } };
mv_source_h mv_source = NULL;
int ret = mv_create_source(&mv_source);
ret = mv_facial_landmark_inference(handle, mv_source);
ASSERT_EQ(ret, 0);
- unsigned int number_of_landmarks;
- unsigned int *x_pos = nullptr, *y_pos = nullptr;
+ unsigned int number_of_objects;
- ret = mv_facial_landmark_get_positions(handle, &number_of_landmarks, &x_pos, &y_pos);
- ASSERT_EQ(ret, 0);
+ ret = mv_facial_landmark_get_result_count(handle, &number_of_objects);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ for (unsigned int idx = 0; idx < number_of_objects; ++idx) {
+ unsigned long frame_number;
+ unsigned int pos_x, pos_y;
+
+ ret = mv_facial_landmark_get_result(handle, idx, &frame_number, &pos_x, &pos_y);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
- for (unsigned int idx = 0; idx < number_of_landmarks; ++idx) {
- int distance_x = x_pos[idx] - answer[0][idx];
- int distance_y = y_pos[idx] - answer[1][idx];
+ int distance_x = pos_x - coordinate_answers[0][idx];
+ int distance_y = pos_y - coordinate_answers[1][idx];
distance_x = distance_x < 0 ? distance_x * -1 : distance_x;
distance_y = distance_y < 0 ? distance_y * -1 : distance_y;
ret = mv_pose_landmark_inference(handle, mv_source);
ASSERT_EQ(ret, 0);
- unsigned int number_of_landmarks;
- unsigned int *x_pos = nullptr, *y_pos = nullptr;
+ unsigned int number_of_objects;
- ret = mv_pose_landmark_get_pos(handle, &number_of_landmarks, &x_pos, &y_pos);
- ASSERT_EQ(ret, 0);
+ ret = mv_pose_landmark_get_result_count(handle, &number_of_objects);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ for (unsigned int idx = 0; idx < number_of_objects; ++idx) {
+ unsigned long frame_number;
+ unsigned int pos_x, pos_y;
+
+ ret = mv_pose_landmark_get_result(handle, idx, &frame_number, &pos_x, &pos_y);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
- for (unsigned int idx = 0; idx < number_of_landmarks; ++idx) {
- int distance_x = x_pos[idx] - coordinate_answers[0][idx];
- int distance_y = y_pos[idx] - coordinate_answers[1][idx];
+ int distance_x = pos_x - coordinate_answers[0][idx];
+ int distance_y = pos_y - coordinate_answers[1][idx];
distance_x = distance_x < 0 ? distance_x * -1 : distance_x;
distance_y = distance_y < 0 ? distance_y * -1 : distance_y;
void pose_landmark_callback(void *user_data)
{
- unsigned int number_of_landmarks;
- unsigned int *x_pos = nullptr, *y_pos = nullptr;
- unsigned long frame_number = 0;
mv_pose_landmark_h handle = static_cast<mv_pose_landmark_h>(user_data);
const unsigned int coordinate_answers[][10] = { { 300, 300, 275, 250, 325, 325, 225, 225, 350, 375 },
{ 50, 87, 100, 137, 100, 137, 187, 250, 187, 250 } };
- while (frame_number < MAX_INFERENCE_ITERATION - 10) {
- int ret = mv_pose_landmark_get_pos(handle, &number_of_landmarks, &x_pos, &y_pos);
+ bool is_loop_exit = false;
+
+ while (!is_loop_exit) {
+ unsigned int number_of_objects;
+
+ int ret = mv_pose_landmark_get_result_count(handle, &number_of_objects);
if (ret == MEDIA_VISION_ERROR_INVALID_OPERATION)
break;
ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
- for (unsigned int idx = 0; idx < number_of_landmarks; ++idx) {
- int distance_x = x_pos[idx] - coordinate_answers[0][idx];
- int distance_y = y_pos[idx] - coordinate_answers[1][idx];
+ for (unsigned int idx = 0; idx < number_of_objects; ++idx) {
+ unsigned long frame_number;
+ unsigned int pos_x, pos_y;
+
+ ret = mv_pose_landmark_get_result(handle, idx, &frame_number, &pos_x, &pos_y);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ if (frame_number > MAX_INFERENCE_ITERATION - 10)
+ is_loop_exit = true;
+
+ int distance_x = pos_x - coordinate_answers[0][idx];
+ int distance_y = pos_y - coordinate_answers[1][idx];
distance_x = distance_x < 0 ? distance_x * -1 : distance_x;
distance_y = distance_y < 0 ? distance_y * -1 : distance_y;
void facial_landmark_callback(void *user_data)
{
- unsigned int number_of_landmarks;
- unsigned int *x_pos = nullptr, *y_pos = nullptr;
- unsigned long frame_number = 0;
mv_facial_landmark_h handle = static_cast<mv_facial_landmark_h>(user_data);
const unsigned int coordinate_answers[][5] = { { 42, 87, 63, 48, 83 }, { 32, 31, 53, 75, 76 } };
+ bool is_loop_exit = false;
- while (frame_number < MAX_INFERENCE_ITERATION - 10) {
- int ret = mv_facial_landmark_get_positions(handle, &number_of_landmarks, &x_pos, &y_pos);
+ while (!is_loop_exit) {
+ unsigned int number_of_objects;
+
+ int ret = mv_facial_landmark_get_result_count(handle, &number_of_objects);
if (ret == MEDIA_VISION_ERROR_INVALID_OPERATION)
break;
ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
- for (unsigned int idx = 0; idx < number_of_landmarks; ++idx) {
- int distance_x = x_pos[idx] - coordinate_answers[0][idx];
- int distance_y = y_pos[idx] - coordinate_answers[1][idx];
+ for (unsigned int idx = 0; idx < number_of_objects; ++idx) {
+ unsigned long frame_number;
+ unsigned int pos_x, pos_y;
+
+ ret = mv_facial_landmark_get_result(handle, idx, &frame_number, &pos_x, &pos_y);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ if (frame_number > MAX_INFERENCE_ITERATION - 10)
+ is_loop_exit = true;
+
+ int distance_x = pos_x - coordinate_answers[0][idx];
+ int distance_y = pos_y - coordinate_answers[1][idx];
distance_x = distance_x < 0 ? distance_x * -1 : distance_x;
distance_y = distance_y < 0 ? distance_y * -1 : distance_y;