summaryrefslogtreecommitdiff
path: root/mv_common
diff options
context:
space:
mode:
authorInki Dae <inki.dae@samsung.com>2022-08-19 19:51:00 +0900
committerInki Dae <inki.dae@samsung.com>2022-09-02 17:09:25 +0900
commit8a0bcb13b9aa25b0205080cefaac53aba7833aca (patch)
tree8414128b1ca51e8a3d7ddb0bfa1f6f245d0110c9 /mv_common
parent38af500c31778fcacbff4890289931a2b2b4d2c9 (diff)
downloadmediavision-8a0bcb13b9aa25b0205080cefaac53aba7833aca.tar.gz
mediavision-8a0bcb13b9aa25b0205080cefaac53aba7833aca.tar.bz2
mediavision-8a0bcb13b9aa25b0205080cefaac53aba7833aca.zip
mv_machine_learning: code refactoring to Inference class
[Issue type] : code refactoring Did code refactoring to Run member function of Inference class by doing, - extracted a function which converts mv sources to cv ones. And this converting function is now considered for multiple sources. - introduced a new util file which can contain common things to be used by machine learning relevant code. - and did code sliding and renaming several variables. This is just a step for next code refactoring and there are many things to do. Change-Id: Ic78ef26156481def5ecda537657638c613a304d1 Signed-off-by: Inki Dae <inki.dae@samsung.com>
Diffstat (limited to 'mv_common')
-rw-r--r--mv_common/include/util.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/mv_common/include/util.h b/mv_common/include/util.h
new file mode 100644
index 00000000..5cb6b8e0
--- /dev/null
+++ b/mv_common/include/util.h
@@ -0,0 +1,85 @@
+/**
+ * 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 __UTIL_H__
+#define __UTIL_H__
+
+#include <vector>
+
+#include <opencv2/core.hpp>
+#include <opencv2/imgproc.hpp>
+
+namespace mediavision
+{
+namespace common
+{
+namespace util
+{
+
+ static int ConvertToCvSource(std::vector<mv_source_h> &mv_srcs, std::vector<cv::Mat>& cv_srcs, std::vector<mv_rectangle_s>& rects)
+ {
+ unsigned int rect_idx = 0;
+
+ for (auto& mv_src : mv_srcs) {
+ mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
+ mv_rectangle_s *roi = &rects[rect_idx++];
+ 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))
+ return MEDIA_VISION_ERROR_INTERNAL;
+
+ // TODO. Let's support various color spaces.
+
+ if (colorspace != MEDIA_VISION_COLORSPACE_RGB888) {
+ LOGE("Not Supported format.");
+ return MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT;
+ }
+
+ /* convert mv_source to cv::Mat */
+ cv::Mat cvSource;
+
+ if (roi == NULL) {
+ cvSource = cv::Mat(cv::Size(width, height), CV_MAKETYPE(CV_8U, 3), buffer).clone();
+ } else {
+ cv::Rect cvRoi;
+
+ cvRoi.x = roi->point.x;
+ cvRoi.y = roi->point.y;
+ cvRoi.width = unsigned(roi->point.x + roi->width) >= width ? width - roi->point.x : roi->width;
+ cvRoi.height = unsigned(roi->point.y + roi->height) >= height ? height - roi->point.y : roi->height;
+ cvSource = cv::Mat(cv::Size(width, height), CV_MAKETYPE(CV_8U, 3), buffer)(cvRoi).clone();
+ }
+
+ cv_srcs.push_back(cvSource);
+ LOGI("Size: w:%u, h:%u", cvSource.size().width, cvSource.size().height);
+ }
+
+ return MEDIA_VISION_ERROR_NONE;
+ }
+
+
+} // util
+} // common
+} // mediavision
+
+#endif \ No newline at end of file