Add get label API support for semantic segmentation task.
Change-Id: Ic381b0157706d6b939e72517db134977570ca4a3
Signed-off-by: Inki Dae <inki.dae@samsung.com>
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.
unsigned int height {};
unsigned int pixel_size {};
std::vector<unsigned char> data;
+ unsigned int num_labels {};
std::vector<std::string> labels;
};
_result.width = static_cast<int>(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);
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<ImageSegmentationResult &>(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<ImageSegmentationResult &>(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