diff options
author | Inki Dae <inki.dae@samsung.com> | 2024-07-22 16:58:09 +0900 |
---|---|---|
committer | Inki Dae <inki.dae@samsung.com> | 2024-09-23 06:53:49 +0000 |
commit | 21a011659ed5cdebbe2224029c3f7fb5e9774cfe (patch) | |
tree | d2a0ae5bbb5a19e4ccdbe5ae31650d8754e5a98f | |
parent | 853ea3fa4511d5e838edf3d523f546248563d8ef (diff) | |
download | mediavision-tizen_devel.tar.gz mediavision-tizen_devel.tar.bz2 mediavision-tizen_devel.zip |
test: add hand detection model test casetizen_devel
Change-Id: Ia752b12148b672e960e82cf14d8becfc3bba31b8
Signed-off-by: Inki Dae <inki.dae@samsung.com>
-rw-r--r-- | test/testsuites/machine_learning/object_detection/test_object_detection.cpp | 102 | ||||
-rw-r--r-- | test/testsuites/machine_learning/object_detection/test_object_detection_async.cpp | 141 |
2 files changed, 243 insertions, 0 deletions
diff --git a/test/testsuites/machine_learning/object_detection/test_object_detection.cpp b/test/testsuites/machine_learning/object_detection/test_object_detection.cpp index 151aafd5..6ab0410f 100644 --- a/test/testsuites/machine_learning/object_detection/test_object_detection.cpp +++ b/test/testsuites/machine_learning/object_detection/test_object_detection.cpp @@ -24,11 +24,14 @@ #include "ImageHelper.h" #include "mv_face_detection.h" #include "mv_face_detection_internal.h" +#include "mv_hand_detection.h" +#include "mv_hand_detection_internal.h" #include "mv_object_detection.h" #include "mv_object_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 IMG_HAND TEST_RES_PATH "/res/inference/images/handDetection.jpg" using namespace testing; using namespace std; @@ -109,6 +112,43 @@ TEST(FaceDetectionTest, GettingAvailableInferenceEnginesInfoShouldBeOk) ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); } +TEST(HandDetectionTest, GettingAvailableInferenceEnginesInfoShouldBeOk) +{ + mv_object_detection_h handle; + + int ret = mv_hand_detection_create(&handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + unsigned int engine_count = 0; + + ret = mv_hand_detection_get_engine_count(handle, &engine_count); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + ASSERT_GE(engine_count, 1); + + for (unsigned int engine_idx = 0; engine_idx < engine_count; ++engine_idx) { + char *engine_type = nullptr; + + ret = mv_hand_detection_get_engine_type(handle, engine_idx, &engine_type); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + unsigned int device_count = 0; + + ret = mv_hand_detection_get_device_count(handle, engine_type, &device_count); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + ASSERT_GE(device_count, 1); + + for (unsigned int device_idx = 0; device_idx < device_count; ++device_idx) { + char *device_type = nullptr; + + ret = mv_hand_detection_get_device_type(handle, engine_type, device_idx, &device_type); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + } + } + + ret = mv_hand_detection_destroy(handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); +} + TEST(ObjectDetectionTest, InferenceShouldBeOk) { mv_object_detection_h handle; @@ -246,3 +286,65 @@ TEST(FaceDetectionTest, InferenceShouldBeOk) ret = mv_destroy_source(mv_source); ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); } + +TEST(HandDetectionTest, InferenceShouldBeOk) +{ + mv_object_detection_h handle; + vector<test_model_input> test_models { + {} // If empty then default model will be used. + // TODO. + }; + const int coordinate_answers[][4] = { { 0, 125, 93, 181 }, { 118, 112, 211, 167 }, { 299, 141, 419, 211 } }; + + mv_source_h mv_source = NULL; + int ret = mv_create_source(&mv_source); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ret = ImageHelper::loadImageToSource(IMG_HAND, mv_source); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + for (auto &model : test_models) { + ret = mv_hand_detection_create(&handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ret = mv_hand_detection_set_model(handle, model.model_file.c_str(), model.meta_file.c_str(), + model.label_file.c_str(), NULL); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ret = mv_hand_detection_set_engine(handle, "tflite", "cpu"); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ret = mv_hand_detection_configure(handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ret = mv_hand_detection_prepare(handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ret = mv_hand_detection_inference(handle, mv_source); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + unsigned long frame_number; + unsigned int number_of_objects; + + ret = mv_hand_detection_get_result_count(handle, &frame_number, &number_of_objects); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + for (unsigned int idx = 0; idx < number_of_objects; ++idx) { + int left, top, right, bottom; + + int ret = mv_hand_detection_get_bound_box(handle, idx, &left, &top, &right, &bottom); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ASSERT_EQ(coordinate_answers[idx][0], left); + ASSERT_EQ(coordinate_answers[idx][1], top); + ASSERT_EQ(coordinate_answers[idx][2], right); + ASSERT_EQ(coordinate_answers[idx][3], bottom); + } + + ret = mv_hand_detection_destroy(handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + } + + ret = mv_destroy_source(mv_source); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); +} diff --git a/test/testsuites/machine_learning/object_detection/test_object_detection_async.cpp b/test/testsuites/machine_learning/object_detection/test_object_detection_async.cpp index 94c44246..86d0e271 100644 --- a/test/testsuites/machine_learning/object_detection/test_object_detection_async.cpp +++ b/test/testsuites/machine_learning/object_detection/test_object_detection_async.cpp @@ -25,11 +25,14 @@ #include "ImageHelper.h" #include "mv_face_detection.h" #include "mv_face_detection_internal.h" +#include "mv_hand_detection.h" +#include "mv_hand_detection_internal.h" #include "mv_object_detection.h" #include "mv_object_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 IMG_HAND TEST_RES_PATH "/res/inference/images/handDetection.jpg" #define MAX_INFERENCE_ITERATION 50 using namespace testing; @@ -309,4 +312,142 @@ TEST(FaceDetectionAsyncTest, InferenceShouldBeOkWithDestroyFirst) thread_handle->join(); } +} + +void hand_detection_callback(void *user_data) +{ + mv_hand_detection_h handle = static_cast<mv_object_detection_h>(user_data); + const int coordinate_answers[][4] = { { 0, 125, 93, 181 }, { 118, 112, 211, 167 }, { 299, 141, 419, 211 } }; + + bool is_loop_exit = false; + + while (!is_loop_exit) { + unsigned long frame_number; + unsigned int number_of_objects; + + int ret = mv_hand_detection_get_result_count(handle, &frame_number, &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_objects; ++idx) { + int left, top, right, bottom; + + int ret = mv_hand_detection_get_bound_box(handle, idx, &left, &top, &right, &bottom); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ASSERT_EQ(coordinate_answers[idx][0], left); + ASSERT_EQ(coordinate_answers[idx][1], top); + ASSERT_EQ(coordinate_answers[idx][2], right); + ASSERT_EQ(coordinate_answers[idx][3], bottom); + + if (frame_number > MAX_INFERENCE_ITERATION - 10) + is_loop_exit = true; + } + } +} + +TEST(HandDetectionAsyncTest, InferenceShouldBeOk) +{ + mv_hand_detection_h handle; + vector<test_model_input> test_models { + {} // If empty then default model will be used. + // TODO. + }; + + for (auto &model : test_models) { + int ret = mv_hand_detection_create(&handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ret = mv_hand_detection_set_model(handle, model.model_file.c_str(), model.meta_file.c_str(), + model.label_file.c_str(), NULL); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ret = mv_hand_detection_set_engine(handle, "tflite", "cpu"); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ret = mv_hand_detection_configure(handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ret = mv_hand_detection_prepare(handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + unique_ptr<thread> thread_handle; + + 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_HAND, mv_source); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ret = mv_hand_detection_inference_async(handle, mv_source); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + if (iter == 0) + thread_handle = make_unique<thread>(&hand_detection_callback, static_cast<void *>(handle)); + + ret = mv_destroy_source(mv_source); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + } + + thread_handle->join(); + + ret = mv_hand_detection_destroy(handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + } +} + +TEST(HandDetectionAsyncTest, InferenceShouldBeOkWithDestroyFirst) +{ + mv_hand_detection_h handle; + vector<test_model_input> test_models { + {} // If empty then default model will be used. + // TODO. + }; + + for (auto &model : test_models) { + int ret = mv_hand_detection_create(&handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ret = mv_hand_detection_set_model(handle, model.model_file.c_str(), model.meta_file.c_str(), + model.label_file.c_str(), NULL); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ret = mv_hand_detection_set_engine(handle, "tflite", "cpu"); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ret = mv_hand_detection_configure(handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ret = mv_hand_detection_prepare(handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + unique_ptr<thread> thread_handle; + + 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_HAND, mv_source); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + ret = mv_hand_detection_inference_async(handle, mv_source); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + if (iter == 0) + thread_handle = make_unique<thread>(&hand_detection_callback, static_cast<void *>(handle)); + + ret = mv_destroy_source(mv_source); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + } + + ret = mv_hand_detection_destroy(handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + thread_handle->join(); + } }
\ No newline at end of file |