/**
* @internal
- * @brief Creates a inference handle for object detection object.
+ * @brief Creates a inference handle for face detection object.
* @details Use this function to create a inference handle. After the creation
- * the object detection 3d task has to be prepared with
+ * the face detection task has to be prepared with
* mv_face_detection_prepare() function to prepare a network
* for the inference.
*
*
* @since_tizen 8.0
*
- * @param[in] handle The handle to the object detection object.
+ * @param[in] handle The handle to the face detection object.
* @param[in] model_name Model name.
* @param[in] model_file Model file name.
* @param[in] meta_file Model meta file name.
* @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation
*
- * @pre Create a object detection handle by calling @ref mv_face_detection_create()
+ * @pre Create a face detection handle by calling @ref mv_face_detection_create()
*/
int mv_face_detection_set_model(mv_face_detection_h handle, const char *model_name, const char *model_file,
const char *meta_file, const char *label_file);
/**
* @internal
- * @brief Configures the backend for the object detection inference.
+ * @brief Configures the backend for the face detection inference.
*
* @since_tizen 8.0
*
/**
* @internal
- * @brief Prepares the object detection inference
- * @details Use this function to prepare the object detection inference based on
+ * @brief Prepares the face detection inference
+ * @details Use this function to prepare the face detection inference based on
* the configured network.
*
* @since_tizen 8.0
/**
* @internal
- * @brief Performs the object detection inference on the @a source.
+ * @brief Performs the face detection inference on the @a source.
*
* @since_tizen 8.0
* @remarks This function is synchronous and may take considerable time to run.
* isn't supported
*
* @pre Create a source handle by calling mv_create_source()
- * @pre Create an inference handle by calling mv_object_detect_create()
- * @pre Prepare an inference by calling mv_object_detect_configure()
- * @pre Prepare an inference by calling mv_object_detect_prepare()
+ * @pre Create an inference handle by calling mv_face_detect_create()
+ * @pre Prepare an inference by calling mv_face_detect_configure()
+ * @pre Prepare an inference by calling mv_face_detect_prepare()
*/
int mv_face_detection_inference(mv_face_detection_h handle, mv_source_h source);
/**
* @internal
- * @brief Gets the object detection inference result on the @a source.
+ * @brief Performs asynchronously the face detection inference on the @a source.
+ *
+ * @since_tizen 7.5
+ * @remarks This function operates asynchronously, so it returns immediately upon invocation.
+ * Therefore, user needs to receive the result though a given callback function.
+ *
+ * @param[in] handle The handle to the inference
+ * @param[in] source The handle to the source of the media
+ * @param[in] completion_cb A callback which is called internally by the framework
+ * once the given inference request is completed.
+ * @param[in] user_data A pointer to user data object.
+ *
+ * @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_face_detect_create()
+ * @pre Prepare an inference by calling mv_face_detect_configure()
+ * @pre Prepare an inference by calling mv_face_detect_prepare()
+ */
+int mv_face_detection_inference_async(mv_face_detection_h handle, mv_source_h source, mv_completion_cb completion_cb,
+ void *user_data);
+
+/**
+ * @internal
+ * @brief Gets the face detection inference result on the @a source.
*
* @since_tizen 8.0
*
* @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_object_detect_create()
- * @pre Prepare an inference by calling mv_object_detect_configure()
- * @pre Prepare an inference by calling mv_object_detect_prepare()
- * @pre Prepare an inference by calling mv_object_detect_inference()
+ * @pre Create an inference handle by calling mv_face_detect_create()
+ * @pre Prepare an inference by calling mv_face_detect_configure()
+ * @pre Prepare an inference by calling mv_face_detect_prepare()
+ * @pre Prepare an inference by calling mv_face_detect_inference()
*/
int mv_face_detection_get_result(mv_face_detection_h handle, unsigned int *number_of_objects,
const unsigned int **indices, const float **confidences, const int **left,
* @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_object_detect_create()
- * @pre Prepare an inference by calling mv_object_detect_configure()
- * @pre Prepare an inference by calling mv_object_detect_prepare()
- * @pre Prepare an inference by calling mv_object_detect_inference()
+ * @pre Create an inference handle by calling mv_face_detect_create()
+ * @pre Prepare an inference by calling mv_face_detect_configure()
+ * @pre Prepare an inference by calling mv_face_detect_prepare()
+ * @pre Prepare an inference by calling mv_face_detect_inference()
*/
int mv_face_detection_get_label(mv_face_detection_h handle, const unsigned int index, const char **label);
*
* @since_tizen 8.0
*
- * @param[in] handle The handle to the object detection object.
+ * @param[in] handle The handle to the face detection object.
* @param[in] engine_type A string of inference engine type.
* @param[in] device_type A string of device type.
*
* @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation
*
- * @pre Create a object detection handle by calling @ref mv_face_detection_create()
+ * @pre Create a face detection handle by calling @ref mv_face_detection_create()
*/
int mv_face_detection_set_engine(mv_face_detection_h handle, const char *engine_type, const char *device_type);
/**
* @internal
- * @brief Gets a number of inference engines available for object detection task API.
- * @details Use this function to get how many inference engines are supported for object detection after calling @ref mv_face_detection_create().
+ * @brief Gets a number of inference engines available for face detection task API.
+ * @details Use this function to get how many inference engines are supported for face detection after calling @ref mv_face_detection_create().
*
* @since_tizen 8.0
*
- * @param[in] handle The handle to the object detection object.
- * @param[out] engine_count A number of inference engines available for object detection API.
+ * @param[in] handle The handle to the face detection object.
+ * @param[out] engine_count A number of inference engines available for face detection API.
*
* @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 Create a object detection handle by calling @ref mv_face_detection_create()
+ * @pre Create a face detection handle by calling @ref mv_face_detection_create()
*/
int mv_face_detection_get_engine_count(mv_face_detection_h handle, unsigned int *engine_count);
*
* @since_tizen 8.0
*
- * @param[in] handle The handle to the object detection object.
+ * @param[in] handle The handle to the face detection object.
* @param[in] engine_index A inference engine index for getting the inference engine type.
* @param[out] engine_type A string to inference engine.
*
* @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation
*
- * @pre Get a number of inference engines available for object detection task API by calling @ref mv_face_detection_get_engine_count()
+ * @pre Get a number of inference engines available for face detection task API by calling @ref mv_face_detection_get_engine_count()
*/
int mv_face_detection_get_engine_type(mv_face_detection_h handle, const unsigned int engine_index, char **engine_type);
*
* @since_tizen 8.0
*
- * @param[in] handle The handle to the object detection object.
+ * @param[in] handle The handle to the face detection object.
* @param[in] engine_type A inference engine string.
* @param[out] device_count A number of device types available for a given inference engine.
*
* @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation
*
- * @pre Create a object detection handle by calling @ref mv_face_detection_create()
+ * @pre Create a face detection handle by calling @ref mv_face_detection_create()
*/
int mv_face_detection_get_device_count(mv_face_detection_h handle, const char *engine_type, unsigned int *device_count);
*
* @since_tizen 8.0
*
- * @param[in] handle The handle to the object detection object.
+ * @param[in] handle The handle to the face detection object.
* @param[in] engine_type A inference engine string.
* @param[in] device_index A device index for getting the device type.
* @param[out] device_type A string to device type.
* @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation
*
- * @pre Create a object detection handle by calling @ref mv_face_detection_create()
- * @pre Configure object detection task by calling @ref mv_face_detection_configure()
+ * @pre Create a face detection handle by calling @ref mv_face_detection_create()
+ * @pre Configure face detection task by calling @ref mv_face_detection_configure()
*/
int mv_face_detection_get_device_type(mv_face_detection_h handle, const char *engine_type,
const unsigned int device_index, char **device_type);
#include "ImageHelper.h"
#include "mv_object_detection_internal.h"
+#include "mv_face_detection_internal.h"
#define IMG_DOG TEST_RES_PATH "/res/inference/images/dog2.jpg"
+#define IMG_FACE TEST_RES_PATH "/res/inference/images/faceDetection.jpg"
#define MAX_INFERENCE_ITERATION 20
using namespace testing;
mv_source_h source;
};
-void completion_callback(mv_object_detection_h handle, void *user_data)
+void object_detection_completion_callback(mv_object_detection_h handle, void *user_data)
{
unsigned int number_of_objects;
const int *left, *top, *right, *bottom;
int ret = mv_object_detection_get_result(handle, &number_of_objects, &indices, &confidences, &left, &top, &right,
&bottom);
- ASSERT_EQ(ret, 0);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
for (unsigned int idx = 0; idx < number_of_objects; ++idx) {
cout << "index = " << indices[idx] << " probability = " << confidences[idx] << " " << left[idx] << " x "
const char *label;
ret = mv_object_detection_get_label(handle, indices[idx], &label);
- ASSERT_EQ(ret, 0);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
cout << "index = " << indices[idx] << " label = " << label << endl;
string label_str(label);
transform(label_str.begin(), label_str.end(), label_str.begin(), ::toupper);
- ASSERT_TRUE(label_str == test_model->answer);
+ ASSERT_EQ(label_str, test_model->answer);
}
}
model.source = mv_source;
- ret = mv_object_detection_inference_async(handle, mv_source, completion_callback,
+ ret = mv_object_detection_inference_async(handle, mv_source, object_detection_completion_callback,
reinterpret_cast<void *>(&model));
- ASSERT_EQ(ret, 0);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
ret = mv_destroy_source(mv_source);
ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
ret = mv_object_detection_destroy(handle);
ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
}
+}
+
+void face_detection_completion_callback(mv_object_detection_h handle, void *user_data)
+{
+ unsigned int number_of_objects;
+ const int *left, *top, *right, *bottom;
+ const unsigned int *indices;
+ const float *confidences;
+ model_info *test_model(static_cast<model_info *>(user_data));
+
+ int ret = mv_face_detection_get_result(handle, &number_of_objects, &indices, &confidences, &left, &top, &right,
+ &bottom);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ for (unsigned int idx = 0; idx < number_of_objects; ++idx) {
+ cout << "index = " << indices[idx] << " probability = " << confidences[idx] << " " << left[idx] << " x "
+ << top[idx] << " ~ " << right[idx] << " x " << bottom[idx] << endl;
+ }
+
+ for (unsigned int idx = 0; idx < number_of_objects; ++idx) {
+ const char *label;
+
+ ret = mv_face_detection_get_label(handle, indices[idx], &label);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+ cout << "index = " << indices[idx] << " label = " << label << endl;
+
+ string label_str(label);
+
+ transform(label_str.begin(), label_str.end(), label_str.begin(), ::toupper);
+
+ ASSERT_EQ(label_str, test_model->answer);
+ }
+}
+
+TEST(FaceDetectionAsyncTest, InferenceShouldBeOk)
+{
+ mv_object_detection_h handle;
+ vector<model_info> test_models {
+ { "", "", "", "", "FACE" } // If empty then default model will be used.
+ // TODO.
+ };
+
+ for (auto &model : test_models) {
+ int ret = mv_face_detection_create(&handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ cout << "model name : " << model.model_file << endl;
+
+ mv_face_detection_set_model(handle, model.model_name.c_str(), model.model_file.c_str(), model.meta_file.c_str(),
+ model.label_file.c_str());
+ mv_face_detection_set_engine(handle, "tflite", "cpu");
+
+ ret = mv_face_detection_configure(handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_face_detection_prepare(handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ for (unsigned int iter = 0; iter < MAX_INFERENCE_ITERATION; ++iter) {
+ mv_source_h mv_source = NULL;
+ ret = mv_create_source(&mv_source);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = ImageHelper::loadImageToSource(IMG_FACE, mv_source);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ model.source = mv_source;
+
+ ret = mv_face_detection_inference_async(handle, mv_source, face_detection_completion_callback,
+ reinterpret_cast<void *>(&model));
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_destroy_source(mv_source);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+ }
+
+ ret = mv_face_detection_destroy(handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+ }
}
\ No newline at end of file