--- /dev/null
+/**
+ * Copyright (c) 2022 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 "assert.h"
+#include <mv_face_recognition.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <image_util.h>
+#include <system_info.h>
+#include <storage.h>
+#include "tct_common.h"
+
+#define MAX_LABEL_CNT 2
+#define MAX_IMAGE_CNT 10
+#define FILE_PATH_SIZE 1024
+#define API_NAMESPACE "[MediaVision]"
+
+static const char *p1_face_examples_dir = NULL;
+static const char *p2_face_examples_dir = NULL;
+
+static const char *image_file_names[MAX_IMAGE_CNT] = {
+ "00.jpg", "01.jpg", "02.jpg", "03.jpg", "04.jpg",
+ "05.jpg", "06.jpg", "07.jpg", "08.jpg", "09.jpg"
+};
+
+static const char *label_names[MAX_LABEL_CNT] = {
+ "p1", "p2"
+};
+
+static int load_image_to_media_source(const char *file_path, mv_source_h source)
+{
+ if (NULL == file_path || NULL == source)
+ {
+ printf("File path or source is NULL\n");
+ return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ }
+
+ unsigned long width = 0;
+ unsigned long height = 0;
+ unsigned long long buffer_size = 0;
+ unsigned char *data_buffer = NULL;
+ int ret1 = IMAGE_UTIL_ERROR_NONE;
+ int ret2 = MEDIA_VISION_ERROR_NONE;
+ image_util_decode_h _decoder = NULL;
+
+ ret1 = image_util_decode_create(&_decoder);
+ if (ret1 != IMAGE_UTIL_ERROR_NONE) goto _LOAD_IMAGE_FAIL;
+ ret1 = image_util_decode_set_input_path(_decoder, file_path);
+ if (ret1 != IMAGE_UTIL_ERROR_NONE) goto _LOAD_IMAGE_FAIL;
+ ret1 = image_util_decode_set_colorspace(_decoder, IMAGE_UTIL_COLORSPACE_RGB888);
+ if (ret1 != IMAGE_UTIL_ERROR_NONE) goto _LOAD_IMAGE_FAIL;
+ ret1 = image_util_decode_set_output_buffer(_decoder, &data_buffer);
+ if (ret1 != IMAGE_UTIL_ERROR_NONE) goto _LOAD_IMAGE_FAIL;
+ ret1 = image_util_decode_run(_decoder, &width, &height, &buffer_size);
+ if (ret1 != IMAGE_UTIL_ERROR_NONE) goto _LOAD_IMAGE_FAIL;
+
+ // Only grayscale and RGB jpegs in test set:
+ mv_colorspace_e source_colorspace = MEDIA_VISION_COLORSPACE_RGB888;
+
+ ret2 = mv_source_clear(source);
+ if (ret2 != MEDIA_VISION_ERROR_NONE) goto _LOAD_IMAGE_FAIL;
+
+ ret2 = mv_source_fill_by_buffer(source, data_buffer, (unsigned long long)buffer_size,
+ (unsigned int)width, (unsigned int)height, source_colorspace);
+
+_LOAD_IMAGE_FAIL:
+ image_util_decode_destroy(_decoder);
+ if(data_buffer)
+ free(data_buffer);
+
+ assert_eq(IMAGE_UTIL_ERROR_NONE, ret1);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret2);
+ return MEDIA_VISION_ERROR_NONE;
+}
+
+static bool is_face_recognition_feature_supported(void)
+{
+ bool isFaceRecognitionSupported =false;
+
+ system_info_get_platform_bool("http://tizen.org/feature/vision.inference.face", &isFaceRecognitionSupported);
+
+ if (!is_face_recognition_feature_supported)
+ printf("Not support face recognition feature.");
+
+ return isFaceRecognitionSupported;
+}
+
+/**
+ * @function utc_capi_media_vision_face_recognition_startup
+ * @description Face recognition module UTC startup code
+ * @parameter NA
+ * @return NA
+ */
+void utc_capi_media_vision_face_recognition_startup(void)
+{
+ printf("capi-media-vision mv_face_recognition tests STARTUP is launched\n");
+
+ char pszValue[CONFIG_VALUE_LEN_MAX] = {0,};
+
+ if (!GetValueForTCTSetting("DEVICE_PHYSICAL_STORAGE_30", pszValue, API_NAMESPACE)) {
+ printf("Fail to get value for TCT setting.\n");
+ return MEDIA_VISION_ERROR_INVALID_OPERATION;
+ }
+
+ PRINT_UTC_LOG("[Line : %d][%s] 'DEVICE_PHYSICAL_STORAGE_30' Values Received %s\\n", __LINE__, API_NAMESPACE, pszValue);
+
+ p1_face_examples_dir=(char*)calloc(strlen(pszValue)+strlen("/res/face_recognition/images/P1")+1, sizeof(char));
+ snprintf(p1_face_examples_dir, strlen(pszValue)+strlen("/res/face_recognition/images/P1")+1, "%s/res/face_recognition/images/P1", pszValue);
+
+ p2_face_examples_dir=(char*)calloc(strlen(pszValue)+strlen("/res/face_recognition/images/P2")+1, sizeof(char));
+ snprintf(p2_face_examples_dir, strlen(pszValue)+strlen("/res/face_recognition/images/P2")+1, "%s/res/face_recognition/images/P2", pszValue);
+
+ printf("capi-media-vision mv_face_recognition tests STARTUP is completed\n");
+}
+
+/**
+ * @function utc_capi_media_vision_face_recognition_cleanup
+ * @description Face recognition module UTC cleanup code
+ * @parameter NA
+ * @return NA
+ */
+void utc_capi_media_vision_face_recognition_cleanup(void)
+{
+ printf("capi-media-vision mv_face_recognition tests CLEANUP is launched\n");
+
+ free(p1_face_examples_dir);
+ free(p2_face_examples_dir);
+
+ printf("capi-media-vision mv_face_recognition tests CLEANUP is completed\n");
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_create_p()
+ * @testcase utc_mediavision_mv_face_recognition_create_p
+ * @since_tizen 7.0
+ * @description Create face recognition handle
+ */
+int utc_mediavision_mv_face_recognition_create_p(void)
+{
+ printf("Start mv_face_recognition_create_p\n");
+
+ mv_face_recognition_h handle = NULL;
+
+ int ret = mv_face_recognition_create(&handle);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_destroy(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ printf("End mv_face_recognition_create_p\n");
+
+ return 0;
+}
+
+/**
+ * @brief Negative test case of mv_face_recognition_create()
+ * @testcase utc_mediavision_mv_face_recognition_create_n
+ * @since_tizen 7.0
+ * @description Create face recognition handle,
+ * but fail because input parameter is NULL
+ */
+int utc_mediavision_mv_face_recognition_create_n(void)
+{
+ printf("Start mv_face_recognition_create_n\n");
+
+ int ret = mv_face_recognition_create(NULL);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_INVALID_PARAMETER, ret);
+
+ printf("End mv_face_recognition_create_n\n");
+
+ return 0;
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_destroy_p()
+ * @testcase utc_mediavision_mv_face_recognition_destroy_p
+ * @since_tizen 7.0
+ * @description Destroy face recognition handle
+ */
+int utc_mediavision_mv_face_recognition_destroy_p(void)
+{
+ printf("Start mv_face_recognition_destroy_p\n");
+
+ mv_face_recognition_h handle = NULL;
+ int ret = mv_face_recognition_create(&handle);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_destroy(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ printf("End mv_face_recognition_destroy_p\n");
+
+ return 0;
+}
+
+/**
+ * @brief Negative test case of mv_face_recognition_destroy_n()
+ * @testcase utc_mediavision_mv_face_recognition_destroy_n
+ * @since_tizen 7.0
+ * @description Destroy face recognition handle,
+ * but fail because input parameter is NULL
+ */
+int utc_mediavision_mv_face_recognition_destroy_n(void)
+{
+ printf("Start mv_face_recognition_destroy_n\n");
+
+ int ret = mv_face_recognition_destroy(NULL);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_INVALID_PARAMETER, ret);
+
+ printf("End mv_face_recognition_destroy_n\n");
+
+ return 0;
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_prepare_p()
+ * @testcase utc_mediavision_mv_face_recognition_prepare_p
+ * @since_tizen 7.0
+ * @description Prepare face recognition
+ */
+int utc_mediavision_mv_face_recognition_prepare_p(void)
+{
+ printf("Start mv_face_recognition_prepare_p\n");
+
+ mv_face_recognition_h handle = NULL;
+ int ret = mv_face_recognition_create(&handle);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_prepare(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_destroy(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ printf("End mv_face_recognition_prepare_p\n");
+
+ return 0;
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_prepare_n()
+ * @testcase utc_mediavision_mv_face_recognition_prepare_n
+ * @since_tizen 7.0
+ * @description Prepare face recognition
+ */
+int utc_mediavision_mv_face_recognition_prepare_n(void)
+{
+ printf("Start mv_face_recognition_prepare_n\n");
+
+ int ret = mv_face_recognition_prepare(NULL);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_INVALID_PARAMETER, ret);
+
+ printf("End mv_face_recognition_prepare_n\n");
+
+ return 0;
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_register_p()
+ * @testcase utc_mediavision_mv_face_recognition_register_p
+ * @since_tizen 7.0
+ * @description Register face image and its label
+ */
+int utc_mediavision_mv_face_recognition_register_p(void)
+{
+ printf("Start mv_face_recognition_register_p\n");
+
+ mv_face_recognition_h handle = NULL;
+ mv_source_h mv_source = NULL;
+
+ int ret = mv_face_recognition_create(&handle);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_prepare(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ for (unsigned int label_idx = 0; label_idx < MAX_LABEL_CNT; ++label_idx) {
+ for (unsigned int img_idx = 0; img_idx < MAX_IMAGE_CNT / 2; ++img_idx) {
+ char image_path[FILE_PATH_SIZE] = "";
+
+ ret = mv_create_source(&mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ if (label_idx == 0)
+ snprintf(image_path, FILE_PATH_SIZE, "%s/%s", p1_face_examples_dir, image_file_names[img_idx]);
+ else
+ snprintf(image_path, FILE_PATH_SIZE, "%s/%s", p2_face_examples_dir, image_file_names[img_idx]);
+
+ ret = load_image_to_media_source(image_path, mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_register(handle, mv_source, label_names[label_idx]);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_destroy_source(mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+ }
+ }
+
+ ret = mv_face_recognition_destroy(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ printf("End mv_face_recognition_register_p\n");
+
+ return 0;
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_register_n1()
+ * @testcase utc_mediavision_mv_face_recognition_register_n1
+ * @since_tizen 7.0
+ * @description Register face image and its label
+ */
+int utc_mediavision_mv_face_recognition_register_n1(void)
+{
+ printf("Start mv_face_recognition_register_n1\n");
+
+ mv_face_recognition_h handle = NULL;
+ mv_source_h mv_source = NULL;
+ char image_path[FILE_PATH_SIZE] = "";
+
+ int ret = mv_face_recognition_create(&handle);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_prepare(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_create_source(&mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ snprintf(image_path, FILE_PATH_SIZE, "%s/%s", p1_face_examples_dir, "00.jpg");
+
+ ret = load_image_to_media_source(image_path, mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_register(NULL, mv_source, "test");
+ assert_eq(MEDIA_VISION_ERROR_INVALID_PARAMETER, ret);
+
+ ret = mv_destroy_source(mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_destroy(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ printf("End mv_face_recognition_register_n1\n");
+
+ return 0;
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_register_n2()
+ * @testcase utc_mediavision_mv_face_recognition_register_n2
+ * @since_tizen 7.0
+ * @description Register face image and its label
+ */
+int utc_mediavision_mv_face_recognition_register_n2(void)
+{
+ printf("Start mv_face_recognition_register_n2\n");
+
+ mv_face_recognition_h handle = NULL;
+
+ int ret = mv_face_recognition_create(&handle);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_prepare(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_register(handle, NULL, "test");
+ assert_eq(MEDIA_VISION_ERROR_INVALID_PARAMETER, ret);
+
+ ret = mv_face_recognition_destroy(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ printf("End mv_face_recognition_register_n2\n");
+
+ return 0;
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_register_n3()
+ * @testcase utc_mediavision_mv_face_recognition_register_n3
+ * @since_tizen 7.0
+ * @description Register face image and its label
+ */
+int utc_mediavision_mv_face_recognition_register_n3(void)
+{
+ printf("Start mv_face_recognition_register_n3\n");
+
+ mv_face_recognition_h handle = NULL;
+ mv_source_h mv_source = NULL;
+ char image_path[FILE_PATH_SIZE] = "";
+
+ int ret = mv_face_recognition_create(&handle);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_prepare(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_create_source(&mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ snprintf(image_path, FILE_PATH_SIZE, "%s/%s", p1_face_examples_dir, "00.jpg");
+
+ ret = mv_face_recognition_register(handle, image_path, NULL);
+ assert_eq(MEDIA_VISION_ERROR_INVALID_PARAMETER, ret);
+
+ ret = mv_destroy_source(mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_destroy(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ printf("End mv_face_recognition_register_n3\n");
+
+ return 0;
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_infernce_p()
+ * @testcase utc_mediavision_mv_face_recognition_inference_p
+ * @since_tizen 7.0
+ * @description Register face image and its label
+ */
+int utc_mediavision_mv_face_recognition_inference_p(void)
+{
+ printf("Start mv_face_recognition_inference_p\n");
+
+ mv_face_recognition_h handle = NULL;
+ mv_source_h mv_source = NULL;
+
+ int ret = mv_face_recognition_create(&handle);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_prepare(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ // Training
+ for (unsigned int label_idx = 0; label_idx < MAX_LABEL_CNT; ++label_idx) {
+ for (unsigned int img_idx = 0; img_idx < MAX_IMAGE_CNT / 2; ++img_idx) {
+ char image_path[FILE_PATH_SIZE] = "";
+
+ ret = mv_create_source(&mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ if (label_idx == 0)
+ snprintf(image_path, FILE_PATH_SIZE, "%s/%s", p1_face_examples_dir, image_file_names[img_idx]);
+ else
+ snprintf(image_path, FILE_PATH_SIZE, "%s/%s", p2_face_examples_dir, image_file_names[img_idx]);
+
+ ret = load_image_to_media_source(image_path, mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_register(handle, mv_source, label_names[label_idx]);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_destroy_source(mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+ }
+ }
+
+ // Inference
+ for (unsigned int label_idx = 0; label_idx < MAX_LABEL_CNT; ++label_idx) {
+ for (unsigned int img_idx = 5; img_idx < MAX_IMAGE_CNT; ++img_idx) {
+ char image_path[FILE_PATH_SIZE] = "";
+
+ ret = mv_create_source(&mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ if (label_idx == 0)
+ snprintf(image_path, FILE_PATH_SIZE, "%s/%s", p1_face_examples_dir, image_file_names[img_idx]);
+ else
+ snprintf(image_path, FILE_PATH_SIZE, "%s/%s", p2_face_examples_dir, image_file_names[img_idx]);
+
+ ret = load_image_to_media_source(image_path, mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_inference(handle, mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_destroy_source(mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+ }
+ }
+
+ ret = mv_face_recognition_destroy(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ printf("End mv_face_recognition_inference_p\n");
+
+ return 0;
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_inference_n1()
+ * @testcase utc_mediavision_mv_face_recognition_inference_n1
+ * @since_tizen 7.0
+ * @description Recognize a given face image
+ */
+int utc_mediavision_mv_face_recognition_inference_n1(void)
+{
+ printf("Start mv_face_recognition_inference_n1\n");
+
+ mv_face_recognition_h handle = NULL;
+ mv_source_h mv_source = NULL;
+ char image_path[FILE_PATH_SIZE] = "";
+
+ int ret = mv_face_recognition_create(&handle);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_prepare(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_create_source(&mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ snprintf(image_path, FILE_PATH_SIZE, "%s/%s", p1_face_examples_dir, "00.jpg");
+
+ ret = load_image_to_media_source(image_path, mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_inference(NULL, mv_source);
+ assert_eq(MEDIA_VISION_ERROR_INVALID_PARAMETER, ret);
+
+ ret = mv_face_recognition_destroy(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ printf("End mv_face_recognition_inference_n1\n");
+
+ return 0;
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_inference_n2()
+ * @testcase utc_mediavision_mv_face_recognition_inference_n2
+ * @since_tizen 7.0
+ * @description Recognize a given face image
+ */
+int utc_mediavision_mv_face_recognition_inference_n2(void)
+{
+ printf("Start mv_face_recognition_inference_n2\n");
+
+ mv_face_recognition_h handle = NULL;
+ mv_source_h mv_source = NULL;
+ char image_path[FILE_PATH_SIZE] = "";
+
+ int ret = mv_face_recognition_create(&handle);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_prepare(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_create_source(&mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ snprintf(image_path, FILE_PATH_SIZE, "%s/%s", p1_face_examples_dir, "00.jpg");
+
+ ret = load_image_to_media_source(image_path, mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_inference(handle, NULL);
+ assert_eq(MEDIA_VISION_ERROR_INVALID_PARAMETER, ret);
+
+ ret = mv_face_recognition_destroy(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ printf("End mv_face_recognition_inference_n2\n");
+
+ return 0;
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_get_label_p()
+ * @testcase utc_mediavision_mv_face_recognition_get_label_p
+ * @since_tizen 7.0
+ * @description Get a label
+ */
+int utc_mediavision_mv_face_recognition_get_label_p(void)
+{
+ printf("Start mv_face_recognition_get_label_p\n");
+
+ mv_face_recognition_h handle = NULL;
+ mv_source_h mv_source = NULL;
+
+ int ret = mv_face_recognition_create(&handle);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_prepare(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ // Training
+ for (unsigned int label_idx = 0; label_idx < MAX_LABEL_CNT; ++label_idx) {
+ for (unsigned int img_idx = 0; img_idx < MAX_IMAGE_CNT / 2; ++img_idx) {
+ char image_path[FILE_PATH_SIZE] = "";
+
+ ret = mv_create_source(&mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ if (label_idx == 0)
+ snprintf(image_path, FILE_PATH_SIZE, "%s/%s", p1_face_examples_dir, image_file_names[img_idx]);
+ else
+ snprintf(image_path, FILE_PATH_SIZE, "%s/%s", p2_face_examples_dir, image_file_names[img_idx]);
+
+ ret = load_image_to_media_source(image_path, mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_register(handle, mv_source, label_names[label_idx]);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_destroy_source(mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+ }
+ }
+
+ // Inference
+ for (unsigned int label_idx = 0; label_idx < MAX_LABEL_CNT; ++label_idx) {
+ for (unsigned int img_idx = 5; img_idx < MAX_IMAGE_CNT; ++img_idx) {
+ char image_path[FILE_PATH_SIZE] = "";
+ const char *out_label = NULL;
+
+ ret = mv_create_source(&mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ if (label_idx == 0)
+ snprintf(image_path, FILE_PATH_SIZE, "%s/%s", p1_face_examples_dir, image_file_names[img_idx]);
+ else
+ snprintf(image_path, FILE_PATH_SIZE, "%s/%s", p2_face_examples_dir, image_file_names[img_idx]);
+
+ ret = load_image_to_media_source(image_path, mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_inference(handle, mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_get_label(handle, &out_label);
+ if (ret != MEDIA_VISION_ERROR_NO_DATA)
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_destroy_source(mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+ }
+ }
+
+ ret = mv_face_recognition_destroy(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ printf("End mv_face_recognition_get_label_p\n");
+
+ return 0;
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_get_label_n1()
+ * @testcase utc_mediavision_mv_face_recognition_get_label_n1
+ * @since_tizen 7.0
+ * @description Get a label
+ */
+int utc_mediavision_mv_face_recognition_get_label_n1(void)
+{
+ printf("Start mv_face_recognition_get_label_n1\n");
+
+ mv_face_recognition_h handle = NULL;
+ const char *out_label = NULL;
+
+ int ret = mv_face_recognition_create(&handle);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_prepare(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_get_label(NULL, &out_label);
+ assert_eq(MEDIA_VISION_ERROR_INVALID_PARAMETER, ret);
+
+ ret = mv_face_recognition_destroy(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ printf("End mv_face_recognition_get_label_n1\n");
+
+ return 0;
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_get_label_n2()
+ * @testcase utc_mediavision_mv_face_recognition_get_label_n2
+ * @since_tizen 7.0
+ * @description Get a label
+ */
+int utc_mediavision_mv_face_recognition_get_label_n2(void)
+{
+ printf("Start mv_face_recognition_get_label_n2\n");
+
+ mv_face_recognition_h handle = NULL;
+
+ int ret = mv_face_recognition_create(&handle);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_prepare(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_get_label(handle, NULL);
+ assert_eq(MEDIA_VISION_ERROR_INVALID_PARAMETER, ret);
+
+ ret = mv_face_recognition_destroy(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ printf("End mv_face_recognition_get_label_n2\n");
+
+ return 0;
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_unregister_p()
+ * @testcase utc_mediavision_mv_face_recognition_unregister_p
+ * @since_tizen 7.0
+ * @description UNregister a given label
+ */
+int utc_mediavision_mv_face_recognition_unregister_p(void)
+{
+ printf("Start mv_face_recognition_unregister_p\n");
+
+ mv_face_recognition_h handle = NULL;
+ mv_source_h mv_source = NULL;
+
+ int ret = mv_face_recognition_create(&handle);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_prepare(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ // Training
+ for (unsigned int label_idx = 0; label_idx < MAX_LABEL_CNT; ++label_idx) {
+ for (unsigned int img_idx = 0; img_idx < MAX_IMAGE_CNT / 2; ++img_idx) {
+ char image_path[FILE_PATH_SIZE] = "";
+
+ ret = mv_create_source(&mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ if (label_idx == 0)
+ snprintf(image_path, FILE_PATH_SIZE, "%s/%s", p1_face_examples_dir, image_file_names[img_idx]);
+ else
+ snprintf(image_path, FILE_PATH_SIZE, "%s/%s", p2_face_examples_dir, image_file_names[img_idx]);
+
+ ret = load_image_to_media_source(image_path, mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_register(handle, mv_source, label_names[label_idx]);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_destroy_source(mv_source);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+ }
+ }
+
+ for (unsigned int label_idx = 0; label_idx < MAX_LABEL_CNT; ++label_idx) {
+ ret = mv_face_recognition_unregister(handle, label_names[label_idx]);
+ assert_eq(ret, MEDIA_VISION_ERROR_NONE);
+ }
+
+ ret = mv_face_recognition_destroy(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ printf("End mv_face_recognition_unregister_p\n");
+
+ return 0;
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_unregister_n1()
+ * @testcase utc_mediavision_mv_face_recognition_unregister_n1
+ * @since_tizen 7.0
+ * @description Unregister a given label
+ */
+int utc_mediavision_mv_face_recognition_unregister_n1(void)
+{
+ printf("Start mv_face_recognition_unregister_n1\n");
+
+ mv_face_recognition_h handle = NULL;
+
+ int ret = mv_face_recognition_create(&handle);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_prepare(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_unregister(NULL, "p1");
+ assert_eq(MEDIA_VISION_ERROR_INVALID_PARAMETER, ret);
+
+ ret = mv_face_recognition_destroy(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ printf("End mv_face_recognition_unregister_n1\n");
+
+ return 0;
+}
+
+/**
+ * @brief Positive test case of mv_face_recognition_unregister_n2()
+ * @testcase utc_mediavision_mv_face_recognition_unregister_n2
+ * @since_tizen 7.0
+ * @description Unregister a given label
+ */
+int utc_mediavision_mv_face_recognition_unregister_n2(void)
+{
+ printf("Start mv_face_recognition_unregister_n2\n");
+
+ mv_face_recognition_h handle = NULL;
+
+ int ret = mv_face_recognition_create(&handle);
+ if (!is_face_recognition_feature_supported()) {
+ assert_eq(ret, MEDIA_VISION_ERROR_NOT_SUPPORTED);
+ return 0;
+ }
+
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_prepare(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ ret = mv_face_recognition_unregister(handle, NULL);
+ assert_eq(MEDIA_VISION_ERROR_INVALID_PARAMETER, ret);
+
+ ret = mv_face_recognition_destroy(handle);
+ assert_eq(MEDIA_VISION_ERROR_NONE, ret);
+
+ printf("End mv_face_recognition_unregister_n2\n");
+
+ return 0;
+}
\ No newline at end of file