mv3d: fix build warning and cleanup
authorInki Dae <inki.dae@samsung.com>
Wed, 21 Sep 2022 09:00:07 +0000 (18:00 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Thu, 22 Sep 2022 06:06:57 +0000 (15:06 +0900)
[Issue type] : code cleanup

Change-Id: I86daac442b5aadb0b40ead94f28b10fc4944ffed
Signed-off-by: Inki Dae <inki.dae@samsung.com>
mv_3d/3d/src/mv_3d internal.cpp [deleted file]
mv_3d/3d/src/mv_3d_internal.cpp [new file with mode: 0644]
mv_machine_learning/inference/src/ObjectDecoder.cpp
test/testsuites/mv3d/depth_test_suite.cpp
test/testsuites/mv3d/depthstream_test_suite.cpp

diff --git a/mv_3d/3d/src/mv_3d internal.cpp b/mv_3d/3d/src/mv_3d internal.cpp
deleted file mode 100644 (file)
index 4c52156..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/**
- * 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 <memory>
-#include <open3d/Open3D.h>
-
-#include "mv_3d_internal.h"
-#include "mv_private.h"
-#include "mv_3d_private.h"
-#include "Mv3d.h"
-
-#define DISTANCE_THRESHOLD 0.01
-#define RANSAC_NUMBER 3
-#define NUM_ITERATIONS 1000
-
-using namespace open3d;
-using namespace mediavision::mv3d;
-
-int mv_3d_pointcloud_plane_model_create(mv_3d_pointcloud_plane_model_h *handle)
-{
-       MEDIA_VISION_NULL_ARG_CHECK(handle);
-
-       MEDIA_VISION_FUNCTION_ENTER();
-
-       /* do nothing */
-
-       MEDIA_VISION_FUNCTION_LEAVE();
-
-       return MEDIA_VISION_ERROR_NONE;
-}
-
-int mv_3d_pointcloud_plane_model_destroy(mv_3d_pointcloud_plane_model_h handle)
-{
-       MEDIA_VISION_INSTANCE_CHECK(handle);
-
-       MEDIA_VISION_FUNCTION_ENTER();
-
-       Eigen::Vector4d *model = (Eigen::Vector4d *) handle;
-       delete model;
-
-       MEDIA_VISION_FUNCTION_LEAVE();
-
-       return MEDIA_VISION_ERROR_NONE;
-}
-
-int mv_3d_pointcloud_plane_inlier_create(mv_3d_pointcloud_plane_inlier_h *handle)
-{
-       MEDIA_VISION_NULL_ARG_CHECK(handle);
-
-       MEDIA_VISION_FUNCTION_ENTER();
-
-       /* do nothing */
-
-       MEDIA_VISION_FUNCTION_LEAVE();
-
-       return MEDIA_VISION_ERROR_NONE;
-}
-
-int mv_3d_pointcloud_plane_inlier_destroy(mv_3d_pointcloud_plane_inlier_h handle)
-{
-       MEDIA_VISION_INSTANCE_CHECK(handle);
-
-       MEDIA_VISION_FUNCTION_ENTER();
-
-       std::vector<size_t> *inlier = (std::vector<size_t> *) handle;
-       delete inlier;
-
-       MEDIA_VISION_FUNCTION_LEAVE();
-
-       return MEDIA_VISION_ERROR_NONE;
-}
-
-/**
- * @file mv_3d_internal.c
- * @brief This file contains Media Vision 3D internal module.
- */
-
-int mv_3d_pointcloud_segment_plane(mv_3d_h mv3d,
-                       mv_3d_pointcloud_h pointcloud,
-                       mv_3d_pointcloud_plane_model_h *model,
-                       mv_3d_pointcloud_plane_inlier_h *inlier)
-{
-       MEDIA_VISION_NULL_ARG_CHECK(mv3d);
-       MEDIA_VISION_NULL_ARG_CHECK(pointcloud);
-       MEDIA_VISION_NULL_ARG_CHECK(model);
-       MEDIA_VISION_NULL_ARG_CHECK(inlier);
-       MEDIA_VISION_FUNCTION_ENTER();
-
-       mv_3d_pointcloud_s *s = (mv_3d_pointcloud_s*) pointcloud;
-       Eigen::Vector4d *best_plane_model = new Eigen::Vector4d;
-       std::vector<size_t> *plane_inlier = new std::vector<size_t>;
-       auto pPcd = static_cast<std::shared_ptr<open3d::geometry::PointCloud>*>(s->pointcloud);
-       open3d::geometry::PointCloud p;
-       p += **pPcd;
-
-       std::tie(*best_plane_model, *plane_inlier) = p.SegmentPlane(DISTANCE_THRESHOLD, RANSAC_NUMBER, NUM_ITERATIONS);
-       *model = (mv_3d_pointcloud_plane_model_h) best_plane_model;
-       *inlier = (mv_3d_pointcloud_plane_inlier_h) plane_inlier;
-
-       MEDIA_VISION_FUNCTION_LEAVE();
-
-       return MEDIA_VISION_ERROR_NONE;
-}
-
-int mv_3d_pointcloud_plane_write_file(mv_3d_h mv3d,
-                       mv_3d_pointcloud_plane_model_h model,
-                       mv_3d_pointcloud_plane_inlier_h inlier,
-                       mv_3d_pointcloud_h pointcloud,
-                       mv_3d_pointcloud_type_e type,
-                       char *filename)
-{
-       MEDIA_VISION_NULL_ARG_CHECK(mv3d);
-       MEDIA_VISION_NULL_ARG_CHECK(model);
-       MEDIA_VISION_NULL_ARG_CHECK(inlier);
-       MEDIA_VISION_FUNCTION_ENTER();
-
-       mv_3d_pointcloud_s *s = (mv_3d_pointcloud_s*) pointcloud;
-       Eigen::Vector4d *best_plane_model = (Eigen::Vector4d*) model;
-       std::vector<size_t> *plane_inlier = (std::vector<size_t>*) inlier;
-       auto pPcd = static_cast<std::shared_ptr<open3d::geometry::PointCloud>*>(s->pointcloud);
-       open3d::geometry::PointCloud p;
-       p += **pPcd;
-
-       std::shared_ptr<geometry::PointCloud> plane = p.SelectByIndex(*plane_inlier);
-       mv_3d_pointcloud_s _pcd = {.type = MV_3D_POINTCLOUD_TYPE_PCD_BIN, .pointcloud = NULL};
-       _pcd.pointcloud = static_cast<void*>(
-                       new std::shared_ptr<open3d::geometry::PointCloud>(
-                                       std::move(plane)));
-       mv_3d_pointcloud_h pcd = &_pcd;
-
-       auto pMv3d = static_cast<Mv3d *>(mv3d);
-       int ret = pMv3d->WritePointcloudFile(pcd, type, filename);
-       if (ret != MEDIA_VISION_ERROR_NONE) {
-               LOGE("Failed to write pointcloud plane file");
-               ret = MEDIA_VISION_ERROR_INTERNAL;
-       }
-
-       MEDIA_VISION_FUNCTION_LEAVE();
-
-       return ret;
-}
\ No newline at end of file
diff --git a/mv_3d/3d/src/mv_3d_internal.cpp b/mv_3d/3d/src/mv_3d_internal.cpp
new file mode 100644 (file)
index 0000000..40b6237
--- /dev/null
@@ -0,0 +1,153 @@
+/**
+ * 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 <memory>
+#include <open3d/Open3D.h>
+
+#include "mv_3d_internal.h"
+#include "mv_private.h"
+#include "mv_3d_private.h"
+#include "Mv3d.h"
+
+#define DISTANCE_THRESHOLD 0.01
+#define RANSAC_NUMBER 3
+#define NUM_ITERATIONS 1000
+
+using namespace open3d;
+using namespace mediavision::mv3d;
+
+int mv_3d_pointcloud_plane_model_create(mv_3d_pointcloud_plane_model_h *handle)
+{
+       MEDIA_VISION_NULL_ARG_CHECK(handle);
+
+       MEDIA_VISION_FUNCTION_ENTER();
+
+       /* do nothing */
+
+       MEDIA_VISION_FUNCTION_LEAVE();
+
+       return MEDIA_VISION_ERROR_NONE;
+}
+
+int mv_3d_pointcloud_plane_model_destroy(mv_3d_pointcloud_plane_model_h handle)
+{
+       MEDIA_VISION_INSTANCE_CHECK(handle);
+
+       MEDIA_VISION_FUNCTION_ENTER();
+
+       Eigen::Vector4d *model = (Eigen::Vector4d *) handle;
+       delete model;
+
+       MEDIA_VISION_FUNCTION_LEAVE();
+
+       return MEDIA_VISION_ERROR_NONE;
+}
+
+int mv_3d_pointcloud_plane_inlier_create(mv_3d_pointcloud_plane_inlier_h *handle)
+{
+       MEDIA_VISION_NULL_ARG_CHECK(handle);
+
+       MEDIA_VISION_FUNCTION_ENTER();
+
+       /* do nothing */
+
+       MEDIA_VISION_FUNCTION_LEAVE();
+
+       return MEDIA_VISION_ERROR_NONE;
+}
+
+int mv_3d_pointcloud_plane_inlier_destroy(mv_3d_pointcloud_plane_inlier_h handle)
+{
+       MEDIA_VISION_INSTANCE_CHECK(handle);
+
+       MEDIA_VISION_FUNCTION_ENTER();
+
+       std::vector<size_t> *inlier = (std::vector<size_t> *) handle;
+       delete inlier;
+
+       MEDIA_VISION_FUNCTION_LEAVE();
+
+       return MEDIA_VISION_ERROR_NONE;
+}
+
+/**
+ * @file mv_3d_internal.c
+ * @brief This file contains Media Vision 3D internal module.
+ */
+
+int mv_3d_pointcloud_segment_plane(mv_3d_h mv3d,
+                       mv_3d_pointcloud_h pointcloud,
+                       mv_3d_pointcloud_plane_model_h *model,
+                       mv_3d_pointcloud_plane_inlier_h *inlier)
+{
+       MEDIA_VISION_NULL_ARG_CHECK(mv3d);
+       MEDIA_VISION_NULL_ARG_CHECK(pointcloud);
+       MEDIA_VISION_NULL_ARG_CHECK(model);
+       MEDIA_VISION_NULL_ARG_CHECK(inlier);
+       MEDIA_VISION_FUNCTION_ENTER();
+
+       mv_3d_pointcloud_s *s = (mv_3d_pointcloud_s*) pointcloud;
+       Eigen::Vector4d *best_plane_model = new Eigen::Vector4d;
+       std::vector<size_t> *plane_inlier = new std::vector<size_t>;
+       auto pPcd = static_cast<std::shared_ptr<open3d::geometry::PointCloud>*>(s->pointcloud);
+       open3d::geometry::PointCloud p;
+       p += **pPcd;
+
+       std::tie(*best_plane_model, *plane_inlier) = p.SegmentPlane(DISTANCE_THRESHOLD, RANSAC_NUMBER, NUM_ITERATIONS);
+       *model = (mv_3d_pointcloud_plane_model_h) best_plane_model;
+       *inlier = (mv_3d_pointcloud_plane_inlier_h) plane_inlier;
+
+       MEDIA_VISION_FUNCTION_LEAVE();
+
+       return MEDIA_VISION_ERROR_NONE;
+}
+
+int mv_3d_pointcloud_plane_write_file(mv_3d_h mv3d,
+                       mv_3d_pointcloud_plane_model_h model,
+                       mv_3d_pointcloud_plane_inlier_h inlier,
+                       mv_3d_pointcloud_h pointcloud,
+                       mv_3d_pointcloud_type_e type,
+                       char *filename)
+{
+       MEDIA_VISION_NULL_ARG_CHECK(mv3d);
+       MEDIA_VISION_NULL_ARG_CHECK(model);
+       MEDIA_VISION_NULL_ARG_CHECK(inlier);
+       MEDIA_VISION_FUNCTION_ENTER();
+
+       mv_3d_pointcloud_s *s = (mv_3d_pointcloud_s*) pointcloud;
+       std::vector<size_t> *plane_inlier = (std::vector<size_t>*) inlier;
+       auto pPcd = static_cast<std::shared_ptr<open3d::geometry::PointCloud>*>(s->pointcloud);
+       open3d::geometry::PointCloud p;
+       p += **pPcd;
+
+       std::shared_ptr<geometry::PointCloud> plane = p.SelectByIndex(*plane_inlier);
+       mv_3d_pointcloud_s _pcd = {.type = MV_3D_POINTCLOUD_TYPE_PCD_BIN, .pointcloud = NULL};
+       _pcd.pointcloud = static_cast<void*>(
+                       new std::shared_ptr<open3d::geometry::PointCloud>(
+                                       std::move(plane)));
+       mv_3d_pointcloud_h pcd = &_pcd;
+
+       auto pMv3d = static_cast<Mv3d *>(mv3d);
+       int ret = pMv3d->WritePointcloudFile(pcd, type, filename);
+       if (ret != MEDIA_VISION_ERROR_NONE) {
+               LOGE("Failed to write pointcloud plane file");
+               ret = MEDIA_VISION_ERROR_INTERNAL;
+       }
+
+       MEDIA_VISION_FUNCTION_LEAVE();
+
+       return ret;
+}
\ No newline at end of file
index 06e8653e9464ba128e58d77c4ff05c1f11048a45..82939f2fcbd6cbb8c41f6d14a528e046b7162a8f 100644 (file)
@@ -165,8 +165,6 @@ int ObjectDecoder::decode()
                                boxes.push_back(box);
                        }
                        boxList.push_back(boxes);
-               } else { // INFERENCE_BOX_DECODING_TYPE_YOLO_ANCHOR
-                       int cellIdx = idx * mBoxOffset;
                }
        }
 
index e062039a1a2ff4255105cebb0dd7eef0ba2973d3..26997e5f3673e29008215a1effb1a0f6dd76d5c3 100644 (file)
@@ -279,7 +279,7 @@ int perform_middlebury_test()
 
        const char* formats[] = {"pfm", "png"};
        int sel_fmt = -1;
-       while(sel_fmt <= 0 || sel_fmt > ARRAY_SIZE(formats)) {
+       while(sel_fmt <= 0 || sel_fmt > static_cast<int>(ARRAY_SIZE(formats))) {
                sel_fmt = show_menu_linear("Select Action", formats, ARRAY_SIZE(formats));
        }
 
@@ -328,9 +328,9 @@ int perform_middlebury_test()
                FILE* fp = fopen(calibFilename, "r");
                char line[MAX_STRING_LENGTH];
                float fVal;
-               float dmin, dmax;
+               float dmin = 0, dmax = 0;
                int iVal;
-               int width, height;
+               int width = 0, height = 0;
                if (fp != NULL) {
                        while (fgets(line, MAX_STRING_LENGTH, fp) != NULL) {
                                if (sscanf(line, "vmin= %f", &fVal) == 1) dmin = fVal;
@@ -528,7 +528,7 @@ int main()
        const char* names[] = {"Middlebury - TrainingQ(Imperf)"};
 
        int sel_opt = show_menu_linear("Select Action", names, ARRAY_SIZE(names));
-       if (sel_opt <= 0 || sel_opt > ARRAY_SIZE(names)) {
+       if (sel_opt <= 0 || sel_opt > static_cast<int>(ARRAY_SIZE(names))) {
                printf("Invalid option");
                return -1;
        }
index 4051ef5df7672d33ae6067c9ff0a0ec74450b462..1f43e46b5b889e822163405d02d2e61f5ace497e 100644 (file)
@@ -80,7 +80,6 @@ typedef struct _appdata
 } appdata;
 
 static float *vertex3d = NULL;
-static unsigned char *data_buffer_3d = NULL;
 mv_source_h mv_source3d;
 
 gulong handler;
@@ -144,7 +143,6 @@ static int minDisp;
 static int maxDisp;
 static int display_xpos;
 static int display_ypos;
-static int fidx = 0;
 void int_handler(int sig)
 {
        char c;
@@ -156,10 +154,6 @@ void int_handler(int sig)
        if (c == 'y' || c == 'Y') {
                g_signal_handler_disconnect(fsink, handler);
                printf("delete buffer, used by visualize 3d\n");
-               //if (data_buffer_3d != NULL) {
-               //      delete [] data_buffer_3d;
-               //      data_buffer_3d = NULL;
-               //}
 
                gst_element_send_event(pipecam, gst_event_new_eos());
                gst_element_send_event(pipedepth, gst_event_new_eos());
@@ -257,22 +251,6 @@ void WritePointCloud(const char* data_path,
 void _depth_stereo_cb(mv_source_h source, unsigned short *depth, unsigned int width,
                                          unsigned int height, void *user_data)
 {
-#if 0
-       if (!user_data) {
-               LOGW("user_data is null, Skip...");
-               return;
-       }
-
-       GstMapInfo *buffer = static_cast<GstMapInfo *>(user_data);
-
-
-       for (int j = 0; j < height; j++) {
-               for (int i = 0; i < width; ++i) {
-                       buffer->data[j * width + i] =
-                                       static_cast<unsigned short>(depth[j * width + i]);
-               }
-       }
-#endif
        double maxDepth = 2000.0;
        double minDepth = 175.0;
        double depthDenom = static_cast<double>(maxDepth - minDepth);
@@ -299,8 +277,8 @@ void _depth_stereo_cb(mv_source_h source, unsigned short *depth, unsigned int wi
                                                                false);
 
        cv::Mat colorMap = cv::Mat(cv::Size(width,height), CV_8UC1);
-       for (int j = 0; j < height; ++j) {
-               for (int i = 0; i < width; ++i) {
+       for (unsigned int j = 0; j < height; ++j) {
+               for (unsigned int i = 0; i < width; ++i) {
                        int idx = j * width + i;
                        int idxInv = width * height - idx - 1;
                        auto depth_raw = pcd->points_.data()[idx][2] * 1000.0;