--- /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 __STDC1_H__
+#define __STDC1_H__
+
+#include "mv_private.h"
+#include <memory>
+#include <mv_common.h>
+#include <string>
+
+#include "ImageSegmentation.h"
+#include <mv_inference_type.h>
+
+namespace mediavision
+{
+namespace machine_learning
+{
+template<typename T> class Stdc1 : public ImageSegmentation<T>
+{
+ using ImageSegmentation<T>::_config;
+ using ImageSegmentation<T>::_preprocess;
+ using ImageSegmentation<T>::_labels;
+
+private:
+ ImageSegmentationResult _result;
+
+public:
+ Stdc1(std::shared_ptr<Config> config);
+ ~Stdc1();
+
+ ImageSegmentationResult &result() override;
+};
+
+} // machine_learning
+} // mediavision
+
+#endif
\ No newline at end of file
#include "SemanticSegmentationAdapter.h"
#include "DeeplabV3.h"
+#include "Stdc1.h"
#include "MvMlException.h"
#include "mv_image_segmentation_config.h"
case ImageSegmentationTaskType::DEEPLAB_V3_MOBILENET_V2:
_semantic_segmentation = make_unique<DeeplabV3<U> >(_config);
break;
+ case ImageSegmentationTaskType::STDC1:
+ _semantic_segmentation = make_unique<Stdc1<U> >(_config);
+ break;
default:
throw InvalidOperation("Invalid semantic segmentation task type.");
}
if (model_name == "DEEPLAB_V3_MOBILENET_V2")
return ImageSegmentationTaskType::DEEPLAB_V3_MOBILENET_V2;
+ else if (model_name == "STDC1")
+ return ImageSegmentationTaskType::STDC1;
throw InvalidParameter("Invalid semantic segmentation model name.");
}
--- /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 <algorithm>
+#include <cmath>
+#include <map>
+#include <string.h>
+
+#include <opencv2/core.hpp>
+#include <opencv2/imgcodecs.hpp>
+#include <opencv2/imgproc.hpp>
+
+#include "Stdc1.h"
+#include "MvMlException.h"
+#include "Postprocess.h"
+#include "mv_image_segmentation_config.h"
+
+using namespace std;
+using namespace mediavision::inference;
+using namespace mediavision::machine_learning::exception;
+
+namespace mediavision
+{
+namespace machine_learning
+{
+template<typename T>
+Stdc1<T>::Stdc1(std::shared_ptr<Config> config)
+ : ImageSegmentation<T>(config), _result()
+{}
+
+template<typename T> Stdc1<T>::~Stdc1()
+{}
+
+template<typename T> ImageSegmentationResult &Stdc1<T>::result()
+{
+ // Clear _result object because result() function can be called every time user wants
+ // so make sure to clear existing result data before getting the data again.
+ _result = ImageSegmentationResult();
+
+ vector<string> names;
+ ImageSegmentation<T>::getOutputNames(names);
+ vector<T> outputTensor;
+ ImageSegmentation<T>::getOutputTensor(names[0], outputTensor);
+
+ auto &outputMetaMap = _config->getOutputMetaMap();
+ auto &metaInfo = outputMetaMap["stdc1/argmax1"];
+ auto height = metaInfo->dims[1];
+ auto width = metaInfo->dims[2];
+ auto ori_src_width = static_cast<double>(_preprocess.getImageWidth()[0]);
+ auto ori_src_height = static_cast<double>(_preprocess.getImageHeight()[0]);
+ auto input_tensor_width = static_cast<double>(width);
+ auto input_tensor_height = static_cast<double>(height);
+
+ // Calculate the ratio[A] between the original image size and the input tensor size.
+ auto width_ratio = ori_src_width / input_tensor_width;
+ auto height_ratio = ori_src_height / input_tensor_height;
+
+ _result.height = static_cast<int>(input_tensor_height * height_ratio);
+ _result.width = static_cast<int>(input_tensor_width * width_ratio);
+ _result.pixel_size = 1;
+ _result.labels = _labels;
+
+ 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);
+
+ cv::resize(cvSource, cvDest, cv::Size(_result.width, _result.height), 0, 0, cv::INTER_NEAREST);
+
+ for (unsigned int h = 0; h < _result.height; ++h)
+ for (unsigned int w = 0; w < _result.width; ++w)
+ _result.data.push_back(*cvDest.ptr<unsigned char>(h, w));
+
+ return _result;
+}
+
+template class Stdc1<unsigned char>;
+}
+}
int mv_semantic_segmentation_get_result_count(mv_semantic_segmentation_h handle, unsigned long *frame_number,
unsigned int *result_cnt)
{
+ MEDIA_VISION_SUPPORT_CHECK(mv_check_feature_key(feature_keys, num_keys, true));
+ MEDIA_VISION_INSTANCE_CHECK(handle);
+ MEDIA_VISION_INSTANCE_CHECK(frame_number);
+ MEDIA_VISION_INSTANCE_CHECK(result_cnt);
+
+ MEDIA_VISION_FUNCTION_ENTER();
+
+ try {
+ auto &result = static_cast<ImageSegmentationResult &>(machine_learning_native_get_result(handle, TASK_NAME));
+
+ *frame_number = result.frame_number;
+ *result_cnt = result.data.size() ? 1 : 0;
+ } catch (const BaseException &e) {
+ LOGE("%s", e.what());
+ return e.getError();
+ }
+
+ MEDIA_VISION_FUNCTION_LEAVE();
return MEDIA_VISION_ERROR_NONE;
}