mv_3d: bug fix in mv_depth_test_suite and minor changes
authorTae-Young Chung <ty83.chung@samsung.com>
Mon, 24 Apr 2023 05:56:39 +0000 (14:56 +0900)
committerKwanghoon Son <k.son@samsung.com>
Wed, 14 Jun 2023 02:14:14 +0000 (11:14 +0900)
[Version] 0.28.1
[Issue type] bug fix and update

if remote_url isn't given, it throws "an instance of 'std::logic_error'
" with "basic_string::_M_construct null not valid" message. That bug is
fixed. In addition, new command menu is added to select three types stereo formats.

Change-Id: I1fc444bead38dde47754b710a24b31c5d4c85cbe
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
test/testsuites/mv3d/depth_test_suite.cpp

index a29a50c..40ab602 100644 (file)
@@ -52,7 +52,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 };
+enum DistanceMode { DISTANCE_DISPARITY = 1, DISTANCE_DEPT };
+enum StereoFormat { STEREO_DECOUPLE = 1, STEREO_COUPLE_SBS, STEREO_COUPLE_TB };
 
 class StopWatch
 {
@@ -280,11 +281,11 @@ int perform_middlebury_test()
        char *remote_url = NULL;
        int err = MEDIA_VISION_ERROR_NONE;
        mv_engine_config_h engine_config = NULL;
-       mv_source_h left_source = NULL;
-       mv_source_h right_source = NULL;
+       mv_source_h base_source = NULL;
+       mv_source_h extra_source = NULL;
        mv_3d_h mv3d_handle = NULL;
        size_t datasize = ARRAY_SIZE(dataset);
-       cv::Mat left_frame, right_frame;
+       cv::Mat base_frame, extra_frame;
 
        while (input_string("root path including dataset:", 1024, &path_to_dataset) == -1) {
                printf("Incorrect! Try again.\n");
@@ -317,22 +318,30 @@ int perform_middlebury_test()
                }
        }
 
+       const char *stereo_format[] = { "Stereo Decouple", "Stereo Couple SBS", "Stereo Copule TB" };
+       int st_format = -1;
+       while (st_format <= 0 || st_format > static_cast<int>(ARRAY_SIZE(stereo_format))) {
+               st_format = show_menu_linear("Select Action", stereo_format, ARRAY_SIZE(stereo_format));
+       }
+
        err = mv_create_engine_config(&engine_config);
        if (err != MEDIA_VISION_ERROR_NONE) {
                printf("Failed to create engine config\n");
                goto _err;
        }
 
-       err = mv_create_source(&left_source);
+       err = mv_create_source(&base_source);
        if (err != MEDIA_VISION_ERROR_NONE) {
-               printf("Failed to create left source\n");
+               printf("Failed to create base source\n");
                goto _err;
        }
 
-       err = mv_create_source(&right_source);
-       if (err != MEDIA_VISION_ERROR_NONE) {
-               printf("Failed to create right source\n");
-               goto _err;
+       if (st_format == STEREO_DECOUPLE) {
+               err = mv_create_source(&extra_source);
+               if (err != MEDIA_VISION_ERROR_NONE) {
+                       printf("Failed to create extra source\n");
+                       goto _err;
+               }
        }
 
        for (size_t data = 0; data < datasize; ++data) {
@@ -455,24 +464,47 @@ int perform_middlebury_test()
                }
 
                // left_source, right_source
-               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<unsigned char>(),
-                                                                          left_frame.elemSize() * left_frame.size().width * left_frame.size().height,
-                                                                          left_frame.size().width, left_frame.size().height, MEDIA_VISION_COLORSPACE_Y800);
-               if (err != MEDIA_VISION_ERROR_NONE) {
-                       printf("Failed to fill left_source\n");
-                       goto _err;
-               }
+               cv::Mat left_frame = cv::imread(leftFilename, cv::IMREAD_GRAYSCALE);
+               cv::Mat right_frame = cv::imread(rightFilename, cv::IMREAD_GRAYSCALE);
+
+               if (st_format == STEREO_COUPLE_SBS) {
+                       cv::hconcat(left_frame, right_frame, base_frame);
+                       err = mv_source_fill_by_buffer(base_source, base_frame.ptr<unsigned char>(),
+                                                                                  base_frame.elemSize() * base_frame.size().width * base_frame.size().height,
+                                                                                  base_frame.size().width, base_frame.size().height,
+                                                                                  MEDIA_VISION_COLORSPACE_Y800);
+                       if (err != MEDIA_VISION_ERROR_NONE) {
+                               printf("Failed to fill base_source\n");
+                               goto _err;
+                       }
+               } else if (st_format == STEREO_COUPLE_TB) {
+                       cv::vconcat(left_frame, right_frame, base_frame);
+                       err = mv_source_fill_by_buffer(base_source, base_frame.ptr<unsigned char>(),
+                                                                                  base_frame.elemSize() * base_frame.size().width * base_frame.size().height,
+                                                                                  base_frame.size().width, base_frame.size().height,
+                                                                                  MEDIA_VISION_COLORSPACE_Y800);
+                       if (err != MEDIA_VISION_ERROR_NONE) {
+                               printf("Failed to fill base_source\n");
+                               goto _err;
+                       }
+               } else {
+                       err = mv_source_fill_by_buffer(base_source, left_frame.ptr<unsigned char>(),
+                                                                                  left_frame.elemSize() * left_frame.size().width * left_frame.size().height,
+                                                                                  left_frame.size().width, left_frame.size().height,
+                                                                                  MEDIA_VISION_COLORSPACE_Y800);
+                       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<unsigned char>(),
-                                                                          right_frame.elemSize() * right_frame.size().width * right_frame.size().height,
-                                                                          right_frame.size().width, right_frame.size().height,
-                                                                          MEDIA_VISION_COLORSPACE_Y800);
-               if (err != MEDIA_VISION_ERROR_NONE) {
-                       printf("Failed to fill right_source\n");
-                       goto _err;
+                       err = mv_source_fill_by_buffer(
+                                       extra_source, right_frame.ptr<unsigned char>(),
+                                       right_frame.elemSize() * right_frame.size().width * right_frame.size().height,
+                                       right_frame.size().width, right_frame.size().height, MEDIA_VISION_COLORSPACE_Y800);
+                       if (err != MEDIA_VISION_ERROR_NONE) {
+                               printf("Failed to fill right_source\n");
+                               goto _err;
+                       }
                }
 
                // depth_handle
@@ -499,7 +531,7 @@ int perform_middlebury_test()
                                           sel_fmt,
                                           std::string(dataset[data]),
                                           static_cast<DistanceMode>(sel_distance),
-                                          std::string(remote_url),
+                                          remote_url != NULL ? std::string(remote_url) : std::string(),
                                           nullptr,
                                           nullptr };
                printf("fx:%f, baseline:%f, d2d: %f\n", fx, baseline, dump.depth2Disp);
@@ -549,7 +581,7 @@ int perform_middlebury_test()
                }
 
                StopWatch stopWatch;
-               err = mv_3d_run(mv3d_handle, left_source, right_source, NULL);
+               err = mv_3d_run(mv3d_handle, base_source, extra_source, NULL);
 
                /* time to save a file is excluded */
                std::chrono::milliseconds diffMs = stopWatch.elapsedTime() - dump.diffMs;
@@ -570,11 +602,11 @@ _err:
        if (engine_config)
                mv_destroy_engine_config(engine_config);
 
-       if (left_source)
-               mv_destroy_source(left_source);
+       if (base_source)
+               mv_destroy_source(base_source);
 
-       if (right_source)
-               mv_destroy_source(right_source);
+       if (extra_source)
+               mv_destroy_source(extra_source);
 
        if (mv3d_handle)
                mv_3d_destroy(mv3d_handle);