/** * Copyright (c) 2019 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 "mv_private.h" #include "mv_inference.h" #ifdef MEDIA_VISION_INFERENCE_LICENSE_PORT /* Include headers of licensed inference module here. */ //#include "mv_inference_lic.h" #else /* Include headers of open inference module here. */ #include "mv_inference_open.h" #endif /* MEDIA_VISION_INFERENCE_LICENSE_PORT */ /** * @file mv_inference.c * @brief This file contains Media Vision inference module. */ int mv_inference_create(mv_inference_h *infer) { MEDIA_VISION_SUPPORT_CHECK( __mv_inference_check_system_info_feature_supported()); MEDIA_VISION_NULL_ARG_CHECK(infer); MEDIA_VISION_FUNCTION_ENTER(); int ret = MEDIA_VISION_ERROR_NONE; #ifdef MEDIA_VISION_INFERENCE_LICENSE_PORT //ret = mv_inference_create_lic(infer); #else ret = mv_inference_create_open(infer); #endif /* MEDIA_VISION_INFERENCE_LICENSE_PORT */ MEDIA_VISION_FUNCTION_LEAVE(); return ret; } int mv_inference_destroy(mv_inference_h infer) { MEDIA_VISION_SUPPORT_CHECK( __mv_inference_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(infer); MEDIA_VISION_FUNCTION_ENTER(); int ret = MEDIA_VISION_ERROR_NONE; #ifdef MEDIA_VISION_INFERENCE_LICENSE_PORT //ret = mv_inference_destroy_lic(infer); #else ret = mv_inference_destroy_open(infer); #endif /* MEDIA_VISION_INFERENCE_LICENSE_PORT */ MEDIA_VISION_FUNCTION_LEAVE(); return ret; } int mv_inference_configure(mv_inference_h infer, mv_engine_config_h engine_config) { MEDIA_VISION_SUPPORT_CHECK( __mv_inference_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(infer); MEDIA_VISION_INSTANCE_CHECK(engine_config); MEDIA_VISION_FUNCTION_ENTER(); int ret = MEDIA_VISION_ERROR_NONE; #ifdef MEDIA_VISION_INFERENCE_LICENSE_PORT //ret = mv_inference_configure_lic(infer); #else ret = mv_inference_configure_engine_open(infer, engine_config); if (ret != MEDIA_VISION_ERROR_NONE) { LOGE("Fail to configure engine and target"); return ret; } #endif /* MEDIA_VISION_INFERENCE_LICENSE_PORT */ MEDIA_VISION_FUNCTION_LEAVE(); return ret; } int mv_inference_prepare(mv_inference_h infer) { MEDIA_VISION_SUPPORT_CHECK( __mv_inference_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(infer); MEDIA_VISION_FUNCTION_ENTER(); int ret = MEDIA_VISION_ERROR_NONE; mv_engine_config_h engine_config = mv_inference_get_engine_config(infer); #ifdef MEDIA_VISION_INFERENCE_LICENSE_PORT //ret = mv_inference_prepare_lic(infer); #else ret = mv_inference_configure_model_open(infer, engine_config); if (ret != MEDIA_VISION_ERROR_NONE) { LOGE("Fail to configure model"); return ret; } // input tensor, input layer ret = mv_inference_configure_input_info_open(infer, engine_config); if (ret != MEDIA_VISION_ERROR_NONE) { LOGE("Fail to configure input info"); return ret; } // output layer ret = mv_inference_configure_output_info_open(infer, engine_config); if (ret != MEDIA_VISION_ERROR_NONE) { LOGE("Fail to configure output info"); return ret; } // maximum candidates, threshold ret = mv_inference_configure_post_process_info_open(infer, engine_config); if (ret != MEDIA_VISION_ERROR_NONE) { LOGE("Fail to configure post process info"); return ret; } ret = mv_inference_prepare_open(infer); #endif /* MEDIA_VISION_INFERENCE_LICENSE_PORT */ MEDIA_VISION_FUNCTION_LEAVE(); return ret; } int mv_inference_foreach_supported_engine( mv_inference_h infer, mv_inference_supported_engine_cb callback, void *user_data) { MEDIA_VISION_SUPPORT_CHECK( __mv_inference_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(infer); MEDIA_VISION_NULL_ARG_CHECK(callback); MEDIA_VISION_FUNCTION_ENTER(); int ret = MEDIA_VISION_ERROR_NONE; #ifdef MEDIA_VISION_INFERENCE_LICENCE_PORT // ret = mv_inference_foreach_supported_engine_lic(infer, callback, user_data); #else ret = mv_inference_foreach_supported_engine_open(infer, callback, user_data); #endif MEDIA_VISION_FUNCTION_LEAVE(); return ret; } int mv_inference_image_classify(mv_source_h source, mv_inference_h infer, mv_rectangle_s *roi, mv_inference_image_classified_cb classified_cb, void *user_data) { MEDIA_VISION_SUPPORT_CHECK( __mv_inference_image_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(source); MEDIA_VISION_INSTANCE_CHECK(infer); MEDIA_VISION_NULL_ARG_CHECK(classified_cb); MEDIA_VISION_FUNCTION_ENTER(); int ret = MEDIA_VISION_ERROR_NONE; #ifdef MEDIA_VISION_INFERENCE_LICENSE_PORT /* ret = mv_inference_image_classify_lic(source, infer, classified_cb, user_data); */ #else ret = mv_inference_image_classify_open(source, infer, roi, classified_cb, user_data); #endif /* MEDIA_VISION_INFERENCE_LICENSE_PORT */ MEDIA_VISION_FUNCTION_LEAVE(); return ret; } int mv_inference_object_detect(mv_source_h source, mv_inference_h infer, mv_inference_object_detected_cb detected_cb, void *user_data) { MEDIA_VISION_SUPPORT_CHECK( __mv_inference_image_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(source); MEDIA_VISION_INSTANCE_CHECK(infer); MEDIA_VISION_NULL_ARG_CHECK(detected_cb); MEDIA_VISION_FUNCTION_ENTER(); int ret = MEDIA_VISION_ERROR_NONE; #ifdef MEDIA_VISION_INFERENCE_LICENSE_PORT /* ret = mv_inference_object_detect_lic(source, infer, classified_cb, user_data); */ #else ret = mv_inference_object_detect_open(source, infer, detected_cb, user_data); #endif /* MEDIA_VISION_INFERENCE_LICENSE_PORT */ MEDIA_VISION_FUNCTION_LEAVE(); return ret; } int mv_inference_face_detect(mv_source_h source, mv_inference_h infer, mv_inference_face_detected_cb detected_cb, void *user_data) { MEDIA_VISION_SUPPORT_CHECK( __mv_inference_face_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(source); MEDIA_VISION_INSTANCE_CHECK(infer); MEDIA_VISION_NULL_ARG_CHECK(detected_cb); MEDIA_VISION_FUNCTION_ENTER(); int ret = MEDIA_VISION_ERROR_NONE; #ifdef MEDIA_VISION_INFERENCE_LICENCE_PORT /* ret = mv_inference_face_detect_lic(source, infer, detected_cb, user_data); */ #else ret = mv_inference_face_detect_open(source, infer, detected_cb, user_data); MEDIA_VISION_FUNCTION_LEAVE(); return ret; #endif } int mv_inference_facial_landmark_detect( mv_source_h source, mv_inference_h infer, mv_rectangle_s *roi, mv_inference_facial_landmark_detected_cb detected_cb, void *user_data) { MEDIA_VISION_SUPPORT_CHECK( __mv_inference_face_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(source); MEDIA_VISION_INSTANCE_CHECK(infer); MEDIA_VISION_NULL_ARG_CHECK(detected_cb); MEDIA_VISION_FUNCTION_ENTER(); int ret = MEDIA_VISION_ERROR_NONE; #ifdef MEDIA_VISION_INFERENCE_LICENCE_PORT /* ret = mv_inference_facial_landmark_detect_lic(source, infer, detected_cb, user_data); */ #else ret = mv_inference_facial_landmark_detect_open(source, infer, roi, detected_cb, user_data); MEDIA_VISION_FUNCTION_LEAVE(); return ret; #endif }