Add remote display to depth_test_suite 33/284033/2
authorTae-Young Chung <ty83.chung@samsung.com>
Mon, 7 Nov 2022 06:47:18 +0000 (15:47 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Wed, 9 Nov 2022 06:57:23 +0000 (06:57 +0000)
[Issue type] update

Change-Id: I25be56bb0ed0c43e6f4d6c4d25427d646c84eb2d
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
(cherry picked from commit 2ad486adc76cda768ac593d9e9b2e9d152ad05a3)

test/testsuites/mv3d/depth_test_suite.cpp

index b5c964e..2a312e6 100644 (file)
@@ -36,6 +36,7 @@
 
 #define MEDIA_FILE_PATH "/opt/usr/home/owner/media/Images"
 #ifdef BUILD_VISUALIZER
+#include "mv_util_visualizer_2d.h"
 #include "mv_util_visualizer_3d.h"
 #endif
 
@@ -83,12 +84,16 @@ typedef struct _appdata
        int fmt;
        std::string dataset;
        DistanceMode distanceMode;
+       std::string remoteUrl;
+       mv_source_h remoteSource;
+       unsigned char *remoteDataBuffer;
 } appdata;
 
 enum
 {
        FMT_PFM = 1,
-       FMT_PNG
+       FMT_PNG,
+       FMT_REMOTE
 };
 
 static int littleendian()
@@ -173,6 +178,33 @@ static void WriteFilePNG(unsigned short *data, int width, int height, const char
        fclose(stream);
 }
 
+static void SendDataToRemoteUrl(unsigned short *data, int width, int height, float minDisp, float maxDips, float depth2Disp,
+                                               std::string url, mv_source_h source, unsigned char *buffer)
+{
+#if BUILD_VISUALIZER
+       int r, g, b;
+       for (int y = 0; y < height; y++) {
+               unsigned short* src = data + y * width;
+               unsigned char*  dst = buffer + y * (width * 4);
+               for (int x = 0; x < width; x++) {
+                       jet((depth2Disp / static_cast<float>(src[x]) - minDisp) / (maxDips - minDisp), r, g, b);
+                       dst[x*4] = r;
+                       dst[x*4 + 1] = g;
+                       dst[x*4 + 2] = b;
+                       dst[x*4 + 3] = 255;
+               }
+    }
+
+       mv_source_fill_by_buffer(source, buffer, width * height * 4, width, height, MEDIA_VISION_COLORSPACE_RGBA);
+
+       mv_util_visualizer_2d(source, url.c_str());
+
+       mv_source_clear(source);
+
+       sleep(3);
+#endif
+}
+
 static void WritePLY(double *data, int size, const char *filename)
 {
        std::ofstream stream(filename, std::ofstream::out);
@@ -207,9 +239,12 @@ static void _depth_middlebury_cb(mv_source_h source, unsigned short *depth, unsi
        if (udata->fmt == FMT_PFM) {
                WriteFilePFM(depth, width, height, udata->datasetName.c_str(),
                        udata->minDisp, udata->maxDisp, udata->depth2Disp, udata->distanceMode);
-       } else {
+       } else if (udata->fmt == FMT_PNG) {
                WriteFilePNG(depth, width, height, udata->datasetName.c_str(),
                        udata->minDisp, udata->maxDisp, udata->depth2Disp, udata->distanceMode);
+       } else {
+               SendDataToRemoteUrl(depth, width, height, udata->minDisp, udata->maxDisp, udata->depth2Disp,
+                                               udata->remoteUrl, udata->remoteSource, udata->remoteDataBuffer);
        }
 
        udata->diffMs = stopWatch.elapsedTime();
@@ -245,6 +280,7 @@ int perform_middlebury_test()
 {
        char *path_to_dataset = NULL;
        char *suffix_for_algo = NULL;
+       char *remote_url = NULL;
        int err = MEDIA_VISION_ERROR_NONE;
        mv_engine_config_h engine_config = NULL;
        mv_source_h left_source = NULL;
@@ -261,7 +297,12 @@ int perform_middlebury_test()
                printf("Incorrect! Try again.\n");
        }
 
+#if BUILD_VISUALIZER
+       const char *formats[] = { "pfm", "png", "remote display" };
+#else
        const char *formats[] = { "pfm", "png" };
+#endif
+
        int sel_fmt = -1;
        while (sel_fmt <= 0 || sel_fmt > static_cast<int>(ARRAY_SIZE(formats))) {
                sel_fmt = show_menu_linear("Select Action", formats, ARRAY_SIZE(formats));
@@ -269,8 +310,14 @@ int perform_middlebury_test()
 
        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));
+       if (sel_fmt == FMT_REMOTE) {
+               while (input_string("remote url where you send:", 1024, &remote_url) == -1) {
+                       printf("Incorrect! Try again.\n");
+               }
+       } else {
+               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);
@@ -455,10 +502,39 @@ int perform_middlebury_test()
                                           fx * baseline,
                                           sel_fmt,
                                           std::string(dataset[data]),
-                                          static_cast<DistanceMode>(sel_distance) };
+                                          static_cast<DistanceMode>(sel_distance),
+                                          std::string(remote_url),
+                                          nullptr,
+                                          nullptr };
                printf("fx:%f, baseline:%f, d2d: %f\n", fx, baseline, dump.depth2Disp);
                dump.datasetName += sel_fmt == FMT_PFM ? std::string(".pfm") : std::string(".png");
 
+               if (sel_fmt == FMT_REMOTE) {
+                       err = mv_create_source(&dump.remoteSource);
+                       if (err != MEDIA_VISION_ERROR_NONE) {
+
+                               printf("Failed to create remote source handle\n");
+                               if (dump.remoteSource) {
+                                       mv_destroy_source(dump.remoteSource);
+                               }
+                               goto _err;
+                       }
+
+                       dump.remoteDataBuffer = new(std::nothrow)unsigned char[width * height * 4];
+                       if (!dump.remoteDataBuffer) {
+                               printf("Failed to allocate remote data buffer\nn");
+
+                               if (dump.remoteSource) {
+                                       mv_destroy_source(dump.remoteSource);
+                               }
+
+                               if (dump.remoteDataBuffer) {
+                                       delete [] dump.remoteDataBuffer;
+                               }
+                               goto _err;
+                       }
+               }
+
                err = mv_3d_set_depth_cb(mv3d_handle, _depth_middlebury_cb, static_cast<void *>(&dump));
                if (err != MEDIA_VISION_ERROR_NONE) {
                        printf("Failed to set depth callback to handle\n");
@@ -466,7 +542,7 @@ int perform_middlebury_test()
                }
 
                err = mv_3d_set_pointcloud_cb(mv3d_handle, _pointcloud_middlebury_cb, static_cast<void *>(&dump));
-               if (err != MEDIA_VISION_ERROR_NONE) {
+               if (err != MEDIA_VISION_ERROR_NONE && err != MEDIA_VISION_ERROR_NOT_SUPPORTED) {
                        printf("Failed to set pointcloud callback to handle\n");
                        goto _err;
                }