From 530f5ba836a60cf9d4dfb224790b2f13670c87ca Mon Sep 17 00:00:00 2001 From: Inki Dae Date: Tue, 27 Sep 2022 11:19:02 +0900 Subject: [PATCH 01/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 02/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 03/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 04/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 05/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 06/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 07/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 08/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 09/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 10/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 11/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 12/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 From 41187f26e9f1f3c1d4da761f55faef525349049b Mon Sep 17 00:00:00 2001 From: Hyunsoo Park Date: Wed, 5 Oct 2022 14:07:52 +0900 Subject: [PATCH 13/16] roi_tracker: Fix default tracker type value as integer [Issue type] : bug fix [Version]: 0.23.35-0 - From this patch, tracker type set as default correctly. Change-Id: I4fc4073f204ea46c46db631f7422e80317b0b452 Signed-off-by: Hyunsoo Park --- media-vision-config.json | 2 +- mv_roi_tracker/roi_tracker/src/mv_roi_tracker_open.cpp | 2 +- packaging/capi-media-vision.spec | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/media-vision-config.json b/media-vision-config.json index 6703092..136ab1b 100644 --- a/media-vision-config.json +++ b/media-vision-config.json @@ -251,7 +251,7 @@ { "name" : "MV_ROI_TRACKER_TYPE", "type" : "integer", - "value" : "2" + "value" : 2 }, { "name" : "MV_3D_DEPTH_MODE", 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 78499ad..4fd2601 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 @@ -99,7 +99,7 @@ int mv_roi_tracker_configure_engine_open(mv_roi_tracker_h handle, mv_engine_conf return MEDIA_VISION_ERROR_INVALID_OPERATION; 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)"); + LOGE("Invalid tracker type."); return MEDIA_VISION_ERROR_INVALID_PARAMETER; } diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index c358f35..58b02c4 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.34 +Version: 0.23.35 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause -- 2.7.4 From f14d368de92032904dc4eb28f3cdee31e9e5d361 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Wed, 5 Oct 2022 14:31:05 +0900 Subject: [PATCH 14/16] mv3d: update mv_depth_test_suite [Version]: 0.23.35-0 [Issue type]: update test - apply coding convention - update global functions to static ones - remove unused variables Change-Id: Ibf8cb916cda98a9656e99632add7897f5c8f2947 Signed-off-by: Tae-Young Chung --- test/testsuites/mv3d/depth_test_suite.cpp | 257 +++++++++++++----------------- 1 file changed, 108 insertions(+), 149 deletions(-) diff --git a/test/testsuites/mv3d/depth_test_suite.cpp b/test/testsuites/mv3d/depth_test_suite.cpp index bee2201..100e976 100644 --- a/test/testsuites/mv3d/depth_test_suite.cpp +++ b/test/testsuites/mv3d/depth_test_suite.cpp @@ -42,58 +42,38 @@ #define MAX_STRING_LENGTH 1024 #define ARRAY_SIZE(x) (sizeof((x)) / sizeof((x)[0])) -#define __max(a,b) (((a) > (b)) ? (a) : (b)) -#define __min(a,b) (((a) < (b)) ? (a) : (b)) +#define __max(a, b) (((a) > (b)) ? (a) : (b)) +#define __min(a, b) (((a) < (b)) ? (a) : (b)) /* There are calib.txt, im0.png, and im1.png in each dataset directories.*/ -static const char* dataset[] = { - "Adirondack", - "Jadeplant", - "Motorcycle", - "Piano", - "Pipes", - "Playroom", - "Playtable", - "Recycle", - "Shelves", - "Vintage", - "Backpack", - "Bicycle1", - "Cable", - "Classroom1", - "Couch", - "Flowers", - "Mask", - "Shopvac", - "Sticks", - "Storage", - "Sword1", - "Sword2", - "Umbrella" -}; +static const char *dataset[] = { "Adirondack", "Jadeplant", "Motorcycle", "Piano", "Pipes", "Playroom", + "Playtable", "Recycle", "Shelves", "Vintage", "Backpack", "Bicycle1", + "Cable", "Classroom1", "Couch", "Flowers", "Mask", "Shopvac", + "Sticks", "Storage", "Sword1", "Sword2", "Umbrella" }; class StopWatch { public: - StopWatch() { + StopWatch() + { start = std::chrono::steady_clock::now(); } ~StopWatch() = default; - std::chrono::milliseconds elapsedTime() { - return std::chrono::duration_cast( - std::chrono::steady_clock::now() - start); + std::chrono::milliseconds elapsedTime() + { + return std::chrono::duration_cast(std::chrono::steady_clock::now() - start); } + private: std::chrono::steady_clock::time_point start; }; -typedef struct _appdata { +typedef struct _appdata +{ mv_3d_h mv3d; std::chrono::milliseconds diffMs; std::string dataPath; - std::string intrinsicName; - std::string rgbName; std::string datasetName; float minDisp; float maxDisp; @@ -101,20 +81,21 @@ typedef struct _appdata { std::string dataset; } appdata; -enum { +enum +{ FMT_PFM = 1, FMT_PNG }; -int littleendian() +static int littleendian() { int intval = 1; - uchar *uval = (uchar *)&intval; + uchar *uval = (uchar *) &intval; return uval[0] == 1; } -void WriteFilePFM(float *data, int width, int height, const char* filename, - float minDisp, float maxDisp, float scalefactor = 1 / 255.0) +static void WriteFilePFM(float *data, int width, int height, const char *filename, float minDisp, float maxDisp, + float scalefactor = 1 / 255.0) { FILE *stream = fopen(filename, "wb"); if (stream == 0) { @@ -129,13 +110,13 @@ void WriteFilePFM(float *data, int width, int height, const char* filename, int n = width; for (int y = height - 1; y >= 0; y--) { - float* ptr = data + y * width; + float *ptr = data + y * width; for (int x = 0; x < width; x++) { if (ptr[x] <= 0 || ptr[x] > maxDisp) { //xsh modified ptr[x] = INFINITY; } } - if ((int)fwrite(ptr, sizeof(float), n, stream) != n) { + if ((int) fwrite(ptr, sizeof(float), n, stream) != n) { fprintf(stderr, "WriteFilePFM: problem writing data\n"); exit(1); } @@ -146,18 +127,20 @@ void WriteFilePFM(float *data, int width, int height, const char* filename, // translate value x in [0..1] into color triplet using "jet" color map // if out of range, use darker colors // variation of an idea by http://www.metastine.com/?p=7 -void jet(float x, int& r, int& g, int& b) +static void jet(float x, int &r, int &g, int &b) { - if (x < 0) x = -0.05; - if (x > 1) x = 1.05; - x = x / 1.15 + 0.1; // use slightly asymmetric range to avoid darkest shades of blue. - r = __max(0, __min(255, (int)(round(255 * (1.5 - 4*fabs(x - .75)))))); - g = __max(0, __min(255, (int)(round(255 * (1.5 - 4*fabs(x - .5)))))); - b = __max(0, __min(255, (int)(round(255 * (1.5 - 4*fabs(x - .25)))))); + if (x < 0) + x = -0.05; + if (x > 1) + x = 1.05; + x = x / 1.15 + 0.1; // use slightly asymmetric range to avoid darkest shades of blue. + r = __max(0, __min(255, (int) (round(255 * (1.5 - 4 * fabs(x - .75)))))); + g = __max(0, __min(255, (int) (round(255 * (1.5 - 4 * fabs(x - .5)))))); + b = __max(0, __min(255, (int) (round(255 * (1.5 - 4 * fabs(x - .25)))))); } -void WriteFilePNG(unsigned short *data, int width, int height, const char* filename, - float minDisp, float maxDisp) +static void WriteFilePNG(unsigned short *data, int width, int height, const char *filename, float minDisp, + float maxDisp) { // Open the file FILE *stream = fopen(filename, "wb"); @@ -169,13 +152,13 @@ void WriteFilePNG(unsigned short *data, int width, int height, const char* filen cv::Mat dump(cv::Size(width, height), CV_16U); for (int y = 0; y < height; y++) { - unsigned short* ptr = data + y * width; + unsigned short *ptr = data + y * width; for (int x = 0; x < width; x++) { unsigned short f = ptr[x]; - dump.at(y,x) = f; + dump.at(y, x) = f; } - } + } printf("%d x %d", width, height); cv::imwrite(filename, dump); @@ -183,7 +166,7 @@ void WriteFilePNG(unsigned short *data, int width, int height, const char* filen fclose(stream); } -void WritePLY(double *data, int size, const char* filename) +static void WritePLY(double *data, int size, const char *filename) { std::ofstream stream(filename, std::ofstream::out); stream << "ply" << std::endl; @@ -195,61 +178,56 @@ void WritePLY(double *data, int size, const char* filename) stream << "end_header" << std::endl; for (int pc = 0; pc < size; ++pc) { - stream << std::fixed << std::setprecision(2) << - data[pc*3] << " " << data[pc*3 + 1] << " " << data[pc*3 + 2] << std::endl; + stream << std::fixed << std::setprecision(2) << data[pc * 3] << " " << data[pc * 3 + 1] << " " + << data[pc * 3 + 2] << std::endl; } return; } -void _depth_middlebury_cb(mv_source_h source, - unsigned short* depth, - unsigned int width, - unsigned int height, - void* user_data) +static void _depth_middlebury_cb(mv_source_h source, unsigned short *depth, unsigned int width, unsigned int height, + void *user_data) { if (!user_data) { printf("user_data is null. Skip..\n"); return; } - auto udata = static_cast(user_data); + auto udata = static_cast(user_data); StopWatch stopWatch; if (udata->fmt == FMT_PFM) { - WriteFilePFM(reinterpret_cast(depth), width, height, udata->datasetName.c_str(), - udata->minDisp, udata->maxDisp); + WriteFilePFM(reinterpret_cast(depth), width, height, udata->datasetName.c_str(), udata->minDisp, + udata->maxDisp); } else { - WriteFilePNG(depth, width, height, udata->datasetName.c_str(), - udata->minDisp, udata->maxDisp); + WriteFilePNG(depth, width, height, udata->datasetName.c_str(), udata->minDisp, udata->maxDisp); } udata->diffMs = stopWatch.elapsedTime(); } -void _pointcloud_middlebury_cb(mv_source_h source, - mv_3d_pointcloud_h pointcloud, - void *user_data) +static void _pointcloud_middlebury_cb(mv_source_h source, mv_3d_pointcloud_h pointcloud, void *user_data) { if (!user_data) { printf("user_data is null. Skip..\n"); return; } - auto udata = static_cast(user_data); - std::string filename = udata->dataset + std::string(".pcd"); - mv_3d_pointcloud_write_file(udata->mv3d, pointcloud, MV_3D_POINTCLOUD_TYPE_PCD_BIN, (char*)filename.c_str()); + auto udata = static_cast(user_data); + std::string filename = udata->dataset + std::string(".ply"); + mv_3d_pointcloud_write_file(udata->mv3d, pointcloud, MV_3D_POINTCLOUD_TYPE_PLY_TXT, (char *) filename.c_str()); - mv_3d_pointcloud_plane_model_h model; - mv_3d_pointcloud_plane_inlier_h inlier; + mv_3d_pointcloud_plane_model_h model = nullptr; + mv_3d_pointcloud_plane_inlier_h inlier = nullptr; mv_3d_pointcloud_plane_model_create(&model); mv_3d_pointcloud_plane_inlier_create(&inlier); mv_3d_pointcloud_segment_plane(udata->mv3d, pointcloud, &model, &inlier); - filename = udata->dataset + std::string("-plane.pcd"); - mv_3d_pointcloud_plane_write_file(udata->mv3d, model, inlier, pointcloud, MV_3D_POINTCLOUD_TYPE_PCD_BIN, (char*)filename.c_str()); + filename = udata->dataset + std::string("-plane.ply"); + mv_3d_pointcloud_plane_write_file(udata->mv3d, model, inlier, pointcloud, MV_3D_POINTCLOUD_TYPE_PLY_TXT, + (char *) filename.c_str()); mv_3d_pointcloud_plane_model_destroy(model); mv_3d_pointcloud_plane_inlier_destroy(inlier); @@ -257,29 +235,27 @@ void _pointcloud_middlebury_cb(mv_source_h source, int perform_middlebury_test() { - char* path_to_dataset = NULL; - char* suffix_for_algo = NULL; + char *path_to_dataset = NULL; + char *suffix_for_algo = NULL; int err = MEDIA_VISION_ERROR_NONE; mv_engine_config_h engine_config = NULL; - mv_source_h left_source = NULL; + mv_source_h left_source = NULL; mv_source_h right_source = NULL; - mv_3d_h mv3d_handle = NULL; + mv_3d_h mv3d_handle = NULL; size_t datasize = ARRAY_SIZE(dataset); cv::Mat left_frame, right_frame; - while (input_string("root path including dataset:", - 1024, &path_to_dataset) == -1) { + while (input_string("root path including dataset:", 1024, &path_to_dataset) == -1) { printf("Incorrect! Try again.\n"); } - while (input_string("suffix for algorithm:", - 1024, &suffix_for_algo) == -1) { + while (input_string("suffix for algorithm:", 1024, &suffix_for_algo) == -1) { printf("Incorrect! Try again.\n"); } - const char* formats[] = {"pfm", "png"}; + const char *formats[] = { "pfm", "png" }; int sel_fmt = -1; - while(sel_fmt <= 0 || sel_fmt > static_cast(ARRAY_SIZE(formats))) { + while (sel_fmt <= 0 || sel_fmt > static_cast(ARRAY_SIZE(formats))) { sel_fmt = show_menu_linear("Select Action", formats, ARRAY_SIZE(formats)); } @@ -313,19 +289,17 @@ int perform_middlebury_test() snprintf(dataPath, MAX_STRING_LENGTH, "%s/%s", path_to_dataset, dataset[data]); snprintf(calibFilename, MAX_STRING_LENGTH, "%s/calib.txt", dataPath); - snprintf(stereoConfigFileName, MAX_STRING_LENGTH, "%s/calibOcv.xml", dataPath); + snprintf(stereoConfigFileName, MAX_STRING_LENGTH, "%s/calibOcv.yaml", dataPath); snprintf(leftFilename, MAX_STRING_LENGTH, "%s/im0.png", dataPath); snprintf(rightFilename, MAX_STRING_LENGTH, "%s/im1.png", dataPath); - if ((access(calibFilename, F_OK) < 0) || - (access(leftFilename, F_OK) < 0) || - (access(rightFilename, F_OK) < 0) ) { + if ((access(calibFilename, F_OK) < 0) || (access(leftFilename, F_OK) < 0) || + (access(rightFilename, F_OK) < 0)) { printf("Invalid dataset path:\n"); goto _err; } - printf("Run dataset %s\n", dataset[data]); - FILE* fp = fopen(calibFilename, "r"); + FILE *fp = fopen(calibFilename, "r"); char line[MAX_STRING_LENGTH]; float fVal; float dmin = 0, dmax = 0; @@ -333,10 +307,14 @@ int perform_middlebury_test() 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; - if (sscanf(line, "vmax= %f", &fVal) == 1) dmax = fVal; - if (sscanf(line, "width= %d", &iVal) == 1) width = iVal; - if (sscanf(line, "height= %d", &iVal) == 1) height = iVal; + if (sscanf(line, "vmin= %f", &fVal) == 1) + dmin = fVal; + if (sscanf(line, "vmax= %f", &fVal) == 1) + dmax = fVal; + if (sscanf(line, "width= %d", &iVal) == 1) + width = iVal; + if (sscanf(line, "height= %d", &iVal) == 1) + height = iVal; } fclose(fp); } else { @@ -348,71 +326,64 @@ int perform_middlebury_test() int maxDisp = static_cast(dmax); // engine_config - err = mv_engine_config_set_int_attribute(engine_config, - MV_3D_DEPTH_MODE, MV_3D_DEPTH_MODE_STEREO); + err = mv_engine_config_set_int_attribute(engine_config, MV_3D_DEPTH_MODE, MV_3D_DEPTH_MODE_STEREO); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to set depth mode\n"); goto _err; } - err = mv_engine_config_set_int_attribute(engine_config, - MV_3D_DEPTH_WIDTH, width); + err = mv_engine_config_set_int_attribute(engine_config, MV_3D_DEPTH_WIDTH, width); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to set width\n"); goto _err; } - err = mv_engine_config_set_int_attribute(engine_config, - MV_3D_DEPTH_HEIGHT, height); + err = mv_engine_config_set_int_attribute(engine_config, MV_3D_DEPTH_HEIGHT, height); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to set height\n"); goto _err; } - err = mv_engine_config_set_int_attribute(engine_config, - MV_3D_DEPTH_MIN_DISPARITY, minDisp); + err = mv_engine_config_set_int_attribute(engine_config, MV_3D_DEPTH_MIN_DISPARITY, minDisp); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to set min disparity\n"); goto _err; } - err = mv_engine_config_set_int_attribute(engine_config, - MV_3D_DEPTH_MAX_DISPARITY, maxDisp); + err = mv_engine_config_set_int_attribute(engine_config, MV_3D_DEPTH_MAX_DISPARITY, maxDisp); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to set max disparity\n"); goto _err; } - err = mv_engine_config_set_string_attribute(engine_config, - MV_3D_DEPTH_STEREO_CONFIG_FILE_PATH, stereoConfigFileName); + err = mv_engine_config_set_string_attribute(engine_config, MV_3D_DEPTH_STEREO_CONFIG_FILE_PATH, + stereoConfigFileName); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to set stereo config file path\n"); goto _err; } - err = mv_engine_config_set_double_attribute(engine_config, - MV_3D_POINTCLOUD_SAMPLING_RATIO, samplingRatio); + err = mv_engine_config_set_double_attribute(engine_config, MV_3D_POINTCLOUD_SAMPLING_RATIO, samplingRatio); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to set stereo config file path\n"); goto _err; } - err = mv_engine_config_set_int_attribute(engine_config, - MV_3D_POINTCLOUD_OUTLIER_REMOVAL_POINTS, outlierRemovalPoints); + err = mv_engine_config_set_int_attribute(engine_config, MV_3D_POINTCLOUD_OUTLIER_REMOVAL_POINTS, + outlierRemovalPoints); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to set stereo config file path\n"); goto _err; } - err = mv_engine_config_set_double_attribute(engine_config, - MV_3D_POINTCLOUD_OUTLIER_REMOVAL_RADIUS, outlierRemovalRadius); + err = mv_engine_config_set_double_attribute(engine_config, MV_3D_POINTCLOUD_OUTLIER_REMOVAL_RADIUS, + outlierRemovalRadius); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to set stereo config file path\n"); goto _err; } - err = mv_engine_config_set_string_attribute(engine_config, - MV_3D_POINTCLOUD_OUTPUT_FILE_PATH, MEDIA_FILE_PATH); + err = mv_engine_config_set_string_attribute(engine_config, MV_3D_POINTCLOUD_OUTPUT_FILE_PATH, MEDIA_FILE_PATH); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to set stereo config file path\n"); goto _err; @@ -422,25 +393,19 @@ int perform_middlebury_test() left_frame = cv::imread(leftFilename, cv::IMREAD_COLOR); right_frame = cv::imread(rightFilename, cv::IMREAD_COLOR); - err = mv_source_fill_by_buffer(left_source, - left_frame.ptr(), - left_frame.elemSize() * left_frame.size().width - * left_frame.size().height, - left_frame.size().width, - left_frame.size().height, - MEDIA_VISION_COLORSPACE_RGB888); + err = mv_source_fill_by_buffer(left_source, left_frame.ptr(), + left_frame.elemSize() * left_frame.size().width * left_frame.size().height, + left_frame.size().width, left_frame.size().height, + MEDIA_VISION_COLORSPACE_RGB888); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to fill left_source\n"); goto _err; } - err = mv_source_fill_by_buffer(right_source, - right_frame.ptr(), - right_frame.elemSize() * right_frame.size().width - * right_frame.size().height, - right_frame.size().width, - right_frame.size().height, - MEDIA_VISION_COLORSPACE_RGB888); + err = mv_source_fill_by_buffer(right_source, right_frame.ptr(), + right_frame.elemSize() * right_frame.size().width * right_frame.size().height, + right_frame.size().width, right_frame.size().height, + MEDIA_VISION_COLORSPACE_RGB888); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to fill right_source\n"); goto _err; @@ -460,27 +425,23 @@ int perform_middlebury_test() } // get depth - appdata dump { - mv3d_handle, - std::chrono::milliseconds::zero(), - std::string(dataPath), - std::string(dataPath) + std::string("/intrinsics.json"), - std::string(leftFilename), - std::string(dataPath) + std::string("/disp0") + std::string(suffix_for_algo), - static_cast(minDisp), - static_cast(maxDisp), - sel_fmt - }; + appdata dump { mv3d_handle, + std::chrono::milliseconds::zero(), + std::string(dataPath), + std::string(dataPath) + std::string("/disp0") + std::string(suffix_for_algo), + static_cast(minDisp), + static_cast(maxDisp), + sel_fmt, + std::string(dataset[data]) }; dump.datasetName += sel_fmt == FMT_PFM ? std::string(".pfm") : std::string(".png"); - dump.dataset = std::string(dataset[data]); - err = mv_3d_set_depth_cb(mv3d_handle, _depth_middlebury_cb, static_cast(&dump)); + err = mv_3d_set_depth_cb(mv3d_handle, _depth_middlebury_cb, static_cast(&dump)); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to set depth callback to handle\n"); goto _err; } - err = mv_3d_set_pointcloud_cb(mv3d_handle, _pointcloud_middlebury_cb, static_cast(&dump)); + err = mv_3d_set_pointcloud_cb(mv3d_handle, _pointcloud_middlebury_cb, static_cast(&dump)); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to set pointcloud callback to handle\n"); goto _err; @@ -491,11 +452,9 @@ int perform_middlebury_test() printf("Failed to prepare depth handle\n"); goto _err; } + StopWatch stopWatch; - err = mv_3d_run(mv3d_handle, - left_source, - right_source, - NULL); + err = mv_3d_run(mv3d_handle, left_source, right_source, NULL); /* time to save a file is excluded */ std::chrono::milliseconds diffMs = stopWatch.elapsedTime() - dump.diffMs; @@ -531,7 +490,7 @@ _err: int main() { int err = MEDIA_VISION_ERROR_NONE; - const char* names[] = {"Middlebury - TrainingQ(Imperf)"}; + const char *names[] = { "Middlebury - TrainingQ(Imperf)" }; int sel_opt = show_menu_linear("Select Action", names, ARRAY_SIZE(names)); if (sel_opt <= 0 || sel_opt > static_cast(ARRAY_SIZE(names))) { -- 2.7.4 From f0469da618e3f02b03932fe05d511f1e93c86d70 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Tue, 11 Oct 2022 12:30:59 +0900 Subject: [PATCH 15/16] mv3d: fix wrong parameters order [Version]: 0.23.36-0 [Issue type]: fix bad bug Change-Id: I0c7e2c12afac2df7561fac3a072800d7bdc9e006 Signed-off-by: Tae-Young Chung --- mv_3d/3d/src/Mv3d.cpp | 2 +- packaging/capi-media-vision.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mv_3d/3d/src/Mv3d.cpp b/mv_3d/3d/src/Mv3d.cpp index 9982635..6cd83b7 100644 --- a/mv_3d/3d/src/Mv3d.cpp +++ b/mv_3d/3d/src/Mv3d.cpp @@ -412,9 +412,9 @@ namespace mv3d auto leftData = handle->mDfsAdaptor->getLeftData(); int ret = mv_source_fill_by_buffer(handle->mInternalSource, static_cast(leftData.data), + leftData.stride * leftData.height, 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) { diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 58b02c4..60cb16c 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.35 +Version: 0.23.36 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause -- 2.7.4 From 9dc0759e0f23b05198368d355fcda71b2b15e028 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Thu, 13 Oct 2022 11:40:56 +0900 Subject: [PATCH 16/16] mv3d: update depth_test_suite.cpp to select disparity or depth [Version]: 0.23.37-0 [Issue type]: update Change-Id: If782905b32fb2057d1b1c42c3c4438639438dac4 Signed-off-by: Tae-Young Chung --- packaging/capi-media-vision.spec | 2 +- test/testsuites/mv3d/depth_test_suite.cpp | 68 +++++++++++++++++++++---------- 2 files changed, 47 insertions(+), 23 deletions(-) diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 60cb16c..0f015d9 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.36 +Version: 0.23.37 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause diff --git a/test/testsuites/mv3d/depth_test_suite.cpp b/test/testsuites/mv3d/depth_test_suite.cpp index 100e976..b5c964e 100644 --- a/test/testsuites/mv3d/depth_test_suite.cpp +++ b/test/testsuites/mv3d/depth_test_suite.cpp @@ -51,6 +51,8 @@ static const char *dataset[] = { "Adirondack", "Jadeplant", "Motorcycle", "Pian "Cable", "Classroom1", "Couch", "Flowers", "Mask", "Shopvac", "Sticks", "Storage", "Sword1", "Sword2", "Umbrella" }; +enum DistanceMode { DISTANCE_DEPTH, DISTANCE_DISPARITY }; + class StopWatch { public: @@ -77,8 +79,10 @@ typedef struct _appdata std::string datasetName; float minDisp; float maxDisp; + float depth2Disp; int fmt; std::string dataset; + DistanceMode distanceMode; } appdata; enum @@ -94,8 +98,8 @@ static int littleendian() return uval[0] == 1; } -static void WriteFilePFM(float *data, int width, int height, const char *filename, float minDisp, float maxDisp, - float scalefactor = 1 / 255.0) +static void WriteFilePFM(unsigned short *data, int width, int height, const char *filename, float minDisp, float maxDisp, + float depth2Disp, DistanceMode distanceMode, float scalefactor = 1 / 255.0) { FILE *stream = fopen(filename, "wb"); if (stream == 0) { @@ -108,19 +112,21 @@ static void WriteFilePFM(float *data, int width, int height, const char *filenam fprintf(stream, "Pf\n%d %d\n%f\n", width, height, scalefactor); - int n = width; + std::vector dump(width); for (int y = height - 1; y >= 0; y--) { - float *ptr = data + y * width; + unsigned short* ptr = data + y * width; for (int x = 0; x < width; x++) { - if (ptr[x] <= 0 || ptr[x] > maxDisp) { //xsh modified - ptr[x] = INFINITY; - } + if (distanceMode == DISTANCE_DISPARITY) + dump[x] = depth2Disp / static_cast(ptr[x]); + else + dump[x] = static_cast(ptr[x]); } - if ((int) fwrite(ptr, sizeof(float), n, stream) != n) { + if ((int)fwrite(dump.data(), sizeof(float), width, stream) != width) { fprintf(stderr, "WriteFilePFM: problem writing data\n"); exit(1); } } + fclose(stream); } @@ -140,7 +146,7 @@ static void jet(float x, int &r, int &g, int &b) } static void WriteFilePNG(unsigned short *data, int width, int height, const char *filename, float minDisp, - float maxDisp) + float maxDisp, float depth2Disp, int distanceMode) { // Open the file FILE *stream = fopen(filename, "wb"); @@ -152,15 +158,16 @@ static void WriteFilePNG(unsigned short *data, int width, int height, const char cv::Mat dump(cv::Size(width, height), CV_16U); for (int y = 0; y < height; y++) { - unsigned short *ptr = data + y * width; + unsigned short* ptr = data + y * width; for (int x = 0; x < width; x++) { - unsigned short f = ptr[x]; - dump.at(y, x) = f; + if (distanceMode == DISTANCE_DISPARITY) + dump.at(y,x) = static_cast(depth2Disp / static_cast(ptr[x])); + else + dump.at(y,x) = ptr[x]; } - } + } - printf("%d x %d", width, height); cv::imwrite(filename, dump); fclose(stream); @@ -198,10 +205,11 @@ static void _depth_middlebury_cb(mv_source_h source, unsigned short *depth, unsi StopWatch stopWatch; if (udata->fmt == FMT_PFM) { - WriteFilePFM(reinterpret_cast(depth), width, height, udata->datasetName.c_str(), udata->minDisp, - udata->maxDisp); + WriteFilePFM(depth, width, height, udata->datasetName.c_str(), + udata->minDisp, udata->maxDisp, udata->depth2Disp, udata->distanceMode); } else { - WriteFilePNG(depth, width, height, udata->datasetName.c_str(), udata->minDisp, udata->maxDisp); + WriteFilePNG(depth, width, height, udata->datasetName.c_str(), + udata->minDisp, udata->maxDisp, udata->depth2Disp, udata->distanceMode); } udata->diffMs = stopWatch.elapsedTime(); @@ -259,6 +267,12 @@ int perform_middlebury_test() sel_fmt = show_menu_linear("Select Action", formats, ARRAY_SIZE(formats)); } + const char* distances[] = {"disparty", "depth"}; + int sel_distance = -1; + while (sel_distance <= 0 || sel_distance > ARRAY_SIZE(distances)) { + sel_distance = show_menu_linear("Select Action", distances, ARRAY_SIZE(distances)); + } + err = mv_create_engine_config(&engine_config); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to create engine config\n"); @@ -304,7 +318,10 @@ int perform_middlebury_test() float fVal; float dmin = 0, dmax = 0; int iVal; + float fx = 0.f; + float baseline = 0.0f; int width = 0, height = 0; + if (fp != NULL) { while (fgets(line, MAX_STRING_LENGTH, fp) != NULL) { if (sscanf(line, "vmin= %f", &fVal) == 1) @@ -315,6 +332,10 @@ int perform_middlebury_test() width = iVal; if (sscanf(line, "height= %d", &iVal) == 1) height = iVal; + if (sscanf(line, "cam0=[ %f", &fVal) == 1) + fx = fVal; + if (sscanf(line, "baseline= %f", &fVal) == 1) + baseline = fVal; } fclose(fp); } else { @@ -390,13 +411,13 @@ int perform_middlebury_test() } // left_source, right_source - left_frame = cv::imread(leftFilename, cv::IMREAD_COLOR); - right_frame = cv::imread(rightFilename, cv::IMREAD_COLOR); + left_frame = cv::imread(leftFilename, cv::IMREAD_GRAYSCALE); + right_frame = cv::imread(rightFilename, cv::IMREAD_GRAYSCALE); err = mv_source_fill_by_buffer(left_source, left_frame.ptr(), left_frame.elemSize() * left_frame.size().width * left_frame.size().height, left_frame.size().width, left_frame.size().height, - MEDIA_VISION_COLORSPACE_RGB888); + MEDIA_VISION_COLORSPACE_Y800); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to fill left_source\n"); goto _err; @@ -405,7 +426,7 @@ int perform_middlebury_test() err = mv_source_fill_by_buffer(right_source, right_frame.ptr(), right_frame.elemSize() * right_frame.size().width * right_frame.size().height, right_frame.size().width, right_frame.size().height, - MEDIA_VISION_COLORSPACE_RGB888); + MEDIA_VISION_COLORSPACE_Y800); if (err != MEDIA_VISION_ERROR_NONE) { printf("Failed to fill right_source\n"); goto _err; @@ -431,8 +452,11 @@ int perform_middlebury_test() std::string(dataPath) + std::string("/disp0") + std::string(suffix_for_algo), static_cast(minDisp), static_cast(maxDisp), + fx * baseline, sel_fmt, - std::string(dataset[data]) }; + std::string(dataset[data]), + static_cast(sel_distance) }; + printf("fx:%f, baseline:%f, d2d: %f\n", fx, baseline, dump.depth2Disp); dump.datasetName += sel_fmt == FMT_PFM ? std::string(".pfm") : std::string(".png"); err = mv_3d_set_depth_cb(mv3d_handle, _depth_middlebury_cb, static_cast(&dump)); -- 2.7.4