--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <algorithm>
+#include <iostream>
+#include <string.h>
+
+#include "gtest/gtest.h"
+
+#include "../task_model_info.hpp"
+#include "ImageHelper.h"
+#include "mv_gaze_tracking.h"
+#include "mv_gaze_tracking_internal.h"
+
+#define IMG_GAZE TEST_RES_PATH "/res/inference/images/gazeDetection.jpg"
+
+using namespace testing;
+using namespace std;
+
+using namespace MediaVision::Common;
+
+TEST(GazeTrackingTest, GettingAvailableInferenceEnginesInfoShouldBeOk)
+{
+ mv_gaze_tracking_h handle;
+
+ int ret = mv_gaze_tracking_create(&handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ unsigned int engine_count = 0;
+
+ ret = mv_gaze_tracking_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_gaze_tracking_get_engine_type(handle, engine_idx, &engine_type);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ unsigned int device_count = 0;
+
+ ret = mv_gaze_tracking_get_device_count(handle, engine_type, &device_count);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+ ASSERT_GE(engine_count, 1);
+
+ for (unsigned int device_idx = 0; device_idx < device_count; ++device_idx) {
+ char *device_type = nullptr;
+
+ ret = mv_gaze_tracking_get_device_type(handle, engine_type, device_idx, &device_type);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+ }
+ }
+
+ ret = mv_gaze_tracking_destroy(handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+}
+
+TEST(GazeTrackingTest, InferenceShouldBeOk)
+{
+ mv_gaze_tracking_h handle;
+ vector<test_model_input> test_models {
+ {} // If empty then default model will be used.
+ };
+
+ mv_source_h mv_source = NULL;
+ int ret = mv_create_source(&mv_source);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = ImageHelper::loadImageToSource(IMG_GAZE, mv_source);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ unsigned int answer_idx = 0;
+
+ for (const auto &model : test_models) {
+ ret = mv_gaze_tracking_create(&handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_gaze_tracking_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_gaze_tracking_set_engine(handle, "tflite", "cpu");
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_gaze_tracking_configure(handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_gaze_tracking_prepare(handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_gaze_tracking_inference(handle, mv_source);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ unsigned long frame_number;
+ unsigned int number_of_faces;
+
+ ret = mv_gaze_tracking_get_result_count(handle, &frame_number, &number_of_faces);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ for (unsigned int idx = 0; idx < number_of_faces; ++idx) {
+ float x, y, yaw, pitch;
+
+ int ret = mv_gaze_tracking_get_pos(handle, idx, &x, &y);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_gaze_tracking_get_raw_data(handle, idx, &yaw, &pitch);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ cout << "frame number = " << frame_number << " x = " << x << " y = " << y << " yaw = " << yaw
+ << " pitch = " << pitch << endl;
+ }
+
+ answer_idx++;
+
+ ret = mv_gaze_tracking_destroy(handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+ }
+
+ ret = mv_destroy_source(mv_source);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+}
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <algorithm>
+#include <iostream>
+#include <string.h>
+#include <thread>
+
+#include "gtest/gtest.h"
+
+#include "../task_model_info.hpp"
+#include "ImageHelper.h"
+#include "mv_gaze_tracking.h"
+#include "mv_gaze_tracking_internal.h"
+
+#define IMG_GAZE TEST_RES_PATH "/res/inference/images/gazeDetection.jpg"
+#define MAX_INFERENCE_ITERATION 50
+
+using namespace testing;
+using namespace std;
+
+using namespace MediaVision::Common;
+
+void gaze_tracking_callback(void *user_data)
+{
+ mv_gaze_tracking_h handle = static_cast<mv_gaze_tracking_h>(user_data);
+
+ bool is_loop_exit = false;
+
+ while (!is_loop_exit) {
+ unsigned long frame_number;
+ unsigned int number_of_results;
+
+ int ret = mv_gaze_tracking_get_result_count(handle, &frame_number, &number_of_results);
+ if (ret == MEDIA_VISION_ERROR_INVALID_OPERATION)
+ break;
+
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ for (unsigned int idx = 0; idx < number_of_results; ++idx) {
+ float x, y, yaw, pitch;
+
+ int ret = mv_gaze_tracking_get_pos(handle, idx, &x, &y);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_gaze_tracking_get_raw_data(handle, idx, &yaw, &pitch);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ cout << "frame number = " << frame_number << " x = " << x << " y = " << y << " yaw = " << yaw
+ << " pitch = " << pitch << endl;
+
+ if (frame_number > MAX_INFERENCE_ITERATION - 10)
+ is_loop_exit = true;
+ }
+ }
+}
+
+TEST(GazeTrackingAsyncTest, InferenceShouldBeOk)
+{
+ mv_gaze_tracking_h handle;
+ vector<test_model_input> test_models {
+ {} // If empty then default model will be used.
+ };
+
+ for (auto &model : test_models) {
+ int ret = mv_gaze_tracking_create(&handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_gaze_tracking_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_gaze_tracking_set_engine(handle, "tflite", "cpu");
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_gaze_tracking_configure(handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_gaze_tracking_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_GAZE, mv_source);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_gaze_tracking_inference_async(handle, mv_source);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ if (iter == 0)
+ thread_handle = make_unique<thread>(&gaze_tracking_callback, static_cast<void *>(handle));
+
+ ret = mv_destroy_source(mv_source);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+ }
+
+ thread_handle->join();
+
+ ret = mv_gaze_tracking_destroy(handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+ }
+}
+
+TEST(GazeTrackingAsyncTest, InferenceShouldBeOkWithDestroyFirst)
+{
+ mv_gaze_tracking_h handle;
+ vector<test_model_input> test_models {
+ {} // If empty then default model will be used.
+ };
+
+ for (auto &model : test_models) {
+ int ret = mv_gaze_tracking_create(&handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_gaze_tracking_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_gaze_tracking_set_engine(handle, "tflite", "cpu");
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_gaze_tracking_configure(handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_gaze_tracking_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_GAZE, mv_source);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ ret = mv_gaze_tracking_inference_async(handle, mv_source);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ if (iter == 0)
+ thread_handle = make_unique<thread>(&gaze_tracking_callback, static_cast<void *>(handle));
+
+ ret = mv_destroy_source(mv_source);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+ }
+
+ ret = mv_gaze_tracking_destroy(handle);
+ ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+ thread_handle->join();
+ }
+}