1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-27 14:23:04 +04:00

Merge pull request #17436 from vpisarev:fix_python_io

* fixed #17044
1. fixed Python part of the tutorial about using OpenCV XML-YAML-JSON I/O functionality from C++ and Python.
2. added startWriteStruct() and endWriteStruct() methods to FileStorage
3. modifed FileStorage::write() methods to make them work well inside sequences, not only mappings.

* try to fix the doc builder

* added Python regression test for FileStorage I/O API ([TODO] iterating through long sequences can be very slow)

* fixed yaml testing
This commit is contained in:
Vadim Pisarevsky
2020-06-01 14:33:09 +03:00
committed by GitHub
parent 8de176988d
commit 5489735258
6 changed files with 169 additions and 21 deletions
+26 -4
View File
@@ -166,22 +166,24 @@ void FileStorage::writeObj( const String& name, const void* obj )
void FileStorage::write( const String& name, int val )
{
*this << name << val;
cvWriteInt(fs, name.c_str(), val);
}
void FileStorage::write( const String& name, double val )
{
*this << name << val;
cvWriteReal(fs, name.c_str(), val);
}
void FileStorage::write( const String& name, const String& val )
{
*this << name << val;
cvWriteString(fs, name.c_str(), val.c_str());
}
void FileStorage::write( const String& name, InputArray val )
{
*this << name << val.getMat();
if(state & INSIDE_MAP)
*this << name;
*this << val.getMat();
}
void FileStorage::writeComment( const String& comment, bool append )
@@ -189,6 +191,26 @@ void FileStorage::writeComment( const String& comment, bool append )
cvWriteComment(fs, comment.c_str(), append ? 1 : 0);
}
void FileStorage::startWriteStruct(const String& name, int flags, const String& typeName)
{
int struct_type = flags & FileNode::TYPE_MASK;
bool isflow = (flags & FileNode::FLOW) != 0;
CV_Assert(struct_type == FileNode::SEQ || struct_type == FileNode::MAP);
char strbegin_[] = { (struct_type == FileNode::SEQ ? '[' : '{'), (isflow ? ':' : '\0'), '\0' };
String strbegin = strbegin_;
if (!typeName.empty())
strbegin += typeName;
*this << name << strbegin;
}
void FileStorage::endWriteStruct()
{
if( structs.empty() )
CV_Error( CV_StsError, "Extra endWriteStruct()" );
char openparen = structs.back();
*this << (openparen == '[' ? "]" : "}");
}
String FileStorage::getDefaultObjectName(const String& _filename)
{
static const char* stubname = "unnamed";