mv_machine_learning: add verifying result data
authorsangho park <sangho.g.park@samsung.com>
Wed, 22 Nov 2023 23:27:21 +0000 (08:27 +0900)
committerKwanghoon Son <k.son@samsung.com>
Wed, 6 Dec 2023 01:36:46 +0000 (10:36 +0900)
[Issue type] code improvement

verifying result data of selfie-segmentation external plugin
by restoring result data to opencv Mat and storing image file

Change-Id: I13a6f18a9bf8ec45b78fd2ae57f7e33c54c185fc
Signed-off-by: sangho park <sangho.g.park@samsung.com>
test/testsuites/machine_learning/image_segmentation/test_selfie_segmentation.cpp

index d016658..1723c2e 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <fstream>
 #include <iostream>
 #include <algorithm>
 #include <string.h>
@@ -23,6 +24,7 @@
 #include "ImageHelper.h"
 #include "mv_selfie_segmentation_internal.h"
 
+#define GROUND_TRUTH TEST_RES_PATH "/res/inference/images/faceSegmentationGT.bin"
 #define IMG_FACE TEST_RES_PATH "/res/inference/images/faceDetection.jpg"
 
 using namespace testing;
@@ -77,9 +79,13 @@ TEST(ImageSegmentationTest, DISABLED_InferenceShouldBeOk)
                ret = mv_selfie_segmentation_get_result(handle, &width, &height, &pixel_size, &data);
                ASSERT_EQ(ret, 0);
 
-               cout << "width = " << width << " height = " << height << " pixel size = " << pixel_size << endl;
+               streamsize length = static_cast<uintmax_t>(width * height * pixel_size);
+               ifstream fin(GROUND_TRUTH, ios::binary);
+               vector<char> buf(length);
 
-               // TODO. update how to verify the data.
+               fin.read(buf.data(), length);
+               ASSERT_TRUE(fin);
+               ASSERT_TRUE(memcmp(data, buf.data(), width * height * pixel_size) == 0);
 
                ret = mv_selfie_segmentation_destroy(handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
@@ -87,4 +93,4 @@ TEST(ImageSegmentationTest, DISABLED_InferenceShouldBeOk)
 
        ret = mv_destroy_source(mv_source);
        ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
-}
\ No newline at end of file
+}