#include "Inference.h"
#include "facenet_parser.h"
#include "face_recognition_type.h"
-#include "Preprocess.h"
+#include "machine_learning_preprocess.h"
namespace mediavision
{
#include "Inference.h"
#include "image_classification_type.h"
#include "ImageClassificationParser.h"
-#include "Preprocess.h"
+#include "machine_learning_preprocess.h"
namespace mediavision
{
#include "Inference.h"
#include "landmark_detection_type.h"
#include "LandmarkDetectionParser.h"
-#include "Preprocess.h"
+#include "machine_learning_preprocess.h"
namespace mediavision
{
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include/media
FILES_MATCHING
- PATTERN "Preprocess.h"
+ PATTERN "machine_learning_preprocess.h"
)
\ No newline at end of file
+++ /dev/null
-/**
- * Copyright (c) 2022 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 __PREPROCESS_H__
-#define __PREPORCESS_H__
-
-#include <string>
-#include <map>
-#include <memory>
-#include <vector>
-
-#include <inference_engine_type.h>
-#include <mv_inference_type.h>
-
-#include "mv_private.h"
-#include "mv_common.h"
-
-#include <opencv2/core.hpp>
-#include <opencv2/imgproc.hpp>
-
-/**
- * @file Preprocess.h
- * @brief This file contains the Preprocess class definition which
- * provides Preprocess before running inference.
- */
-
-namespace mediavision
-{
-namespace machine_learning
-{
-struct PreprocessConfig {
- bool skip_csc {}; /**< It indicates whether color space conversion operation should be skipped or not. */
- mv_colorspace_e output_format {}; /**< The pixel format of output tensor to be converted. */
- mv_inference_data_type_e output_data_type {}; /**< The data type of output tensor to be converted. */
- int output_channel {}; /** The channel size of output tensor te be converted. */
- int output_width {}; /** The width size of output tensor to be converted. */
- int output_height {}; /** The height size of output tensor to be converted. */
- bool normalize {}; /**< It indicates whether normalization to input data should be performed or not. */
- std::vector<double> mean;
- std::vector<double> std;
- bool quantize {}; /**< It indicates whether quantization to input data should be performed or not. */
- std::vector<double> scale;
- std::vector<double> zeropoint;
-};
-
-class Preprocess
-{
-public:
- Preprocess()
- {}
- ~Preprocess() = default;
-
- void setConfig(const PreprocessConfig &config);
- template<typename T> void run(mv_source_h &mv_src, std::vector<T> &inputVector);
-
- std::vector<unsigned int> &getImageWidth()
- {
- return _vImageWidth;
- }
- std::vector<unsigned int> &getImageHeight()
- {
- return _vImageHeight;
- }
-
-private:
- std::vector<unsigned int> _vImageWidth;
- std::vector<unsigned int> _vImageHeight;
- PreprocessConfig _config;
-
- int convertToCv(int given_type, int ch);
- void colorConvert(cv::Mat &source, cv::Mat &dest, int sType, int dType);
- void convertToCvSource(std::vector<mv_source_h> &mv_srcs, std::vector<cv::Mat> &cv_srcs);
- void normalize(cv::Mat &source, cv::Mat &dest, const std::vector<double> &mean, const std::vector<double> &std);
- void quantize(cv::Mat &source, cv::Mat &dest, const std::vector<double> &scale,
- const std::vector<double> &zeropoint);
-};
-
-} /* machine_learning */
-} /* mediavision */
-
-#endif /* __PREPROCESS_H__ */
--- /dev/null
+/**
+ * Copyright (c) 2022 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 __MACHINE_LEARNING_PREPROCESS_H__
+#define __MACHINE_LEARNING_PREPROCESS_H__
+
+#include <string>
+#include <map>
+#include <memory>
+#include <vector>
+
+#include <inference_engine_type.h>
+#include <mv_inference_type.h>
+
+#include "mv_private.h"
+#include "mv_common.h"
+
+#include <opencv2/core.hpp>
+#include <opencv2/imgproc.hpp>
+
+/**
+ * @file machine_learning_preprocess.h
+ * @brief This file contains the Preprocess class definition which
+ * provides Preprocess before running inference.
+ */
+
+namespace mediavision
+{
+namespace machine_learning
+{
+struct PreprocessConfig {
+ bool skip_csc {}; /**< It indicates whether color space conversion operation should be skipped or not. */
+ mv_colorspace_e output_format {}; /**< The pixel format of output tensor to be converted. */
+ mv_inference_data_type_e output_data_type {}; /**< The data type of output tensor to be converted. */
+ int output_channel {}; /** The channel size of output tensor te be converted. */
+ int output_width {}; /** The width size of output tensor to be converted. */
+ int output_height {}; /** The height size of output tensor to be converted. */
+ bool normalize {}; /**< It indicates whether normalization to input data should be performed or not. */
+ std::vector<double> mean;
+ std::vector<double> std;
+ bool quantize {}; /**< It indicates whether quantization to input data should be performed or not. */
+ std::vector<double> scale;
+ std::vector<double> zeropoint;
+};
+
+class Preprocess
+{
+public:
+ Preprocess()
+ {}
+ ~Preprocess() = default;
+
+ void setConfig(const PreprocessConfig &config);
+ template<typename T> void run(mv_source_h &mv_src, std::vector<T> &inputVector);
+
+ std::vector<unsigned int> &getImageWidth()
+ {
+ return _vImageWidth;
+ }
+ std::vector<unsigned int> &getImageHeight()
+ {
+ return _vImageHeight;
+ }
+
+private:
+ std::vector<unsigned int> _vImageWidth;
+ std::vector<unsigned int> _vImageHeight;
+ PreprocessConfig _config;
+
+ int convertToCv(int given_type, int ch);
+ void colorConvert(cv::Mat &source, cv::Mat &dest, int sType, int dType);
+ void convertToCvSource(std::vector<mv_source_h> &mv_srcs, std::vector<cv::Mat> &cv_srcs);
+ void normalize(cv::Mat &source, cv::Mat &dest, const std::vector<double> &mean, const std::vector<double> &std);
+ void quantize(cv::Mat &source, cv::Mat &dest, const std::vector<double> &scale,
+ const std::vector<double> &zeropoint);
+};
+
+} /* machine_learning */
+} /* mediavision */
+
+#endif /* __MACHINE_LEARNING_PREPROCESS_H__ */
+++ /dev/null
-/**
- * Copyright (c) 2022 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 <unistd.h>
-#include <fstream>
-#include <string>
-#include <queue>
-#include <algorithm>
-#include "Preprocess.h"
-#include "machine_learning_exception.h"
-
-constexpr int colorConvertTable[][12] = {
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 0, -1, 0, 0, 0, 0, 0, 0, 0, cv::COLOR_GRAY2BGR565, cv::COLOR_GRAY2RGB, cv::COLOR_GRAY2RGBA },
- { 0, cv::COLOR_YUV2GRAY_I420, -1, 0, 0, 0, 0, 0, 0, 0, cv::COLOR_RGBA2GRAY, cv::COLOR_YUV2RGBA_I420 },
- { 0, cv::COLOR_YUV2GRAY_NV12, 0, -1, 0, 0, 0, 0, 0, 0, cv::COLOR_YUV2RGB_NV12, cv::COLOR_YUV2RGBA_NV12 },
- { 0, cv::COLOR_YUV2GRAY_YV12, 0, 0, -1, 0, 0, 0, 0, 0, cv::COLOR_YUV2RGB_YV12, cv::COLOR_YUV2RGBA_YV12 },
- { 0, cv::COLOR_YUV2GRAY_NV21, 0, 0, 0, -1, 0, 0, 0, 0, cv::COLOR_YUV2RGB_NV21, cv::COLOR_YUV2RGBA_NV21 },
- { 0, cv::COLOR_YUV2GRAY_YUYV, 0, 0, 0, 0, -1, 0, 0, 0, cv::COLOR_YUV2RGB_YUYV, cv::COLOR_YUV2RGBA_YUYV },
- { 0, cv::COLOR_YUV2GRAY_UYVY, 0, 0, 0, 0, 0, -1, 0, 0, cv::COLOR_YUV2BGR_UYVY, cv::COLOR_YUV2BGRA_UYVY },
- { 0, cv::COLOR_YUV2GRAY_Y422, 0, 0, 0, 0, 0, 0, -1, 0, cv::COLOR_YUV2RGB_Y422, cv::COLOR_YUV2RGBA_Y422 },
- { 0, cv::COLOR_BGR5652GRAY, 0, 0, 0, 0, 0, 0, 0, -1, cv::COLOR_BGR5652BGR, cv::COLOR_BGR5652BGRA },
- { 0, cv::COLOR_RGB2GRAY, 0, 0, 0, 0, 0, 0, 0, 0, -1, cv::COLOR_RGB2RGBA },
- { 0, cv::COLOR_RGBA2GRAY, 0, 0, 0, 0, 0, 0, 0, cv::COLOR_BGRA2BGR565, cv::COLOR_RGBA2RGB, -1 }
-};
-
-using namespace std;
-using namespace mediavision::machine_learning::exception;
-
-namespace mediavision
-{
-namespace machine_learning
-{
-void Preprocess::colorConvert(cv::Mat &source, cv::Mat &dest, int sType, int dType)
-{
- LOGI("ENTER");
-
- auto conversionColor = static_cast<int>(colorConvertTable[sType][dType]);
- if (conversionColor == -1) { /* Don't need conversion */
- dest = source;
- } else if (conversionColor > 0) {
- /* Class for representation the given image as cv::Mat before conversion */
- cv::cvtColor(source, dest, conversionColor);
- } else {
- throw InvalidOperation("Fail to ColorConvert");
- }
-
- LOGI("LEAVE");
-}
-
-void Preprocess::normalize(cv::Mat &source, cv::Mat &dest, const vector<double> &mean, const vector<double> &std)
-{
- LOGI("ENTER");
-
- try {
- cv::subtract(source, cv::Scalar(mean[0], mean[1], mean[2]), dest);
- source = dest;
- cv::divide(source, cv::Scalar(std[0], std[1], std[2]), dest);
- } catch (cv::Exception &e) {
- throw InvalidOperation("Fail to substract/divide");
- }
-
- LOGI("LEAVE");
-}
-
-void Preprocess::quantize(cv::Mat &source, cv::Mat &dest, const vector<double> &scale, const vector<double> &zeropoint)
-{
- LOGI("ENTER");
-
- try {
- cv::subtract(source, cv::Scalar(zeropoint[0], zeropoint[1], zeropoint[2]), dest);
- source = dest;
- cv::multiply(source, cv::Scalar(scale[0], scale[1], scale[2]), dest);
- } catch (cv::Exception &e) {
- throw InvalidOperation("Fail to subtract/multiply");
- }
-
- LOGI("LEAVE");
-}
-
-int Preprocess::convertToCv(int given_type, int ch)
-{
- int type = 0;
-
- switch (given_type) {
- case INFERENCE_TENSOR_DATA_TYPE_UINT8:
- case MV_INFERENCE_DATA_UINT8:
- LOGI("Type is %d ch with UINT8", ch);
- type = ch == 1 ? CV_8UC1 : CV_8UC3;
- break;
- case INFERENCE_TENSOR_DATA_TYPE_FLOAT32:
- case MV_INFERENCE_DATA_FLOAT32:
- LOGI("Type is %d ch with FLOAT32", ch);
- type = ch == 1 ? CV_32FC1 : CV_32FC3;
- break;
- default:
- LOGI("unknown data type so FLOAT32 data type will be used in default");
- type = ch == 1 ? CV_32FC1 : CV_32FC3;
- break;
- }
-
- return type;
-}
-
-void Preprocess::convertToCvSource(vector<mv_source_h> &mv_srcs, vector<cv::Mat> &cv_srcs)
-{
- for (auto &mv_src : mv_srcs) {
- mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
- unsigned int width = 0, height = 0;
- unsigned int bufferSize = 0;
- unsigned char *buffer = NULL;
-
- if (mv_source_get_width(mv_src, &width) != MEDIA_VISION_ERROR_NONE ||
- mv_source_get_height(mv_src, &height) != MEDIA_VISION_ERROR_NONE ||
- mv_source_get_colorspace(mv_src, &colorspace) != MEDIA_VISION_ERROR_NONE ||
- mv_source_get_buffer(mv_src, &buffer, &bufferSize))
- throw InvalidParameter("Invalid Parameter.");
-
- _vImageWidth.push_back(width);
- _vImageHeight.push_back(height);
-
- // TODO. Let's support various color spaces.
-
- if (colorspace != MEDIA_VISION_COLORSPACE_RGB888)
- throw InvalidOperation("Not Supported format.");
-
- /* convert mv_source to cv::Mat */
- cv::Mat cvSource = cv::Mat(cv::Size(width, height), CV_MAKETYPE(CV_8U, 3), buffer).clone();
-
- cv_srcs.push_back(cvSource);
- LOGI("Size: w:%u, h:%u", cvSource.size().width, cvSource.size().height);
- }
-}
-
-void Preprocess::setConfig(const PreprocessConfig &config)
-{
- _config = config;
-}
-
-template<typename T> void Preprocess::run(mv_source_h &mv_src, vector<T> &inputVector)
-{
- LOGI("ENTER");
-
- vector<cv::Mat> oriCvSources;
- vector<mv_source_h> mv_srcs = { mv_src };
-
- _vImageWidth.clear();
- _vImageHeight.clear();
- convertToCvSource(mv_srcs, oriCvSources);
-
- inputVector.resize(_config.output_height * _config.output_width * _config.output_channel);
-
- int data_type = convertToCv(_config.output_data_type, _config.output_channel);
- // dest is a wrapper of the buffer.
- cv::Mat dest(cv::Size(_config.output_width, _config.output_height), data_type, inputVector.data());
- cv::Mat cvSource, cvDest;
-
- // cvSource has new allocation with dest.size()
- cv::resize(oriCvSources[0], cvSource, dest.size());
-
- if (_config.skip_csc) {
- cvSource.convertTo(dest, dest.type());
- } else {
- mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
- int ret = mv_source_get_colorspace(mv_srcs[0], &colorspace);
- if (ret != MEDIA_VISION_ERROR_NONE)
- throw InvalidOperation("Fail to get color space.");
-
- // cvDest is allocated if colorspace is not RGB888, and
- // cvDest shares the data with cvSource if the colorspace is RGB888.
- colorConvert(cvSource, cvDest, colorspace, _config.output_format);
- cvDest.convertTo(dest, dest.type());
- }
-
- if (_config.normalize)
- normalize(dest, dest, _config.mean, _config.std);
-
- if (_config.quantize)
- quantize(dest, dest, _config.scale, _config.zeropoint);
-
- LOGI("LEAVE");
-}
-
-template void Preprocess::run<float>(mv_source_h &mv_src, vector<float> &inputVector);
-template void Preprocess::run<unsigned char>(mv_source_h &mv_src, vector<unsigned char> &inputVector);
-
-} /* machine_learning */
-} /* mediavision */
--- /dev/null
+/**
+ * Copyright (c) 2022 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 <unistd.h>
+#include <fstream>
+#include <string>
+#include <queue>
+#include <algorithm>
+#include "machine_learning_preprocess.h"
+#include "machine_learning_exception.h"
+
+constexpr int colorConvertTable[][12] = {
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 0, -1, 0, 0, 0, 0, 0, 0, 0, cv::COLOR_GRAY2BGR565, cv::COLOR_GRAY2RGB, cv::COLOR_GRAY2RGBA },
+ { 0, cv::COLOR_YUV2GRAY_I420, -1, 0, 0, 0, 0, 0, 0, 0, cv::COLOR_RGBA2GRAY, cv::COLOR_YUV2RGBA_I420 },
+ { 0, cv::COLOR_YUV2GRAY_NV12, 0, -1, 0, 0, 0, 0, 0, 0, cv::COLOR_YUV2RGB_NV12, cv::COLOR_YUV2RGBA_NV12 },
+ { 0, cv::COLOR_YUV2GRAY_YV12, 0, 0, -1, 0, 0, 0, 0, 0, cv::COLOR_YUV2RGB_YV12, cv::COLOR_YUV2RGBA_YV12 },
+ { 0, cv::COLOR_YUV2GRAY_NV21, 0, 0, 0, -1, 0, 0, 0, 0, cv::COLOR_YUV2RGB_NV21, cv::COLOR_YUV2RGBA_NV21 },
+ { 0, cv::COLOR_YUV2GRAY_YUYV, 0, 0, 0, 0, -1, 0, 0, 0, cv::COLOR_YUV2RGB_YUYV, cv::COLOR_YUV2RGBA_YUYV },
+ { 0, cv::COLOR_YUV2GRAY_UYVY, 0, 0, 0, 0, 0, -1, 0, 0, cv::COLOR_YUV2BGR_UYVY, cv::COLOR_YUV2BGRA_UYVY },
+ { 0, cv::COLOR_YUV2GRAY_Y422, 0, 0, 0, 0, 0, 0, -1, 0, cv::COLOR_YUV2RGB_Y422, cv::COLOR_YUV2RGBA_Y422 },
+ { 0, cv::COLOR_BGR5652GRAY, 0, 0, 0, 0, 0, 0, 0, -1, cv::COLOR_BGR5652BGR, cv::COLOR_BGR5652BGRA },
+ { 0, cv::COLOR_RGB2GRAY, 0, 0, 0, 0, 0, 0, 0, 0, -1, cv::COLOR_RGB2RGBA },
+ { 0, cv::COLOR_RGBA2GRAY, 0, 0, 0, 0, 0, 0, 0, cv::COLOR_BGRA2BGR565, cv::COLOR_RGBA2RGB, -1 }
+};
+
+using namespace std;
+using namespace mediavision::machine_learning::exception;
+
+namespace mediavision
+{
+namespace machine_learning
+{
+void Preprocess::colorConvert(cv::Mat &source, cv::Mat &dest, int sType, int dType)
+{
+ LOGI("ENTER");
+
+ auto conversionColor = static_cast<int>(colorConvertTable[sType][dType]);
+ if (conversionColor == -1) { /* Don't need conversion */
+ dest = source;
+ } else if (conversionColor > 0) {
+ /* Class for representation the given image as cv::Mat before conversion */
+ cv::cvtColor(source, dest, conversionColor);
+ } else {
+ throw InvalidOperation("Fail to ColorConvert");
+ }
+
+ LOGI("LEAVE");
+}
+
+void Preprocess::normalize(cv::Mat &source, cv::Mat &dest, const vector<double> &mean, const vector<double> &std)
+{
+ LOGI("ENTER");
+
+ try {
+ cv::subtract(source, cv::Scalar(mean[0], mean[1], mean[2]), dest);
+ source = dest;
+ cv::divide(source, cv::Scalar(std[0], std[1], std[2]), dest);
+ } catch (cv::Exception &e) {
+ throw InvalidOperation("Fail to substract/divide");
+ }
+
+ LOGI("LEAVE");
+}
+
+void Preprocess::quantize(cv::Mat &source, cv::Mat &dest, const vector<double> &scale, const vector<double> &zeropoint)
+{
+ LOGI("ENTER");
+
+ try {
+ cv::subtract(source, cv::Scalar(zeropoint[0], zeropoint[1], zeropoint[2]), dest);
+ source = dest;
+ cv::multiply(source, cv::Scalar(scale[0], scale[1], scale[2]), dest);
+ } catch (cv::Exception &e) {
+ throw InvalidOperation("Fail to subtract/multiply");
+ }
+
+ LOGI("LEAVE");
+}
+
+int Preprocess::convertToCv(int given_type, int ch)
+{
+ int type = 0;
+
+ switch (given_type) {
+ case INFERENCE_TENSOR_DATA_TYPE_UINT8:
+ case MV_INFERENCE_DATA_UINT8:
+ LOGI("Type is %d ch with UINT8", ch);
+ type = ch == 1 ? CV_8UC1 : CV_8UC3;
+ break;
+ case INFERENCE_TENSOR_DATA_TYPE_FLOAT32:
+ case MV_INFERENCE_DATA_FLOAT32:
+ LOGI("Type is %d ch with FLOAT32", ch);
+ type = ch == 1 ? CV_32FC1 : CV_32FC3;
+ break;
+ default:
+ LOGI("unknown data type so FLOAT32 data type will be used in default");
+ type = ch == 1 ? CV_32FC1 : CV_32FC3;
+ break;
+ }
+
+ return type;
+}
+
+void Preprocess::convertToCvSource(vector<mv_source_h> &mv_srcs, vector<cv::Mat> &cv_srcs)
+{
+ for (auto &mv_src : mv_srcs) {
+ mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
+ unsigned int width = 0, height = 0;
+ unsigned int bufferSize = 0;
+ unsigned char *buffer = NULL;
+
+ if (mv_source_get_width(mv_src, &width) != MEDIA_VISION_ERROR_NONE ||
+ mv_source_get_height(mv_src, &height) != MEDIA_VISION_ERROR_NONE ||
+ mv_source_get_colorspace(mv_src, &colorspace) != MEDIA_VISION_ERROR_NONE ||
+ mv_source_get_buffer(mv_src, &buffer, &bufferSize))
+ throw InvalidParameter("Invalid Parameter.");
+
+ _vImageWidth.push_back(width);
+ _vImageHeight.push_back(height);
+
+ // TODO. Let's support various color spaces.
+
+ if (colorspace != MEDIA_VISION_COLORSPACE_RGB888)
+ throw InvalidOperation("Not Supported format.");
+
+ /* convert mv_source to cv::Mat */
+ cv::Mat cvSource = cv::Mat(cv::Size(width, height), CV_MAKETYPE(CV_8U, 3), buffer).clone();
+
+ cv_srcs.push_back(cvSource);
+ LOGI("Size: w:%u, h:%u", cvSource.size().width, cvSource.size().height);
+ }
+}
+
+void Preprocess::setConfig(const PreprocessConfig &config)
+{
+ _config = config;
+}
+
+template<typename T> void Preprocess::run(mv_source_h &mv_src, vector<T> &inputVector)
+{
+ LOGI("ENTER");
+
+ vector<cv::Mat> oriCvSources;
+ vector<mv_source_h> mv_srcs = { mv_src };
+
+ _vImageWidth.clear();
+ _vImageHeight.clear();
+ convertToCvSource(mv_srcs, oriCvSources);
+
+ inputVector.resize(_config.output_height * _config.output_width * _config.output_channel);
+
+ int data_type = convertToCv(_config.output_data_type, _config.output_channel);
+ // dest is a wrapper of the buffer.
+ cv::Mat dest(cv::Size(_config.output_width, _config.output_height), data_type, inputVector.data());
+ cv::Mat cvSource, cvDest;
+
+ // cvSource has new allocation with dest.size()
+ cv::resize(oriCvSources[0], cvSource, dest.size());
+
+ if (_config.skip_csc) {
+ cvSource.convertTo(dest, dest.type());
+ } else {
+ mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
+ int ret = mv_source_get_colorspace(mv_srcs[0], &colorspace);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw InvalidOperation("Fail to get color space.");
+
+ // cvDest is allocated if colorspace is not RGB888, and
+ // cvDest shares the data with cvSource if the colorspace is RGB888.
+ colorConvert(cvSource, cvDest, colorspace, _config.output_format);
+ cvDest.convertTo(dest, dest.type());
+ }
+
+ if (_config.normalize)
+ normalize(dest, dest, _config.mean, _config.std);
+
+ if (_config.quantize)
+ quantize(dest, dest, _config.scale, _config.zeropoint);
+
+ LOGI("LEAVE");
+}
+
+template void Preprocess::run<float>(mv_source_h &mv_src, vector<float> &inputVector);
+template void Preprocess::run<unsigned char>(mv_source_h &mv_src, vector<unsigned char> &inputVector);
+
+} /* machine_learning */
+} /* mediavision */
#include "Inference.h"
#include "object_detection_type.h"
#include "ObjectDetectionParser.h"
-#include "Preprocess.h"
+#include "machine_learning_preprocess.h"
#include "iobject_detection.h"
namespace mediavision
#include "Inference.h"
#include "object_detection_3d_type.h"
#include "ObjectDetection3dParser.h"
-#include "Preprocess.h"
+#include "machine_learning_preprocess.h"
namespace mediavision
{
%files machine_learning-devel
%{_includedir}/media/mv_infer*.h
%{_includedir}/media/machine_learning_exception.h
-%{_includedir}/media/Preprocess.h
+%{_includedir}/media/machine_learning_preprocess.h
%{_libdir}/pkgconfig/*inference.pc
%if "%{enable_ml_face_recognition}" == "1"
%{_includedir}/media/mv_face_recognition*.h