test: Move load image function to helper 41/262441/1
authorKwang Son <k.son@samsung.com>
Wed, 11 Aug 2021 02:02:26 +0000 (22:02 -0400)
committerKwang Son <k.son@samsung.com>
Wed, 11 Aug 2021 02:02:26 +0000 (22:02 -0400)
ImageHelper already has similar function.

Change-Id: Ibeecaf6ba387a1504811c70423f9d7b216cec154
Signed-off-by: Kwang Son <k.son@samsung.com>
test/testsuites/common/image_helper/include/ImageHelper.h
test/testsuites/common/image_helper/src/ImageHelper.cpp
test/testsuites/machine_learning/inference/test_image_classification.cpp
test/testsuites/machine_learning/inference/test_inference_helper.cpp
test/testsuites/machine_learning/inference/test_inference_helper.hpp

index 9e3102f..a2e01bd 100644 (file)
@@ -77,6 +77,8 @@ public:
                        unsigned long *pBufferSize,
                        ImageData *pImageData);
 
+       static int loadImageToSource(const char *filePath, mv_source_h source);
+
        /**
         * @brief Saves image stored into @a pDataBuffer to the file in jpeg format.
         *
index d4fb4cd..fa123cc 100644 (file)
@@ -87,6 +87,34 @@ int ImageHelper::loadImageToBuffer(
        return MEDIA_VISION_ERROR_NONE;
 }
 
+int ImageHelper::loadImageToSource(const char *filePath, mv_source_h source)
+{
+       unsigned char *data_buffer = NULL;
+       unsigned long buffer_size = 0;
+       ImageData image_data;
+
+       int err = loadImageToBuffer(filePath, &data_buffer, &buffer_size,
+                                                               &image_data);
+       if (MEDIA_VISION_ERROR_NONE != err) {
+               printf("ERROR: Errors were occurred during opening file!!! code: %i\n",
+                          err);
+               return err;
+       }
+
+       err = mv_source_fill_by_buffer(source, data_buffer, buffer_size,
+                                                                  image_data.imageWidth,
+                                                                  image_data.imageHeight,
+                                                                  image_data.imageColorspace);
+
+       if (MEDIA_VISION_ERROR_NONE != err)
+               printf("ERROR: Errors were occurred during filling source!!! code %i\n",
+                          err);
+
+       if (NULL != data_buffer)
+               destroyLoadedBuffer(data_buffer);
+       return err;
+}
+
 int ImageHelper::saveImageFromBuffer(
                const char *filePath,
                unsigned char *pDataBuffer,
index 979ebfa..96f8075 100644 (file)
@@ -1,4 +1,5 @@
 #include <gtest/gtest.h>
+#include <ImageHelper.h>
 #include "test_inference_helper.hpp"
 
 #define IC_LABEL_MOBILENET_V1_224_PATH \
@@ -49,10 +50,11 @@ TEST_F(TestImageClassification, CPU_TFLITE_MobilenetV1)
        EXPECT_EQ(mv_inference_configure(infer, engine_cfg),
                          MEDIA_VISION_ERROR_NONE);
        EXPECT_EQ(mv_inference_prepare(infer), MEDIA_VISION_ERROR_NONE);
-       EXPECT_EQ(load_mv_source_from_file(mv_source, IMG_BANANA),
+       EXPECT_EQ(MediaVision::Common::ImageHelper::loadImageToSource(IMG_BANANA,
+                                                                                                                                 mv_source),
                          MEDIA_VISION_ERROR_NONE);
        EXPECT_EQ(mv_inference_image_classify(mv_source, infer, NULL,
                                                                                  _image_classified_cb, NULL),
                          MEDIA_VISION_ERROR_NONE);
        EXPECT_EQ(mv_source_clear(mv_source), MEDIA_VISION_ERROR_NONE);
-}
\ No newline at end of file
+}
index 9700001..4fc1038 100644 (file)
@@ -27,36 +27,3 @@ void engine_config_hosted_cpu_tflite_user_model(mv_engine_config_h handle,
                                          handle, MV_INFERENCE_MODEL_USER_FILE_PATH, user_file),
                          MEDIA_VISION_ERROR_NONE);
 }
-
-// TODO: memcpy twice to one time
-int load_mv_source_from_file(mv_source_h source, const char *path_to_image)
-{
-       unsigned char *data_buffer = NULL;
-       unsigned long buffer_size = 0;
-       image_data_s image_data;
-
-       int err = load_image_to_buffer(path_to_image, &data_buffer, &buffer_size,
-                                                                  &image_data);
-       if (MEDIA_VISION_ERROR_NONE != err) {
-               printf("ERROR: Errors were occurred during opening file!!! code: %i\n",
-                          err);
-               if (NULL != data_buffer)
-                       destroy_loaded_buffer(data_buffer);
-
-               return err;
-       }
-
-       err = mv_source_fill_by_buffer(source, data_buffer, buffer_size,
-                                                                  image_data.image_width,
-                                                                  image_data.image_height,
-                                                                  image_data.image_colorspace);
-
-       if (MEDIA_VISION_ERROR_NONE != err)
-               printf("ERROR: Errors were occurred during filling source!!! code %i\n",
-                          err);
-
-       if (NULL != data_buffer)
-               destroy_loaded_buffer(data_buffer);
-
-       return err;
-}
index 4d1f679..05cab7a 100644 (file)
@@ -10,6 +10,4 @@ void engine_config_hosted_cpu_tflite_user_model(mv_engine_config_h handle,
                                                                                                const char *tf_weight,
                                                                                                const char *user_file);
 
-int load_mv_source_from_file(mv_source_h source, const char *path_to_image);
-
-#endif //__TEST_INFERENCE_HELPER_HPP__
\ No newline at end of file
+#endif //__TEST_INFERENCE_HELPER_HPP__