From: Tae-Young Chung Date: Mon, 19 Oct 2015 01:39:29 +0000 (+0900) Subject: Changed json-c to json-glib support for EngineConfig X-Git-Tag: accepted/tizen/mobile/20151020.111039~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=819ac85ed4161849caa46f87c88f80f96dafb857;p=platform%2Fcore%2Fapi%2Fmediavision.git Changed json-c to json-glib support for EngineConfig Change-Id: I9a1d5143219868a317eb33fd7c5d1c560be2e6ba Signed-off-by: Tae-Young Chung --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 16f4b13..ebd2df1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,8 +57,6 @@ else() SET(INC_IMAGE "${PROJECT_SOURCE_DIR}/mv_image/image/include") endif() -INCLUDE_DIRECTORIES(${INC_DIR} ${INC_COMMON} ${INC_BARCODE_DETECTOR} ${INC_BARCODE_GENERATOR} ${INC_IMAGE}) - if(MEDIA_VISION_FACE_LICENSE_PORT) add_definitions(-DMEDIA_VISION_FACE_LICENSE_PORT) SET(INC_FACE "${PROJECT_SOURCE_DIR}/mv_face/face_lic/include") @@ -66,7 +64,12 @@ else() SET(INC_FACE "${PROJECT_SOURCE_DIR}/mv_face/face/include") endif() -INCLUDE_DIRECTORIES(${INC_DIR} ${INC_COMMON} ${INC_BARCODE_DETECTOR} ${INC_BARCODE_GENERATOR} ${INC_FACE}) +INCLUDE_DIRECTORIES(${INC_DIR} + ${INC_COMMON} + ${INC_BARCODE_DETECTOR} + ${INC_BARCODE_GENERATOR} + ${INC_FACE} + ${INC_IMAGE}) SET(dependents "dlog capi-media-tool capi-system-info capi-appfw-application") SET(pc_dependents "dlog") diff --git a/media-vision-config.json b/media-vision-config.json index a3d6eee..9185a1a 100644 --- a/media-vision-config.json +++ b/media-vision-config.json @@ -4,116 +4,116 @@ { "name" : "MV_FACE_DETECTION_MODEL_FILE_PATH", "type" : "string", - "value" : "/usr/share/OpenCV/haarcascades/haarcascade_frontalface_alt2.xml", + "value" : "/usr/share/OpenCV/haarcascades/haarcascade_frontalface_alt2.xml" }, { "name" : "MV_FACE_DETECTION_ROI_X", "type" : "integer", - "value" : -1, + "value" : -1 }, { "name" : "MV_FACE_DETECTION_ROI_Y", "type" : "integer", - "value" : -1, + "value" : -1 }, { "name" : "MV_FACE_DETECTION_ROI_WIDTH", "type" : "integer", - "value" : -1, + "value" : -1 }, { "name" : "MV_FACE_DETECTION_ROI_HEIGHT", "type" : "integer", - "value" : -1, + "value" : -1 }, { "name" : "MV_FACE_DETECTION_MIN_SIZE_WIDTH", "type" : "integer", - "value" : -1, + "value" : -1 }, { "name" : "MV_FACE_DETECTION_MIN_SIZE_HEIGHT", "type" : "integer", - "value" : -1, + "value" : -1 }, { "name" : "MV_BARCODE_GENERATE_ATTR_TEXT", "type" : "integer", - "value" : 0, + "value" : 0 }, { "name" : "MV_BARCODE_DETECT_ATTR_TARGET", "type" : "integer", - "value" : 0, + "value" : 0 }, { "name" : "MV_IMAGE_RECOGNITION_OBJECT_SCALE_FACTOR", "type" : "double", - "value" : 1.2, + "value" : 1.2 }, { "name" : "MV_IMAGE_RECOGNITION_OBJECT_MAX_KEYPOINTS_NUM", "type" : "integer", - "value" : 1000, + "value" : 1000 }, { "name" : "MV_IMAGE_RECOGNITION_SCENE_SCALE_FACTOR", "type" : "double", - "value" : 1.2, + "value" : 1.2 }, { "name" : "MV_IMAGE_RECOGNITION_SCENE_MAX_KEYPOINTS_NUM", "type" : "integer", - "value" : 5000, + "value" : 5000 }, { "name" : "MV_IMAGE_RECOGNITION_MIN_MATCH_NUM", "type" : "integer", - "value" : 30, + "value" : 30 }, { "name" : "MV_IMAGE_RECOGNITION_REQ_MATCH_PART", "type" : "double", - "value" : 0.05, + "value" : 0.05 }, { "name" : "MV_IMAGE_RECOGNITION_TOLERANT_MATCH_PART_ERR", "type" : "double", - "value" : 0.1, + "value" : 0.1 }, { "name" : "MV_IMAGE_TRACKING_HISTORY_AMOUNT", "type" : "integer", - "value" : 3, + "value" : 3 }, { "name" : "MV_IMAGE_TRACKING_EXPECTED_OFFSET", "type" : "double", - "value" : 0, + "value" : 0 }, { "name" : "MV_IMAGE_TRACKING_USE_STABLIZATION", "type" : "boolean", - "value" : false, + "value" : false }, { "name" : "MV_IMAGE_TRACKING_STABLIZATION_TOLERANT_SHIFT", "type" : "double", - "value" : 0.006, + "value" : 0.006 }, { "name" : "MV_IMAGE_TRACKING_STABLIZATION_SPEED", "type" : "double", - "value" : 2, + "value" : 2 }, { "name" : "MV_IMAGE_TRACKING_STABLIZATION_ACCELERATION", "type" : "double", - "value" : 0.001, + "value" : 0.001 }, { "name" : "MV_FACE_RECOGNITION_MODEL_TYPE", "type" : "integer", - "value" : 3, + "value" : 3 } ] } diff --git a/mv_common/CMakeLists.txt b/mv_common/CMakeLists.txt index 64fa19a..db991e8 100644 --- a/mv_common/CMakeLists.txt +++ b/mv_common/CMakeLists.txt @@ -25,12 +25,15 @@ else() include_directories(${OpenCV_INCLUDE_DIRS}) endif() +PKG_CHECK_MODULES(JSONGLIB REQUIRED json-glib-1.0) +INCLUDE_DIRECTORIES(${JSONGLIB_INCLUDE_DIRS}) + if(FORCED_STATIC_BUILD) add_library(${PROJECT_NAME} STATIC ${MV_COMMON_INCLUDE_LIST} ${MV_COMMON_SRC_LIST}) else() add_library(${PROJECT_NAME} SHARED ${MV_COMMON_INCLUDE_LIST} ${MV_COMMON_SRC_LIST}) endif() -TARGET_LINK_LIBRARIES(${MV_COMMON_LIB_NAME} jpeg ${OpenCV_LIBS} capi-media-tool tbm json-c) +TARGET_LINK_LIBRARIES(${MV_COMMON_LIB_NAME} jpeg ${OpenCV_LIBS} capi-media-tool tbm json-glib-1.0) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) diff --git a/mv_common/src/EngineConfig.cpp b/mv_common/src/EngineConfig.cpp index 3faedf1..64bf1d9 100644 --- a/mv_common/src/EngineConfig.cpp +++ b/mv_common/src/EngineConfig.cpp @@ -18,7 +18,7 @@ #include -#include +#include /** * @file EngineConfig.cpp @@ -244,79 +244,115 @@ int EngineConfig::cacheDictionaries(bool isLazyCache, std::string configFilePath DefBoolDict.clear(); DefStrDict.clear(); - json_object *jobj = json_object_from_file(configFilePath.c_str()); + const char *conf_file = configFilePath.c_str(); + JsonParser *parser; + GError *error = NULL; - enum json_type type = json_object_get_type(jobj); - if (json_type_object != type) + parser = json_parser_new(); + json_parser_load_from_file(parser, conf_file, &error); + if (error) { - LOGE("Can't parse engine config file. Incorrect json markup. " - "Supported attributes can't be determined."); - json_object_put(jobj); + LOGW("Unable to parse file '%s': %s\n", conf_file, error->message); + g_error_free(error); + g_object_unref(parser); return MEDIA_VISION_ERROR_NO_DATA; } - json_object *pAttributesObj = json_object_object_get(jobj, "attributes"); - type = json_object_get_type(pAttributesObj); - if (json_type_array != type) + JsonNode *root = json_parser_get_root(parser); + if (JSON_NODE_OBJECT != json_node_get_node_type(root)) { - LOGE("Can't parse engine config file. Incorrect json markup. " - "Supported attributes can't be determined."); - json_object_put(jobj); + LOGW("Can't parse tests configuration file. " + "Incorrect json markup."); + g_object_unref(parser); return MEDIA_VISION_ERROR_NO_DATA; } - const int attrNum = json_object_array_length(pAttributesObj); + JsonObject *jobj = json_node_get_object(root); - for (int attrInd = 0; attrInd < attrNum; ++attrInd) + if (!json_object_has_member(jobj, "attributes")) { - json_object *pAttrObj = - json_object_array_get_idx(pAttributesObj, attrInd); - type = json_object_get_type(pAttrObj); - - json_object *pAttrNameObj = NULL; - json_object *pAttrTypeObj = NULL; - json_object *pAttrValueObj = NULL; - - if (json_type_object != type || - !json_object_object_get_ex(pAttrObj, "name", &pAttrNameObj) || - !json_object_object_get_ex(pAttrObj, "type", &pAttrTypeObj) || - !json_object_object_get_ex(pAttrObj, "value", &pAttrValueObj)) + LOGW("Can't parse tests configuration file. " + "No 'attributes' section."); + g_object_unref(parser); + return MEDIA_VISION_ERROR_NO_DATA; + } + + JsonNode *attr_node = + json_object_get_member(jobj, "attributes"); + + if (JSON_NODE_ARRAY != json_node_get_node_type(attr_node)) + { + LOGW("Can't parse tests configuration file. " + "'attributes' section isn't array."); + g_object_unref(parser); + return MEDIA_VISION_ERROR_NO_DATA; + } + + JsonArray *attr_array = json_node_get_array(attr_node); + + const guint attr_num = json_array_get_length(attr_array); + + guint attrInd = 0; + for (; attrInd < attr_num; ++attrInd) + { + JsonNode *attr_node = json_array_get_element(attr_array, attrInd); + + if (JSON_NODE_OBJECT != json_node_get_node_type(attr_node)) + { + LOGW("Attribute %u wasn't parsed from json file.", attrInd); + continue; + } + + JsonObject *attr_obj = json_node_get_object(attr_node); + + if (!json_object_has_member(attr_obj, "name") || + !json_object_has_member(attr_obj, "type") || + !json_object_has_member(attr_obj, "value")) { - LOGW("Attribute %i wasn't parsed from json file.", attrInd); + LOGW("Attribute %u wasn't parsed from json file.", attrInd); continue; } - const char *nameStr = json_object_get_string(pAttrNameObj); - const char *typeStr = json_object_get_string(pAttrTypeObj); + const char *nameStr = + (char*)json_object_get_string_member(attr_obj, "name"); + const char *typeStr = + (char*)json_object_get_string_member(attr_obj, "type"); - if (0 == strcmp("double", typeStr)) + if (NULL == nameStr || NULL == typeStr) + { + LOGW("Attribute %i wasn't parsed from json file. name and/or " + "type of the attribute are parsed as NULL.", attrInd); + continue; + } + else if (0 == strcmp("double", typeStr)) { DefDblDict[std::string(nameStr)] = - json_object_get_double(pAttrValueObj); + (double)json_object_get_double_member(attr_obj, "value"); } else if (0 == strcmp("integer", typeStr)) { DefIntDict[std::string(nameStr)] = - json_object_get_int(pAttrValueObj); + (int)json_object_get_int_member(attr_obj, "value"); } else if (0 == strcmp("boolean", typeStr)) { DefBoolDict[std::string(nameStr)] = - json_object_get_boolean(pAttrValueObj) ? true : false; + json_object_get_boolean_member(attr_obj, "value") ? true : false; } else if (0 == strcmp("string", typeStr)) { DefStrDict[std::string(nameStr)] = - json_object_get_string(pAttrValueObj); + (char*)json_object_get_string_member(attr_obj, "value"); } else { - LOGW("Attribute %i:%s wasn't parsed from json file. Type isn't supported.", attrInd, nameStr); + LOGW("Attribute %i:%s wasn't parsed from json file. " + "Type isn't supported.", attrInd, nameStr); continue; } } - json_object_put(jobj); + g_object_unref(parser); isCached = true; } diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index a786d8e..73a4fbb 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -1,6 +1,6 @@ Name: capi-media-vision Summary: Media Vision library for Tizen Native API -Version: 0.2.1 +Version: 0.2.2 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-2.0 @@ -17,8 +17,7 @@ BuildRequires: pkgconfig(glib-2.0) # Change to the pkgconfig(zint) after zint package refactor BuildRequires: zint BuildRequires: zint-devel -BuildRequires: libjson -BuildRequires: libjson-devel +BuildRequires: pkgconfig(json-glib-1.0) BuildRequires: dlogutil BuildRequires: libjpeg-turbo BuildRequires: libjpeg-turbo-devel