--- /dev/null
+/**
+ * Copyright (c) 2025 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.
+ */
+
+#ifndef __MV_SEMANTIC_SEGMENTATION_H__
+#define __MV_SEMANTIC_SEGMENTATION_H__
+
+#include "IInferenceTaskInterface.h"
+#include "mv_semantic_segmentation_internal.h"
+#include "SingleoCommonTypes.h"
+
+namespace singleo
+{
+namespace inference
+{
+namespace backends
+{
+class MvSemanticSegmentation : public IInferenceTaskInterface
+{
+private:
+ mv_semantic_segmentation_h _handle {};
+ SsResultType _output_data {};
+
+public:
+ MvSemanticSegmentation();
+ virtual ~MvSemanticSegmentation();
+
+ void configure() override;
+ void prepare() override;
+ void invoke(BaseDataType &input, bool async) override;
+ BaseResultType &result() override;
+};
+
+} // backends
+} // inference
+} // singleo
+
+#endif
--- /dev/null
+/**
+ * Copyright (c) 2025 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 <stdexcept>
+#include "MvSemanticSegmentation.h"
+#include "SingleoLog.h"
+
+using namespace std;
+
+namespace singleo
+{
+namespace inference
+{
+namespace backends
+{
+MvSemanticSegmentation::MvSemanticSegmentation()
+{
+ int ret = mv_semantic_segmentation_create(&_handle);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to create semantic segmentation handle.");
+}
+
+MvSemanticSegmentation::~MvSemanticSegmentation()
+{
+ try {
+ int ret = mv_semantic_segmentation_destroy(_handle);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ SINGLEO_LOGE("Fail to destroy semantic segmentation handle.(%d)", ret);
+ } catch (const std::runtime_error &e) {
+ SINGLEO_LOGE("Failed to destroy semantic segmentation handle: %s", e.what());
+ }
+}
+
+void MvSemanticSegmentation::configure()
+{
+ int ret = mv_semantic_segmentation_configure(_handle);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to configure semantic segmentation.");
+}
+
+void MvSemanticSegmentation::prepare()
+{
+ int ret = mv_semantic_segmentation_prepare(_handle);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to prepare semantic segmentation.");
+}
+
+void MvSemanticSegmentation::invoke(BaseDataType &input, bool async)
+{
+ ImageDataType &data = dynamic_cast<ImageDataType &>(input);
+
+ if (data._data_type != DataType::IMAGE) {
+ SINGLEO_LOGE("Invalid input type.");
+ throw invalid_argument("Input type not support.");
+ }
+
+ mv_source_h mv_src;
+
+ int ret = mv_create_source(&mv_src);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to create mv source.");
+
+ try {
+ ret = mv_source_fill_by_buffer(mv_src, data.ptr, data.width * data.height * data.byte_per_pixel, data.width,
+ data.height, MEDIA_VISION_COLORSPACE_RGB888);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to convert to mv source.");
+
+ ret = mv_semantic_segmentation_inference(_handle, mv_src);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to invoke semantic segmentation.");
+ } catch (std::runtime_error &e) {
+ SINGLEO_LOGE("%s", e.what());
+ }
+
+ ret = mv_destroy_source(mv_src);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to destroy mv source.");
+}
+
+BaseResultType &MvSemanticSegmentation::result()
+{
+ unsigned long frame_number;
+ unsigned int result_cnt;
+
+ int ret = mv_semantic_segmentation_get_result_count(_handle, &frame_number, &result_cnt);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to get semantic segmentation result count.");
+
+ _output_data = SsResultType();
+ _output_data._is_empty = result_cnt == 0;
+ _output_data._frame_number = frame_number;
+
+ for (unsigned int idx = 0; idx < result_cnt; ++idx) {
+ ret = mv_semantic_segmentation_get_result(_handle, &_output_data.width, &_output_data.height, &_output_data.pixel_size, &_output_data._segment_map);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to get semantic segmentation label.");
+ }
+
+ return _output_data;
+}
+
+}
+}
+}