Skip to content

Commit 6fbf075

Browse files
committed
Python: wrap Algorithm::read and Algorithm::write
1 parent f071a48 commit 6fbf075

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

modules/core/include/opencv2/core.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3093,13 +3093,18 @@ class CV_EXPORTS_W Algorithm
30933093
*/
30943094
virtual void write(FileStorage& fs) const { (void)fs; }
30953095

3096+
/** @brief simplified API for language bindings
3097+
* @overload
3098+
*/
3099+
CV_WRAP void write(const Ptr<FileStorage>& fs, const String& name = String()) const;
3100+
30963101
/** @brief Reads algorithm parameters from a file storage
30973102
*/
3098-
virtual void read(const FileNode& fn) { (void)fn; }
3103+
CV_WRAP virtual void read(const FileNode& fn) { (void)fn; }
30993104

31003105
/** @brief Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read
31013106
*/
3102-
virtual bool empty() const { return false; }
3107+
CV_WRAP virtual bool empty() const { return false; }
31033108

31043109
/** @brief Reads algorithm from the file node
31053110

modules/core/src/algorithm.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ Algorithm::~Algorithm()
5555
CV_TRACE_FUNCTION();
5656
}
5757

58+
void Algorithm::write(const Ptr<FileStorage>& fs, const String& name) const
59+
{
60+
CV_TRACE_FUNCTION();
61+
if(name.empty())
62+
{
63+
write(*fs);
64+
return;
65+
}
66+
*fs << name << "{";
67+
write(*fs);
68+
*fs << "}";
69+
}
70+
5871
void Algorithm::save(const String& filename) const
5972
{
6073
CV_TRACE_FUNCTION();

modules/features2d/include/opencv2/features2d.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,15 @@ class CV_EXPORTS_W Feature2D : public virtual Algorithm
210210

211211
virtual void write( FileStorage&) const;
212212

213-
virtual void read( const FileNode&);
213+
// see corresponding cv::Algorithm method
214+
CV_WRAP virtual void read( const FileNode&);
214215

215216
//! Return true if detector object is empty
216217
CV_WRAP virtual bool empty() const;
217218
CV_WRAP virtual String getDefaultName() const;
219+
220+
// see corresponding cv::Algorithm method
221+
CV_WRAP inline void write(const Ptr<FileStorage>& fs, const String& name = String()) const { Algorithm::write(fs, name); }
218222
};
219223

220224
/** Feature detectors in OpenCV have wrappers with a common interface that enables you to easily switch
@@ -985,7 +989,8 @@ class CV_EXPORTS_W DescriptorMatcher : public Algorithm
985989
read(fs.root());
986990
}
987991
// Reads matcher object from a file node
988-
virtual void read( const FileNode& );
992+
// see corresponding cv::Algorithm method
993+
CV_WRAP virtual void read( const FileNode& );
989994
// Writes matcher object to a file storage
990995
virtual void write( FileStorage& ) const;
991996

@@ -1012,6 +1017,10 @@ class CV_EXPORTS_W DescriptorMatcher : public Algorithm
10121017

10131018
CV_WRAP static Ptr<DescriptorMatcher> create( int matcherType );
10141019

1020+
1021+
// see corresponding cv::Algorithm method
1022+
CV_WRAP inline void write(const Ptr<FileStorage>& fs, const String& name = String()) const { Algorithm::write(fs, name); }
1023+
10151024
protected:
10161025
/**
10171026
* Class to work with descriptors from several images as with one merged matrix.

0 commit comments

Comments
 (0)