mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 19:50:38 +08:00
Add support of type headings from YAML1.2
This commit is contained in:
parent
89a740a62f
commit
896c34fab3
@ -1475,6 +1475,26 @@ icvYMLParseValue( CvFileStorage* fs, char* ptr, CvFileNode* node,
|
|||||||
ptr++;
|
ptr++;
|
||||||
value_type |= CV_NODE_USER;
|
value_type |= CV_NODE_USER;
|
||||||
}
|
}
|
||||||
|
if ( d == '<') //support of full type heading from YAML 1.2
|
||||||
|
{
|
||||||
|
const char* yamlTypeHeading = "<tag:yaml.org,2002:";
|
||||||
|
const size_t headingLenght = strlen(yamlTypeHeading);
|
||||||
|
|
||||||
|
char* typeEndPtr = ++ptr;
|
||||||
|
|
||||||
|
do d = *++typeEndPtr;
|
||||||
|
while( cv_isprint(d) && d != ' ' && d != '>' );
|
||||||
|
|
||||||
|
if ( d == '>' && (size_t)(typeEndPtr - ptr) > headingLenght )
|
||||||
|
{
|
||||||
|
if ( memcmp(ptr, yamlTypeHeading, headingLenght) == 0 )
|
||||||
|
{
|
||||||
|
value_type |= CV_NODE_USER;
|
||||||
|
*typeEndPtr = ' ';
|
||||||
|
ptr += headingLenght - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
endptr = ptr++;
|
endptr = ptr++;
|
||||||
do d = *++endptr;
|
do d = *++endptr;
|
||||||
|
@ -996,3 +996,20 @@ TEST(Core_InputOutput, filestorage_vec_vec_io)
|
|||||||
remove((fileName + formats[i]).c_str());
|
remove((fileName + formats[i]).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Core_InputOutput, filestorage_yaml_advanvced_type_heading)
|
||||||
|
{
|
||||||
|
String content = "%YAML:1.0\n cameraMatrix: !<tag:yaml.org,2002:opencv-matrix>\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.);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user