From 896c34fab3fa49ec5d913305040b1eab15589d3a Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Tue, 17 Jan 2017 16:40:38 +0300 Subject: [PATCH] Add support of type headings from YAML1.2 --- modules/core/src/persistence.cpp | 20 ++++++++++++++++++++ modules/core/test/test_io.cpp | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index bf16c2f398..946875f5b1 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -1475,6 +1475,26 @@ icvYMLParseValue( CvFileStorage* fs, char* ptr, CvFileNode* node, ptr++; value_type |= CV_NODE_USER; } + if ( d == '<') //support of full type heading from YAML 1.2 + { + const char* yamlTypeHeading = "' && (size_t)(typeEndPtr - ptr) > headingLenght ) + { + if ( memcmp(ptr, yamlTypeHeading, headingLenght) == 0 ) + { + value_type |= CV_NODE_USER; + *typeEndPtr = ' '; + ptr += headingLenght - 1; + } + } + } endptr = ptr++; do d = *++endptr; diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index eb02a7b23d..880d5cb1d8 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -996,3 +996,20 @@ TEST(Core_InputOutput, filestorage_vec_vec_io) remove((fileName + formats[i]).c_str()); } } + +TEST(Core_InputOutput, filestorage_yaml_advanvced_type_heading) +{ + String content = "%YAML:1.0\n cameraMatrix: !\n" + " rows: 1\n" + " cols: 1\n" + " dt: d\n" + " data: [ 1. ]"; + + cv::FileStorage fs(content, cv::FileStorage::READ | cv::FileStorage::MEMORY); + + cv::Mat inputMatrix; + cv::Mat actualMatrix = cv::Mat::eye(1, 1, CV_64F); + fs["cameraMatrix"] >> inputMatrix; + + ASSERT_EQ(cv::norm(inputMatrix, actualMatrix, NORM_INF), 0.); +}