From: Inki Dae Date: Thu, 27 Feb 2025 06:11:12 +0000 (+0900) Subject: mv_machine_learning: add get label API support for semantic segmentation task X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3b9daf199b18f845e68cfe3ffab87ec5259cdffb;p=platform%2Fcore%2Fapi%2Fmediavision.git mv_machine_learning: add get label API support for semantic segmentation task Add get label API support for semantic segmentation task. Change-Id: Ic381b0157706d6b939e72517db134977570ca4a3 Signed-off-by: Inki Dae --- diff --git a/include/mv_semantic_segmentation_internal.h b/include/mv_semantic_segmentation_internal.h index a190f281..43cb20d2 100644 --- a/include/mv_semantic_segmentation_internal.h +++ b/include/mv_semantic_segmentation_internal.h @@ -240,6 +240,51 @@ int mv_semantic_segmentation_get_result_count(mv_semantic_segmentation_h handle, int mv_semantic_segmentation_get_result(mv_semantic_segmentation_h handle, unsigned int *width, unsigned int *height, unsigned int *pixel_size, const unsigned char **data); +/** + * @internal + * @brief Gets a number of labels. + * + * @since_tizen 10.0 + * + * @param[in] handle The handle to the inference + * @param[out] cnt A number of labels. + * + * @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 + * + * @pre Create a source handle by calling mv_create_source() + * @pre Create an inference handle by calling mv_semantic_segmentation_create() + * @pre Prepare an inference by calling mv_semantic_segmentation_configure() + * @pre Prepare an inference by calling mv_semantic_segmentation_prepare() + * @pre Prepare an inference by calling mv_semantic_segmentation_inference() + */ +int mv_semantic_segmentation_get_label_count(mv_semantic_segmentation_h handle, unsigned int *cnt); + +/** + * @internal + * @brief Gets a label to segmented object region. + * + * @since_tizen 10.0 + * + * @param[in] handle The handle to the inference + * @param[in] index A result index. + * @param[out] label A label name to a detected 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 + * + * @pre Create a source handle by calling mv_create_source() + * @pre Create an inference handle by calling mv_semantic_segmentation_create() + * @pre Prepare an inference by calling mv_semantic_segmentation_configure() + * @pre Prepare an inference by calling mv_semantic_segmentation_prepare() + * @pre Prepare an inference by calling mv_semantic_segmentation_inference() + */ +int mv_semantic_segmentation_get_label(mv_semantic_segmentation_h handle, unsigned int index, const char **label); + /** * @internal * @brief Set user-given inference engine and device types for inference. diff --git a/mv_machine_learning/image_segmentation/include/image_segmentation_type.h b/mv_machine_learning/image_segmentation/include/image_segmentation_type.h index 904a56ee..232cdec8 100644 --- a/mv_machine_learning/image_segmentation/include/image_segmentation_type.h +++ b/mv_machine_learning/image_segmentation/include/image_segmentation_type.h @@ -41,6 +41,7 @@ struct ImageSegmentationResult : public OutputBaseType { unsigned int height {}; unsigned int pixel_size {}; std::vector data; + unsigned int num_labels {}; std::vector labels; }; diff --git a/mv_machine_learning/image_segmentation/src/Stdc1.cpp b/mv_machine_learning/image_segmentation/src/Stdc1.cpp index c3221300..278ea0da 100644 --- a/mv_machine_learning/image_segmentation/src/Stdc1.cpp +++ b/mv_machine_learning/image_segmentation/src/Stdc1.cpp @@ -72,6 +72,7 @@ template ImageSegmentationResult &Stdc1::result() _result.width = static_cast(input_tensor_width * width_ratio); _result.pixel_size = 1; _result.labels = _labels; + _result.num_labels = _labels.size(); cv::Mat cvSource = cv::Mat(cv::Size(width, height), CV_MAKETYPE(CV_8U, 1), outputTensor.data()); cv::Mat cvDest(_result.height, _result.width, CV_8UC1); diff --git a/mv_machine_learning/image_segmentation/src/mv_semantic_segmentation.cpp b/mv_machine_learning/image_segmentation/src/mv_semantic_segmentation.cpp index 1269e685..bd708c1b 100644 --- a/mv_machine_learning/image_segmentation/src/mv_semantic_segmentation.cpp +++ b/mv_machine_learning/image_segmentation/src/mv_semantic_segmentation.cpp @@ -351,5 +351,57 @@ int mv_semantic_segmentation_get_result(mv_semantic_segmentation_h handle, unsig MEDIA_VISION_FUNCTION_LEAVE(); + return MEDIA_VISION_ERROR_NONE; +} + +int mv_semantic_segmentation_get_label_count(mv_semantic_segmentation_h handle, unsigned int *cnt) +{ + MEDIA_VISION_SUPPORT_CHECK(mv_check_feature_key(feature_keys, num_keys, true)); + MEDIA_VISION_INSTANCE_CHECK(cnt); + + MEDIA_VISION_FUNCTION_ENTER(); + + try { + auto &result = + static_cast(machine_learning_native_get_result_cache(handle, TASK_NAME)); + + *cnt = result.num_labels; + } catch (const BaseException &e) { + LOGE("%s", e.what()); + return e.getError(); + } + + MEDIA_VISION_FUNCTION_LEAVE(); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_semantic_segmentation_get_label(mv_semantic_segmentation_h handle, unsigned int index, const char **label) +{ + MEDIA_VISION_SUPPORT_CHECK(mv_check_feature_key(feature_keys, num_keys, true)); + MEDIA_VISION_INSTANCE_CHECK(label); + + MEDIA_VISION_FUNCTION_ENTER(); + + try { + auto &result = + static_cast(machine_learning_native_get_result_cache(handle, TASK_NAME)); + + if (result.labels.empty()) + return MEDIA_VISION_ERROR_NO_DATA; + + if (index >= result.labels.size()) { + LOGE("Invalid index(index = %u, number of labels = %zu).", index, result.labels.size()); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + *label = result.labels[index].c_str(); + } catch (const BaseException &e) { + LOGE("%s", e.what()); + return e.getError(); + } + + MEDIA_VISION_FUNCTION_LEAVE(); + return MEDIA_VISION_ERROR_NONE; } \ No newline at end of file