From 79c1c15ac88bbd2e3c5c5105520b90cd81cf3b13 Mon Sep 17 00:00:00 2001 From: sangho park Date: Wed, 21 Sep 2022 20:10:49 +0900 Subject: [PATCH 01/16] mv3d: add MV_3D_POINTCLOUD_AVAILABLE macro [Issue type] : supports pointcloud feature for aarch64 only Change-Id: I32323b3e587f17b74d06fe1d2058f20084ebdaae Signed-off-by: sangho park --- mv_3d/3d/CMakeLists.txt | 20 +++++--- mv_3d/3d/include/Mv3d.h | 4 +- mv_3d/3d/src/Mv3d.cpp | 37 +++++++++++---- mv_3d/3d/src/mv_3d_internal.cpp | 62 ++++++++++++++++++++++--- mv_3d/3d/src/mv_3d_open.cpp | 6 ++- packaging/capi-media-vision.spec | 5 ++ test/testsuites/mv3d/CMakeLists.txt | 18 +++---- test/testsuites/mv3d/depthstream_test_suite.cpp | 11 ++++- 8 files changed, 131 insertions(+), 32 deletions(-) diff --git a/mv_3d/3d/CMakeLists.txt b/mv_3d/3d/CMakeLists.txt index 2265cbd..5d2e81a 100644 --- a/mv_3d/3d/CMakeLists.txt +++ b/mv_3d/3d/CMakeLists.txt @@ -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}) diff --git a/mv_3d/3d/include/Mv3d.h b/mv_3d/3d/include/Mv3d.h index 8e345a8..df04d92 100644 --- a/mv_3d/3d/include/Mv3d.h +++ b/mv_3d/3d/include/Mv3d.h @@ -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); diff --git a/mv_3d/3d/src/Mv3d.cpp b/mv_3d/3d/src/Mv3d.cpp index 747a786..521c947 100644 --- a/mv_3d/3d/src/Mv3d.cpp +++ b/mv_3d/3d/src/Mv3d.cpp @@ -21,12 +21,14 @@ #include #include #include + +#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE #include +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( new std::shared_ptr( std::move(pcd))); - } +#endif int Mv3d::Run(mv_source_h baseSource, mv_source_h extraSource) { @@ -296,7 +313,7 @@ namespace mv3d static_cast(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(input.data); delete [] static_cast(input.extraData); } catch (const std::exception &e) { @@ -375,7 +393,7 @@ namespace mv3d static_cast(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(input->data); delete [] static_cast(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; } } diff --git a/mv_3d/3d/src/mv_3d_internal.cpp b/mv_3d/3d/src/mv_3d_internal.cpp index 40b6237..95870f8 100644 --- a/mv_3d/3d/src/mv_3d_internal.cpp +++ b/mv_3d/3d/src/mv_3d_internal.cpp @@ -15,7 +15,9 @@ */ #include +#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE #include +#endif #include "mv_3d_internal.h" #include "mv_private.h" @@ -26,9 +28,12 @@ #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 diff --git a/mv_3d/3d/src/mv_3d_open.cpp b/mv_3d/3d/src/mv_3d_open.cpp index 9f914d2..72021a2 100644 --- a/mv_3d/3d/src/mv_3d_open.cpp +++ b/mv_3d/3d/src/mv_3d_open.cpp @@ -240,7 +240,11 @@ int mv3dSetPointcloudCallback(mv_3d_h mv3d, mv_3d_pointcloud_cb pointcloud_cb, v } auto pMv3d = static_cast(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; diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 5853507..36761cc 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -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 diff --git a/test/testsuites/mv3d/CMakeLists.txt b/test/testsuites/mv3d/CMakeLists.txt index 8509a3d..47a1378 100644 --- a/test/testsuites/mv3d/CMakeLists.txt +++ b/test/testsuites/mv3d/CMakeLists.txt @@ -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") diff --git a/test/testsuites/mv3d/depthstream_test_suite.cpp b/test/testsuites/mv3d/depthstream_test_suite.cpp index 1f43e46..c8241b9 100644 --- a/test/testsuites/mv3d/depthstream_test_suite.cpp +++ b/test/testsuites/mv3d/depthstream_test_suite.cpp @@ -25,7 +25,9 @@ #include #include #include +#ifdef MV_3D_POINTCLOUD_IS_AVAILABLE #include +#endif #include #include @@ -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(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; -- 2.7.4 From 45c929981cd3a4c02d9f4b2765dda362a9cf5e31 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Thu, 22 Sep 2022 13:21:45 +0900 Subject: [PATCH 02/16] mv3d: fix a bug using nullptr [Issue type] : bug fix (SVACE: WGID 499264) mDepthCallback uses deallocated memory of the variable 'base'. It should be mv_source_h of a left image. With dfs-adaptation change, ``` commit 1607630a5887d961cd71d0e9663e9945d70fc3ae Author: Tae-Young Chung Date: Thu Sep 22 13:19:04 2022 +0900 Add getLeftData() and getRigthData() [Version] 1.0.9-0 [Issue type] update ``` getLeftData() returns the pointer of a left image and the returned pointer is used to fill mv_source_h. Change-Id: I89af7686e485a102bc444720583bf26739e08809 --- mv_3d/3d/include/Mv3d.h | 2 ++ mv_3d/3d/src/Mv3d.cpp | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/mv_3d/3d/include/Mv3d.h b/mv_3d/3d/include/Mv3d.h index df04d92..8f3558c 100644 --- a/mv_3d/3d/include/Mv3d.h +++ b/mv_3d/3d/include/Mv3d.h @@ -65,6 +65,8 @@ namespace mv3d GAsyncQueue *mDfsAsyncQueue; + mv_source_h mInternalSource; + void GetBufferFromSource(mv_source_h source, unsigned char*& buffer, unsigned int& width, diff --git a/mv_3d/3d/src/Mv3d.cpp b/mv_3d/3d/src/Mv3d.cpp index 521c947..dc4c05c 100644 --- a/mv_3d/3d/src/Mv3d.cpp +++ b/mv_3d/3d/src/Mv3d.cpp @@ -50,7 +50,8 @@ namespace mv3d mDepthCallback(nullptr), mPointcloudCallback(nullptr), mDfsIsLive(false), - mDfsAsyncQueue(nullptr) + mDfsAsyncQueue(nullptr), + mInternalSource(nullptr) { LOGI("ENTER"); #ifdef MV_3D_POINTCLOUD_IS_AVAILABLE @@ -77,6 +78,11 @@ namespace mv3d delete mDfsAdaptor; } + if (mInternalSource) { + mv_destroy_source(mInternalSource); + mInternalSource = nullptr; + } + LOGI("LEAVE"); } @@ -303,6 +309,14 @@ namespace mv3d mDfsAsyncQueue = nullptr; } + if (mInternalSource) { + int ret = mv_destroy_source(mInternalSource); + if (ret != MEDIA_VISION_ERROR_NONE) { + LOGE("Fail to destroy intern source. But keep going.."); + } + mInternalSource = nullptr; + } + GetDfsDataFromSources(baseSource, extraSource, input); mDfsAdaptor->run(input); @@ -362,6 +376,13 @@ namespace mv3d std::shared_ptr input(new DfsInputData); GetDfsDataFromSources(baseSource, extraSource, *input); + if (!mInternalSource) { + int ret = mv_create_source(&mInternalSource); + if (ret != MEDIA_VISION_ERROR_NONE) { + LOGE("Fail to create internal source"); + return MEDIA_VISION_ERROR_INTERNAL; + } + } g_async_queue_push(mDfsAsyncQueue, static_cast( new std::shared_ptr( std::move(input)))); @@ -388,8 +409,16 @@ namespace mv3d handle->mDfsAdaptor->run(*input); auto depthData = handle->mDfsAdaptor->getOutputData(); + auto leftData = handle->mDfsAdaptor->getLeftData(); + mv_source_fill_by_buffer(handle->mInternalSource, + static_cast(leftData.data), + leftData.width, + leftData.height, + leftData.stride * leftData.height, + leftData.type == DFS_DATA_TYPE_UINT8C3 ? MEDIA_VISION_COLORSPACE_RGB888 : + MEDIA_VISION_COLORSPACE_Y800); handle->mDepthCallback( - static_cast(base), + static_cast(handle->mInternalSource), static_cast(depthData.data), depthData.width, depthData.height, handle->mDepthUserData); @@ -402,7 +431,7 @@ namespace mv3d handle->GetPointcloudFromSource(*input, depthData, p); mv_3d_pointcloud_h pcd = &p; - handle->mPointcloudCallback(static_cast(base), + handle->mPointcloudCallback(static_cast(mInternalSource), pcd, handle->mPointcloudUserData); auto pPcd = static_cast*>(p.pointcloud); @@ -412,6 +441,7 @@ namespace mv3d #endif delete [] static_cast(input->data); delete [] static_cast(input->extraData); + mv_source_clear(handle->mInternalSource); input.reset(); } -- 2.7.4 From 8cf7ba9a6489688f4502ba77b047e5fe86188b0e Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Thu, 22 Sep 2022 14:24:48 +0900 Subject: [PATCH 03/16] mv3d: fix bugs [Issue type] : bug fix (SVACE: WGID 499255,499256,499263,499267) 499255: fix flcose() with nullptr 499256: fix delete operation with malloc() 499263: fix assignment of a signed integer value to a bigger size_t 499267: fix memory leak of suffix_for_algo Change-Id: I415baa95286527007e3b8aff8befd218ebe0a09b Signed-off-by: Tae-Young Chung --- mv_3d/3d/include/Mv3d.h | 4 ++-- mv_3d/3d/src/Mv3d.cpp | 4 ++-- mv_3d/3d/src/mv_3d_open.cpp | 5 +++++ test/testsuites/mv3d/depth_test_suite.cpp | 8 +++++++- test/testsuites/mv3d/depthstream_test_suite.cpp | 2 +- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/mv_3d/3d/include/Mv3d.h b/mv_3d/3d/include/Mv3d.h index 8f3558c..3614cea 100644 --- a/mv_3d/3d/include/Mv3d.h +++ b/mv_3d/3d/include/Mv3d.h @@ -47,8 +47,8 @@ namespace mv3d size_t mWidth; size_t mHeight; - size_t mMinDisp; - size_t mMaxDisp; + int mMinDisp; + int mMaxDisp; double mSamplingRatio; int mOutlierRemovalPoints; double mOutlierRemovalRadius; diff --git a/mv_3d/3d/src/Mv3d.cpp b/mv_3d/3d/src/Mv3d.cpp index dc4c05c..258307a 100644 --- a/mv_3d/3d/src/Mv3d.cpp +++ b/mv_3d/3d/src/Mv3d.cpp @@ -104,8 +104,8 @@ namespace mv3d std::string pointcloudOutputPath) { mMode = mode; - mWidth = width; - mHeight = height; + mWidth = static_cast(width); + mHeight = static_cast(height); mMinDisp = minDisp; mMaxDisp = maxDisp; mSamplingRatio = samplingRatio; diff --git a/mv_3d/3d/src/mv_3d_open.cpp b/mv_3d/3d/src/mv_3d_open.cpp index 72021a2..24d2189 100644 --- a/mv_3d/3d/src/mv_3d_open.cpp +++ b/mv_3d/3d/src/mv_3d_open.cpp @@ -115,6 +115,11 @@ int mv3dConfigure(mv_3d_h mv3d, mv_engine_config_h engine_config) return ret; } + if (depthWidth <= 0 || depthHeight <= 0) { + LOGE("Invalid depth resolution %d x %d", depthWidth, depthHeight); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + ret = mv_engine_config_get_int_attribute( engine_config, MV_3D_DEPTH_MIN_DISPARITY, &minDisp); if (ret != MEDIA_VISION_ERROR_NONE) { diff --git a/test/testsuites/mv3d/depth_test_suite.cpp b/test/testsuites/mv3d/depth_test_suite.cpp index 26997e5..bee2201 100644 --- a/test/testsuites/mv3d/depth_test_suite.cpp +++ b/test/testsuites/mv3d/depth_test_suite.cpp @@ -338,8 +338,11 @@ int perform_middlebury_test() if (sscanf(line, "width= %d", &iVal) == 1) width = iVal; if (sscanf(line, "height= %d", &iVal) == 1) height = iVal; } + fclose(fp); + } else { + printf("Fail to open %s\n", calibFilename); + goto _err; } - fclose(fp); int minDisp = static_cast(dmin); int maxDisp = static_cast(dmax); @@ -507,6 +510,9 @@ _err: if (path_to_dataset) free(path_to_dataset); + if (suffix_for_algo) + free(suffix_for_algo); + if (engine_config) mv_destroy_engine_config(engine_config); diff --git a/test/testsuites/mv3d/depthstream_test_suite.cpp b/test/testsuites/mv3d/depthstream_test_suite.cpp index c8241b9..16a4d4e 100644 --- a/test/testsuites/mv3d/depthstream_test_suite.cpp +++ b/test/testsuites/mv3d/depthstream_test_suite.cpp @@ -265,7 +265,7 @@ void _depth_stereo_cb(mv_source_h source, unsigned short *depth, unsigned int wi camera::PinholeCameraIntrinsic intrinsic; io::ReadIJsonConvertible(INTRINSIC_FILE_PATH, intrinsic); - vertex3d = (float *)malloc(width * height * 4); + vertex3d = new float[width * height * 4]; memset(vertex3d, 0, width * height * 4); utility::LogInfo("focal_x = {}", intrinsic.GetFocalLength().first); utility::LogInfo("focal_y = {}", intrinsic.GetFocalLength().second); -- 2.7.4 From 13ecaa7e6b95fda4c5c9fe4223120560cc7c6669 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Thu, 22 Sep 2022 16:49:08 +0900 Subject: [PATCH 04/16] mv3d: fix bugs wrong lib name in CMakeLists.txt [Issue type] : bug fix Change-Id: Ica7aa7c43f0c49bb685c5a4e93989f9ea28ea5fd Signed-off-by: Tae-Young Chung --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75065a2..9bedda5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,7 +137,7 @@ configure_file( install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}-surveillance.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) set(PC_NAME ${fw_name}-3d) -set(PC_LDFLAGS "-l${MV_DEPTH_LIB_NAME} -l${MV_COMMON_LIB_NAME}") +set(PC_LDFLAGS "-l${MV_3D_LIB_NAME} -l${MV_COMMON_LIB_NAME}") configure_file( ${fw_name}.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}-3d.pc -- 2.7.4 From 530f5ba836a60cf9d4dfb224790b2f13670c87ca Mon Sep 17 00:00:00 2001 From: Inki Dae Date: Tue, 27 Sep 2022 11:19:02 +0900 Subject: [PATCH 05/16] mv_machine_learning: fix coverity issue [Version] : 0.23.26-0 [Issue type] : bug fix Fixed a coverity issue by handling an error value correctly. Change-Id: Icce85a27e2be29f38799a4f312d40978d60e59eb Signed-off-by: Inki Dae --- mv_machine_learning/inference/src/Inference.cpp | 8 ++++++-- packaging/capi-media-vision.spec | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mv_machine_learning/inference/src/Inference.cpp b/mv_machine_learning/inference/src/Inference.cpp index 9f3b25c..18f6544 100644 --- a/mv_machine_learning/inference/src/Inference.cpp +++ b/mv_machine_learning/inference/src/Inference.cpp @@ -810,7 +810,11 @@ int Inference::Preprocess(std::vector &mv_sources, std::vector &mv_sources, std::vector Date: Tue, 27 Sep 2022 12:42:43 +0900 Subject: [PATCH 06/16] mv_3d: fix coverity issue [Version] : 0.23.27-0 [Issue type] : bug fix fix coverity DefectId 1612133 (resource leak) Change-Id: I8a8b9a0783db79f3695dc637445dfe62d0b2ea92 Signed-off-by: sangho park --- mv_3d/3d/src/mv_3d_open.cpp | 42 +++++++++++++++++----------------------- packaging/capi-media-vision.spec | 2 +- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/mv_3d/3d/src/mv_3d_open.cpp b/mv_3d/3d/src/mv_3d_open.cpp index 24d2189..0319351 100644 --- a/mv_3d/3d/src/mv_3d_open.cpp +++ b/mv_3d/3d/src/mv_3d_open.cpp @@ -80,6 +80,7 @@ int mv3dConfigure(mv_3d_h mv3d, mv_engine_config_h engine_config) { LOGI("ENTER"); + Mv3d *pMv3d = NULL; if (!mv3d || !engine_config) { LOGE("Handle is NULL"); return MEDIA_VISION_ERROR_INVALID_PARAMETER; @@ -134,18 +135,6 @@ int mv3dConfigure(mv_3d_h mv3d, mv_engine_config_h engine_config) return ret; } - char *stereoConfigFilePath = NULL; - ret = mv_engine_config_get_string_attribute( - engine_config, MV_3D_DEPTH_STEREO_CONFIG_FILE_PATH, &stereoConfigFilePath); - if (ret != MEDIA_VISION_ERROR_NONE) { - LOGE("Failed to get stereo configuration file path"); - if (stereoConfigFilePath) { - free(stereoConfigFilePath); - stereoConfigFilePath = NULL; - } - return ret; - } - double samplingRatio; ret = mv_engine_config_get_double_attribute( engine_config, MV_3D_POINTCLOUD_SAMPLING_RATIO,&samplingRatio); @@ -170,36 +159,41 @@ int mv3dConfigure(mv_3d_h mv3d, mv_engine_config_h engine_config) return ret; } + char *stereoConfigFilePath = NULL; + ret = mv_engine_config_get_string_attribute( + engine_config, MV_3D_DEPTH_STEREO_CONFIG_FILE_PATH, &stereoConfigFilePath); + if (ret != MEDIA_VISION_ERROR_NONE) { + LOGE("Failed to get stereo configuration file path"); + return ret; + } + char *pointcloudOutputFilePath = NULL; ret = mv_engine_config_get_string_attribute( engine_config, MV_3D_POINTCLOUD_OUTPUT_FILE_PATH, &pointcloudOutputFilePath); if (ret != MEDIA_VISION_ERROR_NONE) { LOGE("Failed to get stereo configuration file path"); - if (pointcloudOutputFilePath) { - free(pointcloudOutputFilePath); - pointcloudOutputFilePath = NULL; - } - return ret; + goto out; } - auto pMv3d = static_cast(mv3d); + pMv3d = static_cast(mv3d); ret = pMv3d->Configure(mode, depthWidth, depthHeight, minDisp, maxDisp, samplingRatio, outlierRemovalPoints, outlierRemovalRadius, stereoConfigFilePath, pointcloudOutputFilePath); - if (stereoConfigFilePath) { - free(stereoConfigFilePath); - stereoConfigFilePath = NULL; + if (ret != MEDIA_VISION_ERROR_NONE) { + LOGE("Failed to configure Depth"); + goto out; } +out: if (pointcloudOutputFilePath) { free(pointcloudOutputFilePath); pointcloudOutputFilePath = NULL; } - if (ret != MEDIA_VISION_ERROR_NONE) { - LOGE("Failed to configure Depth"); - return ret; + if (stereoConfigFilePath) { + free(stereoConfigFilePath); + stereoConfigFilePath = NULL; } LOGI("LEAVE"); diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 3e53cfe..fdb9d02 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -1,6 +1,6 @@ Name: capi-media-vision Summary: Media Vision library for Tizen Native API -Version: 0.23.26 +Version: 0.23.27 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause -- 2.7.4 From b3b01a043ca3897180319cea107e6ba101ae0570 Mon Sep 17 00:00:00 2001 From: sangho park Date: Tue, 27 Sep 2022 12:49:37 +0900 Subject: [PATCH 07/16] mv_3d: fix coverity issue [Version] : 0.23.28-0 [Issue type] : bug fix fix coverity DefectId 1612132, 1612134, 1612135 (Unchecked return value) Change-Id: Ib618ab460996f40572e8084b743954eb7fad20c1 Signed-off-by: sangho park --- mv_3d/3d/src/Mv3d.cpp | 8 ++++++-- packaging/capi-media-vision.spec | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mv_3d/3d/src/Mv3d.cpp b/mv_3d/3d/src/Mv3d.cpp index 258307a..b63ad9a 100644 --- a/mv_3d/3d/src/Mv3d.cpp +++ b/mv_3d/3d/src/Mv3d.cpp @@ -410,13 +410,17 @@ namespace mv3d auto depthData = handle->mDfsAdaptor->getOutputData(); auto leftData = handle->mDfsAdaptor->getLeftData(); - mv_source_fill_by_buffer(handle->mInternalSource, + int ret = mv_source_fill_by_buffer(handle->mInternalSource, static_cast(leftData.data), leftData.width, leftData.height, leftData.stride * leftData.height, leftData.type == DFS_DATA_TYPE_UINT8C3 ? MEDIA_VISION_COLORSPACE_RGB888 : MEDIA_VISION_COLORSPACE_Y800); + if (MEDIA_VISION_ERROR_NONE != ret) { + LOGW("Errors were occurred during source filling %i", ret); + continue; + } handle->mDepthCallback( static_cast(handle->mInternalSource), static_cast(depthData.data), @@ -431,7 +435,7 @@ namespace mv3d handle->GetPointcloudFromSource(*input, depthData, p); mv_3d_pointcloud_h pcd = &p; - handle->mPointcloudCallback(static_cast(mInternalSource), + handle->mPointcloudCallback(static_cast(handle->mInternalSource), pcd, handle->mPointcloudUserData); auto pPcd = static_cast*>(p.pointcloud); diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index fdb9d02..bcc2f5d 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -1,6 +1,6 @@ Name: capi-media-vision Summary: Media Vision library for Tizen Native API -Version: 0.23.27 +Version: 0.23.28 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause -- 2.7.4 From 17462e7ea83766a479e5f12e4d295fb631eb38a6 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Tue, 27 Sep 2022 13:57:53 +0900 Subject: [PATCH 08/16] mv_3d: fix svace issue (SIGNED_TO_BIGGER_UNSIGNED) [Version] : 0.23.29-0 [Issue type] : bug fix fix svace wgid 499263 Change-Id: Iea3cf1342f2b1b090d3fef626e26898e65a0c631 --- mv_3d/3d/include/Mv3d.h | 2 +- mv_3d/3d/src/Mv3d.cpp | 2 +- mv_3d/3d/src/mv_3d_open.cpp | 12 +++++++++--- packaging/capi-media-vision.spec | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/mv_3d/3d/include/Mv3d.h b/mv_3d/3d/include/Mv3d.h index 3614cea..eea895b 100644 --- a/mv_3d/3d/include/Mv3d.h +++ b/mv_3d/3d/include/Mv3d.h @@ -93,7 +93,7 @@ namespace mv3d size_t windowHeight, size_t speckleSize); - int Configure(int mode, int width, int height, int minDisp, int maxDisp, + int Configure(int mode, unsigned int width, unsigned int height, int minDisp, int maxDisp, double samplingRatio, int outlierRemovalPoints, double outlierRemovalRadius, std::string stereoConfigPath, std::string pointcloudOutputPath); diff --git a/mv_3d/3d/src/Mv3d.cpp b/mv_3d/3d/src/Mv3d.cpp index b63ad9a..9982635 100644 --- a/mv_3d/3d/src/Mv3d.cpp +++ b/mv_3d/3d/src/Mv3d.cpp @@ -97,7 +97,7 @@ namespace mv3d mDfsParameter.maxSpeckleSize = speckleSize; } - int Mv3d::Configure(int mode, int width, int height, + int Mv3d::Configure(int mode, unsigned int width, unsigned int height, int minDisp, int maxDisp, double samplingRatio, int outlierRemovalPoints, double outlierRemovalRadius, std::string stereoConfigPath, diff --git a/mv_3d/3d/src/mv_3d_open.cpp b/mv_3d/3d/src/mv_3d_open.cpp index 0319351..4c09f60 100644 --- a/mv_3d/3d/src/mv_3d_open.cpp +++ b/mv_3d/3d/src/mv_3d_open.cpp @@ -176,9 +176,15 @@ int mv3dConfigure(mv_3d_h mv3d, mv_engine_config_h engine_config) } pMv3d = static_cast(mv3d); - ret = pMv3d->Configure(mode, depthWidth, depthHeight, minDisp, maxDisp, - samplingRatio, outlierRemovalPoints, outlierRemovalRadius, - stereoConfigFilePath, pointcloudOutputFilePath); + ret = pMv3d->Configure(mode, + static_cast(depthWidth), + static_cast(depthHeight), + minDisp, maxDisp, + samplingRatio, + outlierRemovalPoints, + outlierRemovalRadius, + stereoConfigFilePath, + pointcloudOutputFilePath); if (ret != MEDIA_VISION_ERROR_NONE) { LOGE("Failed to configure Depth"); diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index bcc2f5d..4b02bd8 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -1,6 +1,6 @@ Name: capi-media-vision Summary: Media Vision library for Tizen Native API -Version: 0.23.28 +Version: 0.23.29 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause -- 2.7.4 From 74436d78c4f228cc7bc05de6e583a5bf65003406 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Tue, 27 Sep 2022 17:14:38 +0900 Subject: [PATCH 09/16] Check new vision.3d features [Version] : 0.23.29-0 [Issue type] : update According to ACR-1720, new features, vision.3d, vision.3d.depth, vision.3d.pointcloud, are added. Change-Id: I02ff894588cd20ff11039a80cf9fcd91cada602f Signed-off-by: Tae-Young Chung --- include/mv_private.h | 4 +++ mv_3d/3d/src/mv_3d.c | 12 +++++++++ mv_common/src/mv_private.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/include/mv_private.h b/include/mv_private.h index 49eb3aa..94c5a7b 100644 --- a/include/mv_private.h +++ b/include/mv_private.h @@ -69,6 +69,10 @@ bool _mv_inference_check_system_info_feature_supported(void); bool _mv_inference_image_check_system_info_feature_supported(void); bool _mv_inference_face_check_system_info_feature_supported(void); bool _mv_roi_tracking_check_system_info_feature_supported(void); +bool _mv_3d_all_check_system_info_feature_supported(void); +bool _mv_3d_check_system_info_feature_supported(void); +bool _mv_3d_depth_check_system_info_feature_supported(void); +bool _mv_3d_pointcloud_check_system_info_feature_supported(void); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/mv_3d/3d/src/mv_3d.c b/mv_3d/3d/src/mv_3d.c index c640e13..27ea242 100644 --- a/mv_3d/3d/src/mv_3d.c +++ b/mv_3d/3d/src/mv_3d.c @@ -26,6 +26,7 @@ int mv_3d_create(mv_3d_h *mv3d) { + MEDIA_VISION_SUPPORT_CHECK(_mv_3d_all_check_system_info_feature_supported()); MEDIA_VISION_NULL_ARG_CHECK(mv3d); MEDIA_VISION_FUNCTION_ENTER(); @@ -39,6 +40,7 @@ int mv_3d_create(mv_3d_h *mv3d) int mv_3d_destroy(mv_3d_h mv3d) { + MEDIA_VISION_SUPPORT_CHECK(_mv_3d_all_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(mv3d); MEDIA_VISION_FUNCTION_ENTER(); @@ -53,6 +55,7 @@ int mv_3d_destroy(mv_3d_h mv3d) int mv_3d_configure(mv_3d_h mv3d, mv_engine_config_h engine_config) { + MEDIA_VISION_SUPPORT_CHECK(_mv_3d_all_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(mv3d); MEDIA_VISION_INSTANCE_CHECK(engine_config); @@ -69,6 +72,8 @@ int mv_3d_set_depth_cb(mv_3d_h mv3d, mv_3d_depth_cb depth_cb, void *user_data) { + MEDIA_VISION_SUPPORT_CHECK(_mv_3d_depth_check_system_info_feature_supported() || + _mv_3d_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(mv3d); MEDIA_VISION_NULL_ARG_CHECK(depth_cb); @@ -86,6 +91,8 @@ int mv_3d_set_pointcloud_cb(mv_3d_h mv3d, mv_3d_pointcloud_cb pointcloud_cb, void *user_data) { + MEDIA_VISION_SUPPORT_CHECK(_mv_3d_pointcloud_check_system_info_feature_supported() || + _mv_3d_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(mv3d); MEDIA_VISION_NULL_ARG_CHECK(pointcloud_cb); @@ -101,6 +108,7 @@ int mv_3d_set_pointcloud_cb(mv_3d_h mv3d, int mv_3d_prepare(mv_3d_h mv3d) { + MEDIA_VISION_SUPPORT_CHECK(_mv_3d_all_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(mv3d); MEDIA_VISION_FUNCTION_ENTER(); @@ -117,6 +125,7 @@ int mv_3d_run(mv_3d_h mv3d, mv_source_h source_extra, mv_source_h color) { + MEDIA_VISION_SUPPORT_CHECK(_mv_3d_all_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(mv3d); MEDIA_VISION_INSTANCE_CHECK(source); @@ -136,6 +145,7 @@ int mv_3d_run_async(mv_3d_h mv3d, mv_source_h source_extra, mv_source_h color) { + MEDIA_VISION_SUPPORT_CHECK(_mv_3d_all_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(mv3d); MEDIA_VISION_INSTANCE_CHECK(source); @@ -155,6 +165,8 @@ int mv_3d_pointcloud_write_file(mv_3d_h mv3d, mv_3d_pointcloud_type_e type, char *filename) { + MEDIA_VISION_SUPPORT_CHECK(_mv_3d_pointcloud_check_system_info_feature_supported() || + _mv_3d_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(mv3d); MEDIA_VISION_INSTANCE_CHECK(pointcloud); diff --git a/mv_common/src/mv_private.c b/mv_common/src/mv_private.c index 84be33a..f6dc75a 100644 --- a/mv_common/src/mv_private.c +++ b/mv_common/src/mv_private.c @@ -259,3 +259,70 @@ bool _mv_roi_tracking_check_system_info_feature_supported(void) return supported; } + +bool _mv_3d_all_check_system_info_feature_supported(void) +{ + return _mv_3d_check_system_info_feature_supported() || + _mv_3d_depth_check_system_info_feature_supported() || + _mv_3d_pointcloud_check_system_info_feature_supported(); +} + +bool _mv_3d_check_system_info_feature_supported(void) +{ + bool is3dSupported = false; + + const int nRetVal1 = system_info_get_platform_bool("http://tizen.org/feature/vision.3d", + &is3dSupported); + + if (nRetVal1 != SYSTEM_INFO_ERROR_NONE) { + LOGE("SYSTEM_INFO_ERROR: vision.3d"); + return false; + } + + is3dSupported ? LOGI("system_info_get_platform_bool returned " + "Supported 3d feature capability\n") : + LOGE("system_info_get_platform_bool returned " + "Unsupported 3d feature capability\n"); + + return is3dSupported; +} + +bool _mv_3d_depth_check_system_info_feature_supported(void) +{ + bool is3dDepthSupported = false; + + const int nRetVal1 = system_info_get_platform_bool("http://tizen.org/feature/vision.3d.depth", + &is3dDepthSupported); + + if (nRetVal1 != SYSTEM_INFO_ERROR_NONE) { + LOGE("SYSTEM_INFO_ERROR: vision.3d.depth"); + return false; + } + + is3dDepthSupported ? LOGI("system_info_get_platform_bool returned " + "Supported 3d depth feature capability\n") : + LOGE("system_info_get_platform_bool returned " + "Unsupported 3d depth feature capability\n"); + + return is3dDepthSupported; +} + +bool _mv_3d_pointcloud_check_system_info_feature_supported(void) +{ + bool is3dPointCloudSupported = false; + + const int nRetVal1 = system_info_get_platform_bool("http://tizen.org/feature/vision.3d.pointcloud", + &is3dPointCloudSupported); + + if (nRetVal1 != SYSTEM_INFO_ERROR_NONE) { + LOGE("SYSTEM_INFO_ERROR: vision.3d.pointcloud"); + return false; + } + + is3dPointCloudSupported ? LOGI("system_info_get_platform_bool returned " + "Supported 3d pointcloud feature capability\n") : + LOGE("system_info_get_platform_bool returned " + "Unsupported 3d pointcloud feature capability\n"); + + return is3dPointCloudSupported; +} \ No newline at end of file -- 2.7.4 From 858103faefe72d824826e7714381f9afa7e66a65 Mon Sep 17 00:00:00 2001 From: sangho park Date: Fri, 23 Sep 2022 14:01:29 +0900 Subject: [PATCH 10/16] mv3d: fix typo [Issue type] : fix typo MMV_3D_POINTCLOUD_IS_AVAILABLE to MV_3D_POINTCLOUD_IS_AVAILABLE in spec file Change-Id: I5f384053219829b046c39178889ad1049218669c Signed-off-by: sangho park --- packaging/capi-media-vision.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 4b02bd8..ba2a586 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -274,7 +274,7 @@ export LDFLAGS+=" -lgcov" %cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo %{build_options} \ %ifarch aarch64 --DMMV_3D_POINTCLOUD_IS_AVAILABLE=TRUE \ +-DMV_3D_POINTCLOUD_IS_AVAILABLE=TRUE \ %endif %if 0%{?ml_only:1} -DBUILD_ML_ONLY=ON \ -- 2.7.4 From f0c6d72be23fc5cc89f38ec16e6717ebd825552e Mon Sep 17 00:00:00 2001 From: sangho park Date: Fri, 23 Sep 2022 15:42:31 +0900 Subject: [PATCH 11/16] mv3d: fix bugs [Issue type] : bug fix for building mv_3d (add compile_definitions) Change-Id: Ic325fc0bb82122ae014538fb60c7cd2096e71e6b Signed-off-by: sangho park --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9bedda5..fab7f73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,9 @@ if(BUILD_VISUALIZER) add_compile_definitions(BUILD_VISUALIZER) endif() +if(MV_3D_POINTCLOUD_IS_AVAILABLE) + add_compile_definitions(MV_3D_POINTCLOUD_IS_AVAILABLE) +endif() set(MV_COMMON_LIB_NAME "mv_common") set(MV_BARCODE_DETECTOR_LIB_NAME "mv_barcode_detector" CACHE STRING -- 2.7.4 From cb5dfaeda4618d8b28dee545bff19f258a1a4023 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Thu, 29 Sep 2022 14:28:44 +0900 Subject: [PATCH 12/16] mv3d: fix bug [Version] : 0.23.30-0 [Issue type] : bug fix parameters orders are wrong in mv3dRunAsync() Change-Id: Ib06b26dffeae8a8088713ba9f5b51e39f8cf6621 Signed-off-by: Tae-Young Chung --- mv_3d/3d/src/mv_3d.c | 6 +++--- packaging/capi-media-vision.spec | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mv_3d/3d/src/mv_3d.c b/mv_3d/3d/src/mv_3d.c index 27ea242..5f62b6d 100644 --- a/mv_3d/3d/src/mv_3d.c +++ b/mv_3d/3d/src/mv_3d.c @@ -151,9 +151,9 @@ int mv_3d_run_async(mv_3d_h mv3d, MEDIA_VISION_FUNCTION_ENTER(); - int ret = mv3dRunAsync(source, - source_extra, - mv3d); + int ret = mv3dRunAsync(mv3d, + source, + source_extra); MEDIA_VISION_FUNCTION_LEAVE(); diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index ba2a586..a93396f 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -1,6 +1,6 @@ Name: capi-media-vision Summary: Media Vision library for Tizen Native API -Version: 0.23.29 +Version: 0.23.30 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause -- 2.7.4 From 7c71a2aa35c62247032f9ea0f7771badcf1d23a9 Mon Sep 17 00:00:00 2001 From: Inki Dae Date: Fri, 30 Sep 2022 12:02:52 +0900 Subject: [PATCH 13/16] mv_barcode: code cleanup to mv_barcode_generate_open.cpp [Version]: 0.23.31-0 [Issue type] : code cleanup Just drop unnecessary code and use LOGE instead of LOGW in case of an error. Change-Id: I696731722df593527e92b58888f881177d9d8728 Signed-off-by: Inki Dae --- .../src/mv_barcode_generate_open.cpp | 83 +++++----------------- packaging/capi-media-vision.spec | 2 +- 2 files changed, 18 insertions(+), 67 deletions(-) diff --git a/mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp b/mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp index 17da765..c140bea 100644 --- a/mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp +++ b/mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp @@ -246,40 +246,26 @@ int mv_barcode_generate_source_open(mv_engine_config_h engine_cfg, const char *m if (engine_cfg != NULL) { error = mv_engine_config_get_int_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_TEXT", &showText); if (error != MEDIA_VISION_ERROR_NONE) { - LOGW("mv_engine_config_get_int_attribute failed"); + LOGE("mv_engine_config_get_int_attribute failed"); return error; } if (showText == BARCODE_GEN_TEXT_VISIBLE && type == MV_BARCODE_QR) { - LOGW("QR code generation with visible text is not supported"); + LOGE("QR code generation with visible text is not supported"); return MEDIA_VISION_ERROR_INVALID_OPERATION; } /* set color value */ error = mv_engine_config_get_string_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_COLOR_FRONT", &fgcolour); if (error != MEDIA_VISION_ERROR_NONE) { - if (fgcolour) { - free(fgcolour); - fgcolour = NULL; - } - - LOGW("mv_engine_config_get_string_attribute failed"); + LOGE("mv_engine_config_get_string_attribute failed"); return error; } error = mv_engine_config_get_string_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_COLOR_BACK", &bgcolour); if (error != MEDIA_VISION_ERROR_NONE) { - if (bgcolour) { - free(bgcolour); - bgcolour = NULL; - } - - if (fgcolour) { - free(fgcolour); - fgcolour = NULL; - } - - LOGW("mv_engine_config_get_string_attribute failed"); + free(fgcolour); + LOGE("mv_engine_config_get_string_attribute failed"); return error; } @@ -309,22 +295,11 @@ int mv_barcode_generate_source_open(mv_engine_config_h engine_cfg, const char *m convertEncodingMode(qr_enc_mode), convertECC(qr_ecc), qr_version, showText, fgcolour, bgcolour); - if (fgcolour != NULL) { - free(fgcolour); - fgcolour = NULL; - } - - if (bgcolour != NULL) { - free(bgcolour); - bgcolour = NULL; - } + free(fgcolour); + free(bgcolour); if (error != BARCODE_ERROR_NONE) { LOGE("Barcode generation to the buffer failed"); - if (NULL != imageBuffer) { - LOGI("Delete temporal buffer"); - delete[] imageBuffer; - } return convertBarcodeError(error); } @@ -337,14 +312,11 @@ int mv_barcode_generate_source_open(mv_engine_config_h engine_cfg, const char *m error = mv_source_fill_by_buffer_c(image, imageBuffer, imageBufferSize, imageWidth, imageHeight, MEDIA_VISION_COLORSPACE_RGB888); - if (error != MEDIA_VISION_ERROR_NONE) { + if (error != MEDIA_VISION_ERROR_NONE) LOGE("Meidiavision source fill by generated buffer failed"); - } - if (NULL != imageBuffer) { - LOGI("Delete temporal buffer"); - delete[] imageBuffer; - } + // Delete temporal buffer. + delete[] imageBuffer; return error; } @@ -385,40 +357,26 @@ int mv_barcode_generate_image_open(mv_engine_config_h engine_cfg, const char *me /* set visible text attribute */ error = mv_engine_config_get_int_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_TEXT", &showText); if (error != MEDIA_VISION_ERROR_NONE) { - LOGW("mv_engine_config_get_int_attribute failed"); + LOGE("mv_engine_config_get_int_attribute failed"); return error; } if (showText == BARCODE_GEN_TEXT_VISIBLE && type == MV_BARCODE_QR) { - LOGW("QR code generation with visible text is not supported"); + LOGE("QR code generation with visible text is not supported"); return MEDIA_VISION_ERROR_INVALID_OPERATION; } /* set color value */ error = mv_engine_config_get_string_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_COLOR_FRONT", &fgcolour); if (error != MEDIA_VISION_ERROR_NONE) { - if (fgcolour) { - free(fgcolour); - fgcolour = NULL; - } - - LOGW("mv_engine_config_get_string_attribute failed"); + LOGE("mv_engine_config_get_string_attribute failed"); return error; } error = mv_engine_config_get_string_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_COLOR_BACK", &bgcolour); if (error != MEDIA_VISION_ERROR_NONE) { - if (bgcolour) { - free(bgcolour); - bgcolour = NULL; - } - - if (fgcolour) { - free(fgcolour); - fgcolour = NULL; - } - - LOGW("mv_engine_config_get_string_attribute failed"); + free(fgcolour); + LOGE("mv_engine_config_get_string_attribute failed"); return error; } @@ -448,15 +406,8 @@ int mv_barcode_generate_image_open(mv_engine_config_h engine_cfg, const char *me convertEncodingMode(qr_enc_mode), convertECC(qr_ecc), qr_version, showText, fgcolour, bgcolour); - if (fgcolour != NULL) { - free(fgcolour); - fgcolour = NULL; - } - - if (bgcolour != NULL) { - free(bgcolour); - bgcolour = NULL; - } + free(fgcolour); + free(bgcolour); if (error != BARCODE_ERROR_NONE) { LOGE("Barcode generation to the image file failed"); diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index a93396f..529d0a1 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -1,6 +1,6 @@ Name: capi-media-vision Summary: Media Vision library for Tizen Native API -Version: 0.23.30 +Version: 0.23.31 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause -- 2.7.4 From ce101969c5628fb9f400278e3b8d41c65dd6a63b Mon Sep 17 00:00:00 2001 From: Hyunsoo Park Date: Wed, 28 Sep 2022 18:39:38 +0900 Subject: [PATCH 14/16] roi_tracker: move checking codes [Version]: 0.23.32-0 [Issue type] : code clean up Change-Id: I334d859ac84a239ac4c48816dd75240954d14ede Signed-off-by: Hyunsoo Park --- mv_roi_tracker/roi_tracker/src/mv_roi_tracker.c | 9 +++++---- packaging/capi-media-vision.spec | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mv_roi_tracker/roi_tracker/src/mv_roi_tracker.c b/mv_roi_tracker/roi_tracker/src/mv_roi_tracker.c index 6b8b650..3977c04 100644 --- a/mv_roi_tracker/roi_tracker/src/mv_roi_tracker.c +++ b/mv_roi_tracker/roi_tracker/src/mv_roi_tracker.c @@ -72,10 +72,11 @@ int mv_roi_tracker_prepare(mv_roi_tracker_h handle, int x, int y, int width, int { MEDIA_VISION_SUPPORT_CHECK(_mv_roi_tracking_check_system_info_feature_supported()); MEDIA_VISION_INSTANCE_CHECK(handle); - MEDIA_VISION_NULL_ARG_CHECK(x); - MEDIA_VISION_NULL_ARG_CHECK(y); - MEDIA_VISION_NULL_ARG_CHECK(width); - MEDIA_VISION_NULL_ARG_CHECK(height); + + if( x < 0 || y < 0 || width <= 0 || height <= 0 ) { + LOGE("Invalid ROI. Check if roi parameters are less than zero, specially if width and height are equal to zero."); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } MEDIA_VISION_FUNCTION_ENTER(); diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 529d0a1..54de6e6 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -1,6 +1,6 @@ Name: capi-media-vision Summary: Media Vision library for Tizen Native API -Version: 0.23.31 +Version: 0.23.32 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause -- 2.7.4 From 1d68e196bb4cc65da965578b7e360577a6d71c2d Mon Sep 17 00:00:00 2001 From: Hyunsoo Park Date: Wed, 28 Sep 2022 19:45:46 +0900 Subject: [PATCH 15/16] roi_tracker: sets to use default tracker type [Issue type] : bug fix [Version]: 0.23.33-0 - From this patch, tracker type is checked for error handling. If it has wrong setting, default type would be set. Change-Id: I92935555fcfbfc14a970290b54f79fb3f6520a68 Signed-off-by: Hyunsoo Park --- mv_roi_tracker/roi_tracker/src/mv_roi_tracker_open.cpp | 7 ++++++- packaging/capi-media-vision.spec | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mv_roi_tracker/roi_tracker/src/mv_roi_tracker_open.cpp b/mv_roi_tracker/roi_tracker/src/mv_roi_tracker_open.cpp index d8bba9a..78499ad 100644 --- a/mv_roi_tracker/roi_tracker/src/mv_roi_tracker_open.cpp +++ b/mv_roi_tracker/roi_tracker/src/mv_roi_tracker_open.cpp @@ -92,12 +92,17 @@ int mv_roi_tracker_configure_engine_open(mv_roi_tracker_h handle, mv_engine_conf return MEDIA_VISION_ERROR_INVALID_PARAMETER; } + auto pTracker = static_cast(handle); int tracker_type; if (mv_engine_config_get_int_attribute(engine_config, MV_ROI_TRACKER_TYPE, &tracker_type) != MEDIA_VISION_ERROR_NONE) return MEDIA_VISION_ERROR_INVALID_OPERATION; - auto pTracker = static_cast(handle); + if (tracker_type <= MV_ROI_TRACKER_TYPE_NONE || tracker_type > MV_ROI_TRACKER_TYPE_SPEED) { + LOGE("Invalid tracker type. Use default tracker type.(MV_ROI_TRACKER_TYPE_BALANCE)"); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + pTracker->setType(static_cast(tracker_type)); LOGI("LEAVE"); diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 54de6e6..a08c8bb 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -1,6 +1,6 @@ Name: capi-media-vision Summary: Media Vision library for Tizen Native API -Version: 0.23.32 +Version: 0.23.33 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause -- 2.7.4 From 525d5fc82232a94300561db37864a1435fb36a0e Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Tue, 4 Oct 2022 17:22:21 +0900 Subject: [PATCH 16/16] mv3d: add mv_test_3d for testing mv3d module [Version]: 0.23.34-0 [Issue type] : update test Change-Id: I859593365ddc19cc232a8073a5bbe87e8f46081b Signed-off-by: Tae-Young Chung --- packaging/capi-media-vision.spec | 2 +- test/testsuites/mv3d/CMakeLists.txt | 19 ++- test/testsuites/mv3d/test_3d.cpp | 283 ++++++++++++++++++++++++++++++++++++ 3 files changed, 302 insertions(+), 2 deletions(-) create mode 100644 test/testsuites/mv3d/test_3d.cpp diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index a08c8bb..c358f35 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -1,6 +1,6 @@ Name: capi-media-vision Summary: Media Vision library for Tizen Native API -Version: 0.23.33 +Version: 0.23.34 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause diff --git a/test/testsuites/mv3d/CMakeLists.txt b/test/testsuites/mv3d/CMakeLists.txt index 47a1378..1b27aeb 100644 --- a/test/testsuites/mv3d/CMakeLists.txt +++ b/test/testsuites/mv3d/CMakeLists.txt @@ -1,3 +1,4 @@ +## mv_depth_test_suite with images project(mv_depth_test_suite) cmake_minimum_required(VERSION 2.6...3.13) @@ -29,7 +30,8 @@ if(BUILD_VISUALIZER) endif() install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) -## mv_depthstream + +## mv_depthstream_test_sutie pkg_check_modules(GLIB_PKG glib-2.0) if (NOT GLIB_PKG_FOUND) @@ -67,3 +69,18 @@ if(BUILD_VISUALIZER) endif() install(TARGETS mv_depthstream_test_suite DESTINATION ${CMAKE_INSTALL_BINDIR}) + +## mv_test_3d by gtest +project(mv_test_3d) +cmake_minimum_required(VERSION 2.6...3.13) + +set(TEST_3D mv_test_3d) + +add_executable(${TEST_3D} test_3d.cpp) + +target_link_libraries(${TEST_3D} gtest gtest_main + mv_3d + mv_image_helper +) + +install(TARGETS ${TEST_3D} DESTINATION ${CMAKE_INSTALL_BINDIR}) \ No newline at end of file diff --git a/test/testsuites/mv3d/test_3d.cpp b/test/testsuites/mv3d/test_3d.cpp new file mode 100644 index 0000000..37645f2 --- /dev/null +++ b/test/testsuites/mv3d/test_3d.cpp @@ -0,0 +1,283 @@ +/** + * 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 +#include +#include + +#include "gtest/gtest.h" +#include "ImageHelper.h" +#include "mv_3d.h" + +using namespace testing; + +// 0:image,1 camera, test sequence name if image, width, height, min disp, max disp, camera parameter +typedef std::tuple ParamTypes; +#define IMAGE_RES_PATH "/usr/share/capi-media-vision/dfseval" +#define PCD_OUTPUT_PATH "/tmp" +#define DEPTH_INTRINSIC_FILENAME "calibOcv.yaml" +#define PCD_WRITE_FILENAME "test_pontcloud.pcd" +#define IMAGE_FILENAME_LEFT "im0.jpeg" +#define IMAGE_FILENAME_RIGHT "im1.jpeg" +#define PCD_SAMPLING_RATIO 0.05 +#define PCD_OUTLIER_REMOVAL_POINT 3 +#define PCD_OUTLIER_REMOVAL_RADIUS 0.5 + +enum { TEST_MODE_IMAGE = 0, TEST_MODE_CAMERA = 1 }; +static GCond gThreadCond; +static GMutex gThreadMutex; +static void WaitUntil() +{ + g_mutex_lock(&gThreadMutex); + g_print("\t[__wait] waiting... until finishing\n"); + g_cond_wait(&gThreadCond, &gThreadMutex); + g_print("\t[__wait] get signal from callback\n"); + g_mutex_unlock(&gThreadMutex); +} + +static void Signal() +{ + g_mutex_lock(&gThreadMutex); + g_cond_signal(&gThreadCond); + g_print("\t[__signal] send signal to test proc\n"); + g_mutex_unlock(&gThreadMutex); +} + +class Mv3DTestsFixture : public ::testing::TestWithParam +{ +protected: + Mv3DTestsFixture() = default; + ~Mv3DTestsFixture() = default; + + void SetUp() final + { + ASSERT_EQ(mv_3d_create(&mDepthHandle), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_create_engine_config(&mEngineCfgHandle),MEDIA_VISION_ERROR_NONE); + + std::tie(mTestMode, + mImageName, + mWidth, + mHeight, + mMinDisparity, + mMaxDisparity, + mCameraCalibrationPath) = GetParam(); + + ASSERT_EQ(mv_engine_config_set_int_attribute(mEngineCfgHandle, + MV_3D_DEPTH_WIDTH, + mWidth), MEDIA_VISION_ERROR_NONE); + + + ASSERT_EQ(mv_engine_config_set_int_attribute(mEngineCfgHandle, + MV_3D_DEPTH_HEIGHT, + mHeight), MEDIA_VISION_ERROR_NONE); + + ASSERT_EQ(mv_engine_config_set_int_attribute(mEngineCfgHandle, + MV_3D_DEPTH_MIN_DISPARITY, + mMinDisparity), MEDIA_VISION_ERROR_NONE); + + ASSERT_EQ(mv_engine_config_set_int_attribute(mEngineCfgHandle, + MV_3D_DEPTH_MAX_DISPARITY, + mMaxDisparity), MEDIA_VISION_ERROR_NONE); + + if (mTestMode == 0) + mCameraCalibrationPath = std::string(IMAGE_RES_PATH) + std::string("/") + + mImageName + std::string("/") + + std::string(DEPTH_INTRINSIC_FILENAME); + else + ASSERT_FALSE(mCameraCalibrationPath.empty()) << "there is no calibration file"; + + ASSERT_EQ(mv_engine_config_set_string_attribute(mEngineCfgHandle, + MV_3D_DEPTH_STEREO_CONFIG_FILE_PATH, + mCameraCalibrationPath.c_str()), MEDIA_VISION_ERROR_NONE); + + ASSERT_EQ(mv_engine_config_set_double_attribute(mEngineCfgHandle, + MV_3D_POINTCLOUD_SAMPLING_RATIO, + PCD_SAMPLING_RATIO), MEDIA_VISION_ERROR_NONE); + + ASSERT_EQ(mv_engine_config_set_int_attribute(mEngineCfgHandle, + MV_3D_POINTCLOUD_OUTLIER_REMOVAL_POINTS, + PCD_OUTLIER_REMOVAL_POINT), MEDIA_VISION_ERROR_NONE); + + ASSERT_EQ(mv_engine_config_set_double_attribute(mEngineCfgHandle, + MV_3D_POINTCLOUD_OUTLIER_REMOVAL_RADIUS, + PCD_OUTLIER_REMOVAL_RADIUS), MEDIA_VISION_ERROR_NONE); + + ASSERT_EQ(mv_engine_config_set_string_attribute(mEngineCfgHandle, + MV_3D_POINTCLOUD_OUTPUT_FILE_PATH, + PCD_OUTPUT_PATH), MEDIA_VISION_ERROR_NONE); + } + + + void TearDown() final + { + ASSERT_EQ(mv_3d_destroy(mDepthHandle), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_destroy_engine_config(mEngineCfgHandle), MEDIA_VISION_ERROR_NONE); + + if (mLeftSourceHandle) { + ASSERT_EQ(mv_destroy_source(mLeftSourceHandle), MEDIA_VISION_ERROR_NONE); + } + + if (mRightSourceHandle) { + ASSERT_EQ(mv_destroy_source(mRightSourceHandle), MEDIA_VISION_ERROR_NONE); + } + } + + void LoadImage() + { + auto imagePath = std::string(IMAGE_RES_PATH) + std::string("/") + mImageName; + auto leftImageFilePath = imagePath + std::string("/") + std::string(IMAGE_FILENAME_LEFT); + auto rightImageFilePath = imagePath + std::string("/") + std::string(IMAGE_FILENAME_RIGHT); + + ASSERT_EQ(access(leftImageFilePath.c_str(), F_OK | R_OK), 0) << leftImageFilePath << " doesn't exist"; + ASSERT_EQ(mv_create_source(&mLeftSourceHandle), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(MediaVision::Common::ImageHelper::loadImageToSource( + leftImageFilePath.c_str(), mLeftSourceHandle), MEDIA_VISION_ERROR_NONE); + + ASSERT_EQ(access(rightImageFilePath.c_str(), F_OK | R_OK), 0) << rightImageFilePath << " doesn't exist"; + ASSERT_EQ(mv_create_source(&mRightSourceHandle), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(MediaVision::Common::ImageHelper::loadImageToSource( + rightImageFilePath.c_str(), mRightSourceHandle), MEDIA_VISION_ERROR_NONE); + } + + mv_source_h mLeftSourceHandle {nullptr}; + mv_source_h mRightSourceHandle {nullptr}; + mv_engine_config_h mEngineCfgHandle {nullptr}; + + int mTestMode {TEST_MODE_IMAGE}; + std::string mImageName {""}; + int mWidth {0}; + int mHeight {0}; + int mMinDisparity {0}; + int mMaxDisparity {0}; + std::string mCameraCalibrationPath {""}; + +public: + mv_3d_h mDepthHandle {nullptr}; + bool mIsDepthCallbackInvoked {false}; + bool mIsPointCloudCallbackInvoked {false}; + bool mIsPointCloudWriteSuccess {false}; + bool mIsRunAsync {false}; +}; + +static void _depth_cb(mv_source_h source, unsigned short *depth, unsigned int width, + unsigned int height, void *user_data) +{ + auto mv3dTestsFixture = static_cast(user_data); + mv3dTestsFixture->mIsDepthCallbackInvoked = true; +} + +static void _pointcloud_cb(mv_source_h source, + mv_3d_pointcloud_h pointcloud, + void *user_data) +{ + auto mv3dTestsFixture = static_cast(user_data); + mv3dTestsFixture->mIsPointCloudCallbackInvoked = true; + if (mv3dTestsFixture->mIsRunAsync) + Signal(); +} + +static void _pointcloud_write_file_cb(mv_source_h source, + mv_3d_pointcloud_h pointcloud, + void *user_data) +{ + auto mv3dTestsFixture = static_cast(user_data); + mv3dTestsFixture->mIsPointCloudCallbackInvoked = true; + + int ret = mv_3d_pointcloud_write_file(mv3dTestsFixture->mDepthHandle, pointcloud, MV_3D_POINTCLOUD_TYPE_PCD_BIN, PCD_WRITE_FILENAME); + if (ret == MEDIA_VISION_ERROR_NONE) + mv3dTestsFixture->mIsPointCloudWriteSuccess = true; +} + +TEST_P(Mv3DTestsFixture, Configure) +{ + ASSERT_EQ(mv_3d_configure(mDepthHandle, mEngineCfgHandle), MEDIA_VISION_ERROR_NONE); +} + +TEST_P(Mv3DTestsFixture, SetCallback) +{ + ASSERT_EQ(mv_3d_set_depth_cb(mDepthHandle, _depth_cb, this), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_3d_set_pointcloud_cb(mDepthHandle, _pointcloud_cb, this), MEDIA_VISION_ERROR_NONE); +} + +TEST_P(Mv3DTestsFixture, Prepare) +{ + ASSERT_EQ(mv_3d_configure(mDepthHandle, mEngineCfgHandle), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_3d_set_depth_cb(mDepthHandle, _depth_cb, this), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_3d_set_pointcloud_cb(mDepthHandle, _pointcloud_cb, this), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_3d_prepare(mDepthHandle), MEDIA_VISION_ERROR_NONE); +} + +TEST_P(Mv3DTestsFixture, Runsync) +{ + ASSERT_EQ(mv_3d_configure(mDepthHandle, mEngineCfgHandle), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_3d_set_depth_cb(mDepthHandle, _depth_cb, this), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_3d_set_pointcloud_cb(mDepthHandle, _pointcloud_cb, this), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_3d_prepare(mDepthHandle), MEDIA_VISION_ERROR_NONE); + + if (mTestMode == 0) { + LoadImage(); + } + ASSERT_EQ(mv_3d_run(mDepthHandle, mLeftSourceHandle, mRightSourceHandle, nullptr), MEDIA_VISION_ERROR_NONE); + ASSERT_TRUE(mIsDepthCallbackInvoked); + ASSERT_TRUE(mIsPointCloudCallbackInvoked); +} + +TEST_P(Mv3DTestsFixture, RunAsync) +{ + mIsRunAsync = true; + ASSERT_EQ(mv_3d_configure(mDepthHandle, mEngineCfgHandle), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_3d_set_depth_cb(mDepthHandle, _depth_cb, this), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_3d_set_pointcloud_cb(mDepthHandle, _pointcloud_cb, this), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_3d_prepare(mDepthHandle), MEDIA_VISION_ERROR_NONE); + + if (mTestMode == 0) { + LoadImage(); + } + ASSERT_EQ(mv_3d_run_async(mDepthHandle, mLeftSourceHandle, mRightSourceHandle, nullptr), MEDIA_VISION_ERROR_NONE); + + WaitUntil(); + ASSERT_TRUE(mIsDepthCallbackInvoked); + ASSERT_TRUE(mIsPointCloudCallbackInvoked); +} + +TEST_P(Mv3DTestsFixture, PointCloudWriteFile) +{ + ASSERT_EQ(mv_3d_configure(mDepthHandle, mEngineCfgHandle), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_3d_set_depth_cb(mDepthHandle, _depth_cb, this), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_3d_set_pointcloud_cb(mDepthHandle, _pointcloud_write_file_cb, this), MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_3d_prepare(mDepthHandle), MEDIA_VISION_ERROR_NONE); + + if (mTestMode == 0) { + LoadImage(); + } + ASSERT_EQ(mv_3d_run(mDepthHandle, mLeftSourceHandle, mRightSourceHandle, nullptr), MEDIA_VISION_ERROR_NONE); + ASSERT_TRUE(mIsDepthCallbackInvoked); + ASSERT_TRUE(mIsPointCloudCallbackInvoked); + ASSERT_TRUE(mIsPointCloudWriteSuccess); +} + +INSTANTIATE_TEST_SUITE_P( + Mv3DTests, + Mv3DTestsFixture, + ::Values( + ParamTypes(TEST_MODE_IMAGE, std::string("Adirondack"), 718, 496, 8, 72, std::string())) +); + +int main(int argc, char **argv) +{ + InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file -- 2.7.4