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

core(persistence): resolve DMatch/KeyPoint problem

This commit is contained in:
Alexander Alekhin
2017-08-25 18:55:31 +03:00
parent 86b55b3923
commit 0451629e22
3 changed files with 332 additions and 83 deletions
+45 -18
View File
@@ -7333,21 +7333,45 @@ void read( const FileNode& node, SparseMat& mat, const SparseMat& default_mat )
m->copyToSparseMat(mat);
}
void write(FileStorage& fs, const String& objname, const std::vector<KeyPoint>& keypoints)
CV_EXPORTS void read(const FileNode& node, KeyPoint& value, const KeyPoint& default_value)
{
cv::internal::WriteStructContext ws(fs, objname, CV_NODE_SEQ + CV_NODE_FLOW);
int i, npoints = (int)keypoints.size();
for( i = 0; i < npoints; i++ )
if( node.empty() )
{
write(fs, keypoints[i]);
value = default_value;
return;
}
node >> value;
}
CV_EXPORTS void read(const FileNode& node, DMatch& value, const DMatch& default_value)
{
if( node.empty() )
{
value = default_value;
return;
}
node >> value;
}
#ifdef CV__LEGACY_PERSISTENCE
void write( FileStorage& fs, const String& name, const std::vector<KeyPoint>& vec)
{
// from template implementation
cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ);
write(fs, vec);
}
void read(const FileNode& node, std::vector<KeyPoint>& keypoints)
{
keypoints.resize(0);
FileNode first_node = *(node.begin());
if (first_node.isSeq())
{
// modern scheme
FileNodeIterator it = node.begin();
it >> keypoints;
return;
}
keypoints.clear();
FileNodeIterator it = node.begin(), it_end = node.end();
for( ; it != it_end; )
{
@@ -7357,21 +7381,24 @@ void read(const FileNode& node, std::vector<KeyPoint>& keypoints)
}
}
void write(FileStorage& fs, const String& objname, const std::vector<DMatch>& matches)
void write( FileStorage& fs, const String& name, const std::vector<DMatch>& vec)
{
cv::internal::WriteStructContext ws(fs, objname, CV_NODE_SEQ + CV_NODE_FLOW);
int i, n = (int)matches.size();
for( i = 0; i < n; i++ )
{
write(fs, matches[i]);
}
// from template implementation
cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ);
write(fs, vec);
}
void read(const FileNode& node, std::vector<DMatch>& matches)
{
matches.resize(0);
FileNode first_node = *(node.begin());
if (first_node.isSeq())
{
// modern scheme
FileNodeIterator it = node.begin();
it >> matches;
return;
}
matches.clear();
FileNodeIterator it = node.begin(), it_end = node.end();
for( ; it != it_end; )
{
@@ -7380,7 +7407,7 @@ void read(const FileNode& node, std::vector<DMatch>& matches)
matches.push_back(m);
}
}
#endif
int FileNode::type() const { return !node ? NONE : (node->tag & TYPE_MASK); }
bool FileNode::isNamed() const { return !node ? false : (node->tag & NAMED) != 0; }