mv3d: add MV_3D_POINTCLOUD_AVAILABLE macro
authorsangho park <sangho.g.park@samsung.com>
Wed, 21 Sep 2022 11:10:49 +0000 (20:10 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Thu, 22 Sep 2022 06:06:57 +0000 (15:06 +0900)
[Issue type] : supports pointcloud feature for aarch64 only

Change-Id: I32323b3e587f17b74d06fe1d2058f20084ebdaae
Signed-off-by: sangho park <sangho.g.park@samsung.com>
mv_3d/3d/CMakeLists.txt
mv_3d/3d/include/Mv3d.h
mv_3d/3d/src/Mv3d.cpp
mv_3d/3d/src/mv_3d_internal.cpp
mv_3d/3d/src/mv_3d_open.cpp
packaging/capi-media-vision.spec
test/testsuites/mv3d/CMakeLists.txt
test/testsuites/mv3d/depthstream_test_suite.cpp

index 2265cbd..5d2e81a 100644 (file)
@@ -10,12 +10,14 @@ if(NOT OpenCV_FOUND)
        return()
 endif()
 
-find_package(Open3D REQUIRED NO_POLICY_SCOPE)
-if(NOT Open3D_FOUND)
-       message(SEND_ERROR "Open3D NOT FOUND")
-       return()
-else()
-  include_directories(${Open3D_INCLUDE_DIRS})
+if(MV_3D_POINTCLOUD_IS_AVAILABLE)
+       find_package(Open3D REQUIRED NO_POLICY_SCOPE)
+       if(NOT Open3D_FOUND)
+               message(SEND_ERROR "Open3D NOT FOUND")
+               return()
+       else()
+               include_directories(${Open3D_INCLUDE_DIRS})
+       endif()
 endif()
 
 if(FORCED_STATIC_BUILD)
@@ -24,6 +26,10 @@ else()
        add_library(${PROJECT_NAME} SHARED ${MV_DFS_SOURCE_LIST})
 endif()
 
-target_link_libraries(${PROJECT_NAME} ${MV_COMMON_LIB_NAME} ${OpenCV_LIBS} ${Open3D_LIBRARIES} ${${PROJECT_NAME}_DEP_LIBRARIES})
+target_link_libraries(${PROJECT_NAME} ${MV_COMMON_LIB_NAME} ${OpenCV_LIBS} ${${PROJECT_NAME}_DEP_LIBRARIES})
+
+if(MV_3D_POINTCLOUD_IS_AVAILABLE)
+       target_link_libraries(${PROJECT_NAME} ${Open3D_LIBRARIES})
+endif()
 target_include_directories(${PROJECT_NAME} PRIVATE include)
 install(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
index 8e345a8..df04d92 100644 (file)
@@ -78,9 +78,11 @@ namespace mv3d
 
                static gpointer DfsThreadLoop(gpointer data);
 
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
                void GetPointcloudFromSource(DfsInputData &intput,
                                                                        DfsOutputData &depthData,
                                                                        mv_3d_pointcloud_s &pointcloud);
+#endif
        public:
                Mv3d();
                ~Mv3d();
@@ -95,7 +97,7 @@ namespace mv3d
 
                void SetDepthCallback(mv_3d_depth_cb depthCallback, void *depthUserData);
 
-               void SetPointcloudCallback(mv_3d_pointcloud_cb pointcloudCallback, void *pointcloudUserData);
+               int SetPointcloudCallback(mv_3d_pointcloud_cb pointcloudCallback, void *pointcloudUserData);
 
                int WritePointcloudFile(mv_3d_pointcloud_h pointcloud, mv_3d_pointcloud_type_e type, char *fileName);
 
index 747a786..521c947 100644 (file)
 #include <opencv2/core.hpp>
 #include <opencv2/imgcodecs.hpp>
 #include <opencv2/imgproc.hpp>
+
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
 #include <open3d/Open3D.h>
+using namespace open3d;
+#endif
 
 #include "Mv3d.h"
 
-using namespace open3d;
-
 namespace mediavision
 {
 namespace mv3d
@@ -51,7 +53,9 @@ namespace mv3d
                mDfsAsyncQueue(nullptr)
        {
                LOGI("ENTER");
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
                utility::SetVerbosityLevel(utility::VerbosityLevel::Debug);
+#endif
                LOGI("LEAVE");
        }
 
@@ -126,11 +130,23 @@ namespace mv3d
                mDepthUserData = depthUserData;
        }
 
-       void Mv3d::SetPointcloudCallback(mv_3d_pointcloud_cb pointcloudCallback, void *pointcloudUserData)
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
+       int Mv3d::SetPointcloudCallback(mv_3d_pointcloud_cb pointcloudCallback, void *pointcloudUserData)
        {
+               if (pointcloudCallback == NULL || pointcloudUserData == NULL)
+                       return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+
                mPointcloudCallback = pointcloudCallback;
                mPointcloudUserData = pointcloudUserData;
+
+               return MEDIA_VISION_ERROR_NONE;
        }
+#else
+       int Mv3d::SetPointcloudCallback(mv_3d_pointcloud_cb pointcloudCallback, void *pointcloudUserData)
+       {
+               return MEDIA_VISION_ERROR_NOT_SUPPORTED;
+       }
+#endif
 
        int Mv3d::Prepare()
        {
@@ -224,6 +240,7 @@ namespace mv3d
                }
        }
 
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
        void Mv3d::GetPointcloudFromSource(DfsInputData &input,
                                                                                DfsOutputData &depthData,
                                                                                mv_3d_pointcloud_s &pointcloud)
@@ -268,8 +285,8 @@ namespace mv3d
                pointcloud.pointcloud = static_cast<void*>(
                                        new std::shared_ptr<open3d::geometry::PointCloud>(
                                                std::move(pcd)));
-
        }
+#endif
 
        int Mv3d::Run(mv_source_h baseSource, mv_source_h extraSource)
        {
@@ -296,7 +313,7 @@ namespace mv3d
                                        static_cast<DepthTypePtr>(depthData.data),
                                        depthData.width, depthData.height,
                                        mDepthUserData);
-
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
                        if (mPointcloudCallback) {
                                mv_3d_pointcloud_s p = {.type = MV_3D_POINTCLOUD_TYPE_PCD_BIN, .pointcloud = NULL};
                                GetPointcloudFromSource(input, depthData, p);
@@ -309,6 +326,7 @@ namespace mv3d
                                auto _pcd = std::move(pPcd);
                                delete _pcd;
                        }
+#endif
                        delete [] static_cast<unsigned char*>(input.data);
                        delete [] static_cast<unsigned char*>(input.extraData);
                } catch (const std::exception &e) {
@@ -375,7 +393,7 @@ namespace mv3d
                                        static_cast<DepthTypePtr>(depthData.data),
                                        depthData.width, depthData.height,
                                        handle->mDepthUserData);
-
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
                        if (handle->mPointcloudCallback) {
                                mv_3d_pointcloud_s p = {.type = MV_3D_POINTCLOUD_TYPE_PCD_BIN, .pointcloud = NULL};
                                //mPointcloudThread = g_thread_new("pointcloud_thread",
@@ -391,7 +409,7 @@ namespace mv3d
                                auto _pcd = std::move(pPcd);
                                delete _pcd;
                        }
-
+#endif
                        delete [] static_cast<unsigned char*>(input->data);
                        delete [] static_cast<unsigned char*>(input->extraData);
                        input.reset();
@@ -402,6 +420,7 @@ namespace mv3d
 
        int Mv3d::WritePointcloudFile(mv_3d_pointcloud_h pointcloud, mv_3d_pointcloud_type_e type, char *fileName)
        {
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
                mv_3d_pointcloud_s *s = (mv_3d_pointcloud_s*) pointcloud;
                if (s == NULL) {
                        LOGE("Pointcloud data is NULL");
@@ -436,7 +455,9 @@ namespace mv3d
                        utility::LogError("Failed to write {}", fullPath.c_str());
                        return MEDIA_VISION_ERROR_INTERNAL;
                }
-
+#else
+       return MEDIA_VISION_ERROR_NOT_SUPPORTED;
+#endif
                return MEDIA_VISION_ERROR_NONE;
        }
 }
index 40b6237..95870f8 100644 (file)
@@ -15,7 +15,9 @@
  */
 
 #include <memory>
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
 #include <open3d/Open3D.h>
+#endif
 
 #include "mv_3d_internal.h"
 #include "mv_private.h"
 #define RANSAC_NUMBER 3
 #define NUM_ITERATIONS 1000
 
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
 using namespace open3d;
 using namespace mediavision::mv3d;
+#endif
 
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
 int mv_3d_pointcloud_plane_model_create(mv_3d_pointcloud_plane_model_h *handle)
 {
        MEDIA_VISION_NULL_ARG_CHECK(handle);
@@ -41,7 +46,14 @@ int mv_3d_pointcloud_plane_model_create(mv_3d_pointcloud_plane_model_h *handle)
 
        return MEDIA_VISION_ERROR_NONE;
 }
+#else
+int mv_3d_pointcloud_plane_model_create(mv_3d_pointcloud_plane_model_h *handle)
+{
+       return MEDIA_VISION_ERROR_NOT_SUPPORTED;
+}
+#endif
 
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
 int mv_3d_pointcloud_plane_model_destroy(mv_3d_pointcloud_plane_model_h handle)
 {
        MEDIA_VISION_INSTANCE_CHECK(handle);
@@ -55,7 +67,14 @@ int mv_3d_pointcloud_plane_model_destroy(mv_3d_pointcloud_plane_model_h handle)
 
        return MEDIA_VISION_ERROR_NONE;
 }
+#else
+int mv_3d_pointcloud_plane_model_destroy(mv_3d_pointcloud_plane_model_h handle)
+{
+       return MEDIA_VISION_ERROR_NOT_SUPPORTED;
+}
+#endif
 
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
 int mv_3d_pointcloud_plane_inlier_create(mv_3d_pointcloud_plane_inlier_h *handle)
 {
        MEDIA_VISION_NULL_ARG_CHECK(handle);
@@ -68,7 +87,14 @@ int mv_3d_pointcloud_plane_inlier_create(mv_3d_pointcloud_plane_inlier_h *handle
 
        return MEDIA_VISION_ERROR_NONE;
 }
+#else
+int mv_3d_pointcloud_plane_inlier_create(mv_3d_pointcloud_plane_inlier_h *handle)
+{
+       return MEDIA_VISION_ERROR_NOT_SUPPORTED;
+}
+#endif
 
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
 int mv_3d_pointcloud_plane_inlier_destroy(mv_3d_pointcloud_plane_inlier_h handle)
 {
        MEDIA_VISION_INSTANCE_CHECK(handle);
@@ -82,17 +108,20 @@ int mv_3d_pointcloud_plane_inlier_destroy(mv_3d_pointcloud_plane_inlier_h handle
 
        return MEDIA_VISION_ERROR_NONE;
 }
+#else
+int mv_3d_pointcloud_plane_inlier_destroy(mv_3d_pointcloud_plane_inlier_h handle)
+{
+       return MEDIA_VISION_ERROR_NOT_SUPPORTED;
+}
+#endif
 
-/**
- * @file mv_3d_internal.c
- * @brief This file contains Media Vision 3D internal module.
- */
-
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
 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);
@@ -114,7 +143,17 @@ int mv_3d_pointcloud_segment_plane(mv_3d_h mv3d,
 
        return MEDIA_VISION_ERROR_NONE;
 }
+#else
+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)
+{
+       return MEDIA_VISION_ERROR_NOT_SUPPORTED;
+}
+#endif
 
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
 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,
@@ -150,4 +189,15 @@ int mv_3d_pointcloud_plane_write_file(mv_3d_h mv3d,
        MEDIA_VISION_FUNCTION_LEAVE();
 
        return ret;
-}
\ No newline at end of file
+}
+#else
+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)
+{
+       return MEDIA_VISION_ERROR_NOT_SUPPORTED;
+}
+#endif
index 9f914d2..72021a2 100644 (file)
@@ -240,7 +240,11 @@ int mv3dSetPointcloudCallback(mv_3d_h mv3d, mv_3d_pointcloud_cb pointcloud_cb, v
        }
 
        auto pMv3d = static_cast<Mv3d *>(mv3d);
-       pMv3d->SetPointcloudCallback(pointcloud_cb, user_data);
+       int ret = pMv3d->SetPointcloudCallback(pointcloud_cb, user_data);
+       if (ret != MEDIA_VISION_ERROR_NONE) {
+               LOGE("Failed to run depth");
+               return ret;
+       }
 
        LOGI("LEAVE");
        return MEDIA_VISION_ERROR_NONE;
index 5853507..36761cc 100644 (file)
@@ -33,7 +33,9 @@ BuildRequires: pkgconfig(wayland-egl)
 BuildRequires: pkgconfig(glesv2)
 BuildRequires: gtest-devel
 BuildRequires: pkgconfig(dfs-adaptation)
+%ifarch aarch64
 BuildRequires: Open3D-devel
+%endif
 %if 0%{?visualizer:1}
 BuildRequires: pkgconfig(protobuf)
 BuildRequires: pkgconfig(grpc++)
@@ -271,6 +273,9 @@ export LDFLAGS+=" -lgcov"
 %endif
 
 %cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo %{build_options} \
+%ifarch aarch64
+-DMMV_3D_POINTCLOUD_IS_AVAILABLE=TRUE \
+%endif
 %if 0%{?ml_only:1}
  -DBUILD_ML_ONLY=ON \
 %endif
index 8509a3d..47a1378 100644 (file)
@@ -3,16 +3,18 @@ cmake_minimum_required(VERSION 2.6...3.13)
 
 find_package(OpenCV REQUIRED core videoio imgcodecs)
 if(NOT OpenCV_FOUND)
-       message(SEND_ERROR "OpenCV NOT FOUND")
-       return()
+  message(SEND_ERROR "OpenCV NOT FOUND")
+  return()
 endif()
 
-find_package(Open3D REQUIRED NO_POLICY_SCOPE)
-if(NOT Open3D_FOUND)
-       message(SEND_ERROR "Open3D NOT FOUND")
-       return()
-else()
-  include_directories(${Open3D_INCLUDE_DIRS})
+if(MV_3D_POINTCLOUD_IS_AVAILABLE)
+  find_package(Open3D REQUIRED NO_POLICY_SCOPE)
+  if(NOT Open3D_FOUND)
+    message(SEND_ERROR "Open3D NOT FOUND")
+    return()
+  else()
+    include_directories(${Open3D_INCLUDE_DIRS})
+  endif()
 endif()
 
 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format-truncation")
index 1f43e46..c8241b9 100644 (file)
@@ -25,7 +25,9 @@
 #include <opencv2/core.hpp>
 #include <opencv2/imgcodecs.hpp>
 #include <opencv2/imgproc.hpp>
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
 #include <open3d/Open3D.h>
+#endif
 
 #include <mv_log_cfg.h>
 #include <mv_common.h>
@@ -46,7 +48,9 @@
 #define MAX_FRAMES 1800 // 30 fps * 60s
 
 #define INTRINSIC_FILE_PATH "/usr/share/capi-media-vision/stereoCalibZedVGA.json"
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
 using namespace open3d;
+#endif
 
 class StopWatch
 {
@@ -208,6 +212,7 @@ static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data)
        return TRUE;
 }
 
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
 void WritePointCloud(const char* data_path,
                                        const char* color_filename,
                                        const char* depth_filename,
@@ -247,10 +252,12 @@ void WritePointCloud(const char* data_path,
                utility::LogError("Failed to write {}", filename_ply);
        }
 }
+#endif
 
 void _depth_stereo_cb(mv_source_h source, unsigned short *depth, unsigned int width,
                                          unsigned int height, void *user_data)
 {
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
        double maxDepth = 2000.0;
        double minDepth = 175.0;
        double depthDenom = static_cast<double>(maxDepth - minDepth);
@@ -325,6 +332,7 @@ void _depth_stereo_cb(mv_source_h source, unsigned short *depth, unsigned int wi
        delete [] vertex3d;
        vertex3d = NULL;
        __signal();
+#endif
 }
 
 static void stereo_handoff(GstElement *object, GstBuffer *buffer, GstPad *pad,
@@ -479,8 +487,9 @@ int main(int argc, char *argv[])
                display_xpos = atoi(argv[7]);
                display_ypos = atoi(argv[8]);
        }
-
+#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
        utility::SetVerbosityLevel(utility::VerbosityLevel::Debug);
+#endif
 
        SrcData srcData;
        int ret = MEDIA_VISION_ERROR_NONE;