create new test directories for VQA (Visual Quality Assessment) 48/255248/6
authorsangho park <sangho.g.park@samsung.com>
Mon, 15 Mar 2021 22:59:35 +0000 (07:59 +0900)
committersangho park <sangho.g.park@samsung.com>
Tue, 23 Mar 2021 02:16:19 +0000 (11:16 +0900)
New directories
 - assessment

I plan to work with barcode and add the rest.

Change-Id: I948d53fa60215c8124e5e4a503dc8e4c7989bce0
Signed-off-by: sangho park <sangho.g.park@samsung.com>
test/CMakeLists.txt
test/assessment/CMakeLists.txt [new file with mode: 0644]
test/assessment/barcode/CMakeLists.txt [new file with mode: 0644]
test/assessment/barcode/test_barcode.cpp [new file with mode: 0644]

index 8637790..e3743d0 100644 (file)
@@ -2,4 +2,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 
 SET(testbin_dir ${TZ_SYS_BIN})
 
+ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/test/assessment)
 ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/test/testsuites)
diff --git a/test/assessment/CMakeLists.txt b/test/assessment/CMakeLists.txt
new file mode 100644 (file)
index 0000000..bac344c
--- /dev/null
@@ -0,0 +1,4 @@
+project(mv_test_assessment)
+cmake_minimum_required(VERSION 2.6)
+
+add_subdirectory(${PROJECT_SOURCE_DIR}/barcode)
diff --git a/test/assessment/barcode/CMakeLists.txt b/test/assessment/barcode/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a318365
--- /dev/null
@@ -0,0 +1,27 @@
+cmake_minimum_required(VERSION 2.6)
+SET(fw_name "mv_barcode_test_assessment")
+
+PROJECT(${fw_name})
+
+set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG _DEBUG)
+
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${LIB_INSTALL_DIR})
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${LIB_INSTALL_DIR})
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${MV_CAPI_MEDIA_VISION_INC_DIR})
+
+FILE(GLOB MV_TEST_ASSESSMENT_SRC_LIST "${PROJECT_SOURCE_DIR}/test_barcode.cpp")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE")
+
+ADD_EXECUTABLE(${PROJECT_NAME} ${MV_TEST_ASSESSMENT_SRC_LIST} ${MV_TEST_ASSESSMENT_INC_LIST} ${MV_CAPI_MEDIA_VISION_INC_LIST})
+
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${MV_BARCODE_DETECTOR_LIB_NAME}
+                                      ${${fw_name}_LDFLAGS}
+                                      ${MV_BARCODE_GENERATOR_LIB_NAME}
+                                      dlog
+                                      )
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${testbin_dir})
diff --git a/test/assessment/barcode/test_barcode.cpp b/test/assessment/barcode/test_barcode.cpp
new file mode 100644 (file)
index 0000000..03e6399
--- /dev/null
@@ -0,0 +1,259 @@
+/**
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <mv_barcode.h>
+#include <mv_private.h>
+
+#include <opencv2/core.hpp>
+#include <opencv2/highgui.hpp>
+#include <opencv2/imgproc.hpp>
+#include <opencv2/imgproc/imgproc_c.h>
+#include <opencv2/imgcodecs/legacy/constants_c.h>
+
+#include <error.h>
+#include <argp.h>
+
+#define MAX_ARGS 3
+#define INDEX_MAX 4
+#define BARCODE_STRING_MAX 255
+#define RESULT_STRING_MAX 20
+
+static const char doc[] = "[VQA-barcode]\vmediavision barcode performance test\n\
+ e.g) mv_barcode_test_performance barcode.png result.txt";
+static const char args_doc[] = "SOURCE ANNOTATION";
+
+struct arguments
+{
+       char *source;
+       char *annotation;
+};
+
+#define NANO_PER_SEC ((__clock_t) 1000000000)
+#define NANO_PER_MILLI ((__clock_t) 1000000)
+#define MILLI_PER_SEC ((__clock_t) 1000)
+
+struct timespec diff(struct timespec start, struct timespec end)
+{
+       struct timespec temp;
+       if ((end.tv_nsec - start.tv_nsec) < 0) {
+               temp.tv_sec = end.tv_sec - start.tv_sec - 1;
+               temp.tv_nsec = NANO_PER_SEC + end.tv_nsec - start.tv_nsec;
+       } else {
+               temp.tv_sec = end.tv_sec - start.tv_sec;
+               temp.tv_nsec = end.tv_nsec - start.tv_nsec;
+       }
+       return temp;
+}
+unsigned long gettotalmillisec(const struct timespec time)
+{
+       return time.tv_sec * MILLI_PER_SEC + time.tv_nsec / NANO_PER_MILLI;
+}
+
+int load_image_to_buffer(char *source,
+               unsigned char **buffer,
+               unsigned long *size,
+               unsigned int *width,
+               unsigned int *height)
+{
+       cv::Mat image;
+       image = cv::imread(source);
+
+       if (!image.data)
+               return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+
+       try {
+               cv::cvtColor(image, image, CV_BGR2GRAY);
+       } catch (cv::Exception &e) {
+               return MEDIA_VISION_ERROR_INVALID_OPERATION;
+       }
+
+       *size = image.total() * image.elemSize();
+       *buffer = new unsigned char[*size];
+       std::memcpy(*buffer, image.data, *size);
+
+       *width = image.cols;
+       *height = image.rows;
+
+       return MEDIA_VISION_ERROR_NONE;
+}
+
+void barcode_detected_cb(
+               mv_source_h source,
+               mv_engine_config_h engine_cfg,
+               const mv_quadrangle_s *barcodes_locations,
+               const char *messages[],
+               const mv_barcode_type_e *types,
+               int number_of_barcodes,
+               void *user_data)
+{
+       MEDIA_VISION_FUNCTION_ENTER();
+
+       struct arguments *arguments = (struct arguments *) user_data;
+       FILE *fp;
+       char buf[BARCODE_STRING_MAX + 1] = {0};
+       char result[INDEX_MAX][RESULT_STRING_MAX] = {"no_detect", "match", "no_match", "failed"};
+       unsigned int idx = INDEX_MAX -1;
+
+       if (number_of_barcodes == 0)
+               idx = 0;
+       else {
+               size_t message_size = sizeof(messages[0]);
+               fp = fopen(arguments->annotation, "rt");
+               if (fp != NULL) {
+                       if (fgets(buf, BARCODE_STRING_MAX, fp) != NULL){
+                               if (strncmp(messages[0], buf, message_size) == 0)
+                                       idx = 1;
+                               else
+                                       idx = 2;
+                       }
+                       fclose(fp);
+               } else {
+                       LOGE("Errors were occurred during opening the file!!! file : %s", arguments->annotation);
+                       idx = 3;
+               }
+
+       }
+       printf("%s|%s|%s", arguments->source, arguments->annotation, result[idx]);
+
+       MEDIA_VISION_FUNCTION_LEAVE();
+}
+
+void perform_detect(struct arguments *arguments)
+{
+       MEDIA_VISION_FUNCTION_ENTER();
+
+       mv_engine_config_h mv_engine_config = NULL;
+       mv_source_h source = NULL;
+       unsigned char *data_buffer = NULL;
+       unsigned long buffer_size = 0;
+       unsigned int image_width = 0;
+       unsigned int image_height = 0;
+       int int_value = MV_BARCODE_DETECT_ATTR_TARGET_ALL;
+       mv_rectangle_s roi = { {0, 0}, 0, 0 };
+
+       int err = load_image_to_buffer(arguments->source,
+                       &data_buffer, &buffer_size, &image_width, &image_height);
+
+       if (MEDIA_VISION_ERROR_NONE != err) {
+               LOGE("Errors were occurred during opening the file!!! code : %i", err);
+               goto out;
+       }
+
+       err = mv_create_engine_config(&mv_engine_config);
+       if (MEDIA_VISION_ERROR_NONE != err)
+               LOGE("Errors were occurred during creating the media engine config : %i", err);
+
+       if (MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE ==
+               mv_engine_config_get_int_attribute(
+                                       mv_engine_config, MV_BARCODE_DETECT_ATTR_TARGET, &int_value)) {
+               LOGE("Errors were occurred during target attribute"
+                               "configuration : %i", err);
+               goto out;
+       }
+
+       err = mv_create_source(&source);
+       if (MEDIA_VISION_ERROR_NONE != err) {
+               LOGE("Errors were occurred during creating the source!!! code : %i", err);
+               goto out;
+       }
+
+       err = mv_source_fill_by_buffer(source, data_buffer, buffer_size,
+                       image_width, image_height, MEDIA_VISION_COLORSPACE_Y800);
+       if (MEDIA_VISION_ERROR_NONE != err) {
+               LOGE("Errors were occurred during filling the source!!! code : %i", err);
+               goto out;
+       }
+
+       roi.width = image_width;
+       roi.height = image_height;
+       err = mv_barcode_detect(source, mv_engine_config, roi, barcode_detected_cb, arguments);
+       if (MEDIA_VISION_ERROR_NONE != err) {
+               LOGE("Errors were occurred during barcode detection!!! code : %i", err);
+       }
+out:
+       if (MEDIA_VISION_ERROR_NONE != err)
+               printf("%s|%s|failed", arguments->source, arguments->annotation);
+
+       if (data_buffer != NULL) {
+               delete [] data_buffer;
+               data_buffer = NULL;
+       }
+
+       if (source != NULL) {
+               err = mv_destroy_source(source);
+               if (MEDIA_VISION_ERROR_NONE != err) {
+                       LOGE("Errors were occurred during destroying the source!!! code : %i", err);
+               }
+       }
+
+       if (mv_engine_config != NULL) {
+               err = mv_destroy_engine_config(mv_engine_config);
+               if (MEDIA_VISION_ERROR_NONE != err) {
+                       LOGE("Error were occurred during destroying the source!!! code : %i", err);
+               }
+       }
+
+       MEDIA_VISION_FUNCTION_LEAVE();
+}
+
+static error_t parse_opt (int key, char *arg, struct argp_state *state)
+{
+       struct arguments *arguments = (struct arguments *)state->input;
+
+       switch (key) {
+       case ARGP_KEY_NO_ARGS:
+               argp_usage(state);
+               break;
+       case ARGP_KEY_ARG:
+               if(state->argc > MAX_ARGS)
+                       argp_failure(state, 1, 0, "too many arguments");
+               else if(state->argc < MAX_ARGS)
+                       argp_failure(state, 1, 0, "too few arguments");
+               arguments->source = arg;
+               arguments->annotation = state->argv[state->next];
+               state->next = state->argc;
+               break;
+       default:
+               return ARGP_ERR_UNKNOWN;
+       }
+
+       return 0;
+}
+
+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 Test-Accuracy 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);
+
+       struct timespec diffspec = diff(s_tspec, e_tspec);
+       unsigned long timeDiff = gettotalmillisec(diffspec);
+       printf("|%lums\n", timeDiff);
+
+       LOGI("Media Vision Test-Accuracy is closed.");
+
+       return 0;
+}