[Face/Barcode] Handle Error return 36/258136/7
authorHyunsoo Park <hance.park@samsung.com>
Tue, 11 May 2021 06:07:53 +0000 (15:07 +0900)
committerHyunsoo Park <hance.park@samsung.com>
Thu, 13 May 2021 02:36:13 +0000 (11:36 +0900)
Change-Id: Ia1fcefc4b567fb67924113b64c9ac22ccc6094d9
Signed-off-by: Hyunsoo Park <hance.park@samsung.com>
test/assessment/barcode/assessment_barcode.cpp
test/assessment/face/assessment_face.cpp

index fd4e14b..9e69292 100644 (file)
@@ -25,6 +25,8 @@
 
 #include <error.h>
 #include <argp.h>
+#include <iostream>
+#include <chrono>
 
 #define MAX_ARGS 2
 
@@ -111,7 +113,7 @@ void barcode_detected_cb(
        MEDIA_VISION_FUNCTION_LEAVE();
 }
 
-void perform_detect(struct arguments *arguments)
+int perform_detect(struct arguments *arguments)
 {
        MEDIA_VISION_FUNCTION_ENTER();
 
@@ -123,8 +125,9 @@ void perform_detect(struct arguments *arguments)
        unsigned int image_height = 0;
        int int_value = MV_BARCODE_DETECT_ATTR_TARGET_ALL;
        mv_rectangle_s roi = { {0, 0}, 0, 0 };
+       int err = MEDIA_VISION_ERROR_NONE;
 
-       int err = load_image_to_buffer(arguments->source,
+       err = load_image_to_buffer(arguments->source,
                        &data_buffer, &buffer_size, &image_width, &image_height);
 
        if (MEDIA_VISION_ERROR_NONE != err) {
@@ -133,8 +136,10 @@ void perform_detect(struct arguments *arguments)
        }
 
        err = mv_create_engine_config(&mv_engine_config);
-       if (MEDIA_VISION_ERROR_NONE != err)
+       if (MEDIA_VISION_ERROR_NONE != err) {
                LOGE("Errors were occurred during creating the media engine config : %i", err);
+               goto out;
+       }
 
        if (MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE ==
                mv_engine_config_get_int_attribute(
@@ -160,9 +165,8 @@ void perform_detect(struct arguments *arguments)
        roi.width = image_width;
        roi.height = image_height;
        err = mv_barcode_detect(source, mv_engine_config, roi, barcode_detected_cb, NULL);
-       if (MEDIA_VISION_ERROR_NONE != err) {
+       if (MEDIA_VISION_ERROR_NONE != err)
                LOGE("Errors were occurred during barcode detection!!! code : %i", err);
-       }
 out:
        if (MEDIA_VISION_ERROR_NONE != err)
                printf("-1\n");
@@ -187,6 +191,7 @@ out:
        }
 
        MEDIA_VISION_FUNCTION_LEAVE();
+       return err;
 }
 
 static error_t parse_opt (int key, char *arg, struct argp_state *state)
@@ -223,13 +228,13 @@ int main(int argc, char *argv[])
        struct arguments arguments;
        argp_parse (&argp, argc, argv, 0, 0, &arguments);
 
-       clock_gettime(CLOCK_MONOTONIC, &s_tspec);
-       perform_detect(&arguments);
-       clock_gettime(CLOCK_MONOTONIC, &e_tspec);
+       std::chrono::system_clock::time_point StartTime = std::chrono::system_clock::now();
+       int err = perform_detect(&arguments);
+       std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - StartTime);
+       std::cout << ms.count() << "ms" << std::endl;
 
-       struct timespec diffspec = diff(s_tspec, e_tspec);
-       unsigned long timeDiff = gettotalmillisec(diffspec);
-       printf("%lums\n", timeDiff);
+       if (err != MEDIA_VISION_ERROR_NONE)
+               printf("ERROR: Action is finished with error code: %i\n", err);
 
        LOGI("Media Vision Assessment-Barcode is closed.");
 
index f94ebda..bbaa0e5 100644 (file)
@@ -26,6 +26,8 @@
 
 #include <error.h>
 #include <argp.h>
+#include <iostream>
+#include <chrono>
 
 #define MAX_ARGS 3
 
@@ -119,7 +121,7 @@ int load_image_to_buffer(char *source,
        return MEDIA_VISION_ERROR_NONE;
 }
 
-void perform_detect(struct arguments *arguments)
+int perform_detect(struct arguments *arguments)
 {
        MEDIA_VISION_FUNCTION_ENTER();
 
@@ -139,8 +141,10 @@ void perform_detect(struct arguments *arguments)
        }
 
        err = mv_create_engine_config(&mv_engine_config);
-       if (MEDIA_VISION_ERROR_NONE != err)
+       if (MEDIA_VISION_ERROR_NONE != err) {
                LOGE("Errors were occurred during creating the media engine config : %i", err);
+               goto out;
+       }
 
        mv_engine_config_set_string_attribute(
                                mv_engine_config,
@@ -161,9 +165,9 @@ void perform_detect(struct arguments *arguments)
        }
 
        err = mv_face_detect(source, mv_engine_config, on_face_detected_cb, NULL);
-       if (MEDIA_VISION_ERROR_NONE != err) {
+       if (MEDIA_VISION_ERROR_NONE != err)
                LOGE("Errors were occurred during face detection!!! code : %i", err);
-       }
+
 out:
        if (MEDIA_VISION_ERROR_NONE != err)
                printf("-1\n");
@@ -183,6 +187,7 @@ out:
        }
 
        MEDIA_VISION_FUNCTION_LEAVE();
+       return err;
 }
 
 static error_t parse_opt (int key, char *arg, struct argp_state *state)
@@ -216,21 +221,18 @@ static struct argp argp = { NULL, parse_opt, args_doc, doc };
 
 int main(int argc, char *argv[])
 {
-       struct timespec s_tspec;
-       struct timespec e_tspec;
-
        LOGI("Media Vision Assessment-Face is launched.");
 
        struct arguments arguments;
        argp_parse (&argp, argc, argv, 0, 0, &arguments);
 
-       clock_gettime(CLOCK_MONOTONIC, &s_tspec);
-       perform_detect(&arguments);
-       clock_gettime(CLOCK_MONOTONIC, &e_tspec);
+       std::chrono::system_clock::time_point StartTime = std::chrono::system_clock::now();
+       int err = perform_detect(&arguments);
+       std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - StartTime);
+       std::cout << ms.count() << "ms" << std::endl;
 
-       struct timespec diffspec = diff(s_tspec, e_tspec);
-       unsigned long timeDiff = gettotalmillisec(diffspec);
-       printf("%lums\n", timeDiff);
+       if (err != MEDIA_VISION_ERROR_NONE)
+               printf("ERROR: Action is finished with error code: %i\n", err);
 
        LOGI("Media Vision Assessment-Face is closed.");