44 #ifndef OPENCV_CORE_PERSISTENCE_HPP
45 #define OPENCV_CORE_PERSISTENCE_HPP
49 #define CV__LEGACY_PERSISTENCE
53 # error persistence.hpp header must be compiled as C++
100 #include "opencv2/core/types.hpp"
101 #include "opencv2/core/mat.hpp"
314 FORMAT_MASK = (7<<3),
317 FORMAT_YAML = (2<<3),
318 FORMAT_JSON = (3<<3),
321 WRITE_BASE64 = BASE64 | WRITE,
575 operator int()
const;
577 operator float()
const;
579 operator double()
const;
620 FileNode(FileStorage::Impl* fs,
size_t blockIdx,
size_t ofs);
622 FileStorage::Impl*
fs;
679 size_t len=(
size_t)INT_MAX );
687 FileStorage::Impl*
fs;
705 #ifdef CV__LEGACY_PERSISTENCE
721 #ifdef CV__LEGACY_PERSISTENCE
738 saturate_cast<_Tp>(
temp[2]));
757 saturate_cast<_Tp>(
temp[2]), saturate_cast<_Tp>(
temp[3]));
766 template<
typename _Tp,
int m,
int n>
static inline void read(
const FileNode& node,
Matx<_Tp, m, n>&
value,
const Matx<_Tp, m, n>& default_matx =
Matx<_Tp, m, n>())
772 value = default_matx;
781 saturate_cast<_Tp>(
temp[2]), saturate_cast<_Tp>(
temp[3]));
803 ~WriteStructContext();
808 template<
typename _Tp,
int numflag>
class VecWriterProxy
811 VecWriterProxy( FileStorage* _fs ) : fs(_fs) {}
815 for (
size_t i = 0; i <
count; i++)
822 template<
typename _Tp>
class VecWriterProxy<_Tp, 1>
825 VecWriterProxy( FileStorage* _fs ) : fs(_fs) {}
828 int _fmt = traits::SafeFmt<_Tp>::fmt;
829 char fmt[] = { (char)((_fmt >> 8) +
'1'), (
char)_fmt,
'\0' };
830 fs->writeRaw(fmt, !vec.
empty() ? (
uchar*)&vec[0] : 0, vec.
size() *
sizeof(_Tp));
836 template<
typename _Tp,
int numflag>
class VecReaderProxy
844 for (
size_t i = 0; i <
count; i++, ++(*it))
845 read(**it, vec[i], _Tp());
851 template<
typename _Tp>
class VecReaderProxy<_Tp, 1>
857 size_t remaining = it->remaining();
859 int _fmt = traits::SafeFmt<_Tp>::fmt;
861 char fmt[] = { (char)((_fmt >> 8)+
'1'), (
char)_fmt,
'\0' };
863 size_t remaining1 = remaining / cn;
866 it->readRaw(fmt, !vec.
empty() ? (
uchar*)&vec[0] : 0,
count*
sizeof(_Tp));
876 template<
typename _Tp>
static inline
906 template<
typename _Tp>
static inline
913 template<
typename _Tp>
static inline
921 template<
typename _Tp>
static inline
928 template<
typename _Tp>
static inline
935 template<
typename _Tp>
static inline
944 template<
typename _Tp,
int cn>
static inline
947 for(
int i = 0; i < cn; i++)
951 template<
typename _Tp,
int m,
int n>
static inline
957 template<
typename _Tp>
static inline
973 template<
typename _Tp>
static inline
976 cv::internal::VecWriterProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0> w(&fs);
980 template<
typename _Tp>
static inline
987 template<
typename _Tp>
static inline
994 template<
typename _Tp>
static inline
1001 template<
typename _Tp>
static inline
1008 template<
typename _Tp>
static inline
1015 template<
typename _Tp,
int cn>
static inline
1022 template<
typename _Tp,
int m,
int n>
static inline
1028 template<
typename _Tp>
static inline
1068 write(fs, name,
static_cast<int>(val));
1071 template<
typename _Tp>
static inline
1078 template<
typename _Tp>
static inline
1081 cv::internal::WriteStructContext ws(fs, name,
FileNode::SEQ);
1082 for(
size_t i = 0; i < vec.
size(); i++)
1089 #ifdef CV__LEGACY_PERSISTENCE
1096 cv::internal::VecWriterProxy<KeyPoint, 0> w(&fs);
1101 cv::internal::VecWriterProxy<DMatch, 0> w(&fs);
1112 read(node,
temp, (
int)default_value);
1120 read(node,
temp, (
int)default_value);
1128 read(node,
temp, (
int)default_value);
1136 read(node,
temp, (
int)default_value);
1144 read(node,
temp, (
int)default_value);
1148 template<
typename _Tp>
static inline
1151 cv::internal::VecReaderProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0>
r(&it);
1156 static inline void read(
const FileNode& node, _Tp&
value,
const _Tp& default_value =
static_cast<_Tp
>(0))
1159 read(node,
temp,
static_cast<int>(default_value));
1163 template<
typename _Tp>
static inline
1167 vec = default_value;
1179 vec = default_value;
1188 vec = default_value;
1195 template<
typename _Tp>
static inline
1213 return (fs <<
String(str));
1226 template<
typename _Tp>
static inline
1235 template<
typename _Tp>
static inline
1238 cv::internal::VecReaderProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0>
r(&it);
1239 r(vec, (
size_t)INT_MAX);
1245 template<
typename _Tp>
static inline
1253 template<
typename _Tp>
static inline
1270 #ifdef CV__LEGACY_PERSISTENCE
A complex number class.
Definition: types.hpp:80
_Tp im
the real and the imaginary parts
Definition: types.hpp:92
_Tp re
Definition: types.hpp:92
Class for matching keypoint descriptors.
Definition: types.hpp:842
CV_PROP_RW int queryIdx
query descriptor index
Definition: types.hpp:848
CV_PROP_RW float distance
Definition: types.hpp:852
CV_PROP_RW int imgIdx
train image index
Definition: types.hpp:850
CV_PROP_RW int trainIdx
train descriptor index
Definition: types.hpp:849
used to iterate through sequences and mappings.
Definition: persistence.hpp:634
FileNodeIterator(const FileNodeIterator &it)
size_t ofs
Definition: persistence.hpp:689
size_t remaining() const
returns the number of remaining (not read yet) elements
bool equalTo(const FileNodeIterator &it) const
size_t nodeNElems
Definition: persistence.hpp:691
FileNodeIterator()
The constructors.
size_t blockSize
Definition: persistence.hpp:690
FileStorage::Impl * fs
Definition: persistence.hpp:687
size_t blockIdx
Definition: persistence.hpp:688
size_t idx
Definition: persistence.hpp:692
FileNodeIterator(const FileNode &node, bool seekEnd)
FileNodeIterator & operator=(const FileNodeIterator &it)
FileNodeIterator & readRaw(const String &fmt, void *vec, size_t len=(size_t) INT_MAX)
Reads node elements to the buffer with the specified format.
File Storage Node class.
Definition: persistence.hpp:482
CV_WRAP int type() const
Returns type of the node.
CV_WRAP double real() const
Simplified reading API to use with bindings.
static bool isSeq(int flags)
static bool isMap(int flags)
FileNodeIterator begin() const
returns iterator pointing to the first node element
operator std::string() const
returns the node content as text string
Definition: persistence.hpp:581
CV_WRAP FileNode()
The constructors.
CV_WRAP std::vector< String > keys() const
Returns keys of a mapping node.
CV_WRAP bool empty() const
returns true if the node is empty
void setValue(int type, const void *value, int len=-1)
CV_WRAP bool isInt() const
returns true if the node is an integer
CV_WRAP std::string name() const
returns the node name or an empty string if the node is nameless
FileNode(const FileNode &node)
CV_WRAP bool isMap() const
returns true if the node is a mapping
FileNode operator[](const String &nodename) const
Returns element of a mapping node or a sequence node.
FileNodeIterator end() const
returns iterator pointing to the element following the last node element
static bool isEmptyCollection(int flags)
FileNode(FileStorage::Impl *fs, size_t blockIdx, size_t ofs)
CV_WRAP std::string string() const
Simplified reading API to use with bindings.
CV_WRAP_AS(getNode) FileNode operator[](const char *nodename) const
size_t blockIdx
Definition: persistence.hpp:623
FileNode & operator=(const FileNode &node)
size_t ofs
Definition: persistence.hpp:624
CV_WRAP bool isString() const
returns true if the node is a text string
@ FLOW
compact representation of a sequence or mapping. Used only by YAML writer
Definition: persistence.hpp:497
@ SEQ
sequence
Definition: persistence.hpp:493
CV_WRAP Mat mat() const
Simplified reading API to use with bindings.
void readRaw(const String &fmt, void *vec, size_t len) const
Reads node elements to the buffer with the specified format.
CV_WRAP bool isNone() const
returns true if the node is a "none" object
static bool isCollection(int flags)
static bool isFlow(int flags)
CV_WRAP_AS(at) FileNode operator[](int i) const
CV_WRAP bool isReal() const
returns true if the node is a floating-point number
FileStorage::Impl * fs
Definition: persistence.hpp:622
FileNode(const FileStorage *fs, size_t blockIdx, size_t ofs)
CV_WRAP size_t rawSize() const
returns raw size of the FileNode in bytes
const uchar * ptr() const
CV_WRAP bool isSeq() const
returns true if the node is a sequence
CV_WRAP bool isNamed() const
returns true if the node has a name
CV_WRAP size_t size() const
returns the number of elements in the node, if it is a sequence or mapping, or 1 otherwise.
XML/YAML/JSON file storage class that encapsulates all the information necessary for writing or readi...
Definition: persistence.hpp:304
CV_WRAP FileStorage()
The constructors.
CV_WRAP void write(const String &name, int val)
Simplified writing API to use with bindings.
virtual CV_WRAP void release()
Closes the file and releases all the memory buffers.
CV_WRAP void write(const String &name, const Mat &val)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void writeRaw(const String &fmt, const void *vec, size_t len)
Writes multiple numbers.
CV_WRAP void write(const String &name, const std::vector< String > &val)
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual ~FileStorage()
the destructor. calls release()
CV_WRAP void write(const String &name, double val)
This is an overloaded member function, provided for convenience. It differs from the above function o...
CV_WRAP FileNode root(int streamidx=0) const
Returns the top-level mapping.
CV_WRAP FileNode getFirstTopLevelNode() const
Returns the first element of the top-level mapping.
CV_WRAP void startWriteStruct(const String &name, int flags, const String &typeName=String())
Starts to write a nested structure (sequence or a mapping).
Mode
file storage mode
Definition: persistence.hpp:308
CV_WRAP void endWriteStruct()
Finishes writing nested structure (should pair startWriteStruct())
CV_WRAP_AS(getNode) FileNode operator[](const char *nodename) const
CV_WRAP void writeComment(const String &comment, bool append=false)
Writes a comment.
int state
Definition: persistence.hpp:462
State
Definition: persistence.hpp:324
@ INSIDE_MAP
Definition: persistence.hpp:328
@ NAME_EXPECTED
Definition: persistence.hpp:327
virtual CV_WRAP bool open(const String &filename, int flags, const String &encoding=String())
Opens a file.
CV_WRAP int getFormat() const
Returns the current format.
CV_WRAP void write(const String &name, const String &val)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static String getDefaultObjectName(const String &filename)
Returns the normalized object name for the specified name of a file.
virtual CV_WRAP bool isOpened() const
Checks whether the file is opened.
CV_WRAP FileStorage(const String &filename, int flags, const String &encoding=String())
Opens a file.
FileNode operator[](const String &nodename) const
Returns the specified element of the top-level mapping.
std::string elname
Definition: persistence.hpp:463
Ptr< Impl > p
Definition: persistence.hpp:465
virtual CV_WRAP String releaseAndGetString()
Closes the file and releases all the memory buffers.
Data structure for salient point detectors.
Definition: types.hpp:745
CV_PROP_RW float angle
Definition: types.hpp:806
CV_PROP_RW Point2f pt
coordinates of the keypoints
Definition: types.hpp:804
CV_PROP_RW int octave
octave (pyramid layer) from which the keypoint has been extracted
Definition: types.hpp:810
CV_PROP_RW float response
the response by which the most strong keypoints have been selected. Can be used for the further sorti...
Definition: types.hpp:809
CV_PROP_RW int class_id
object class (if the keypoints need to be clustered by an object they belong to)
Definition: types.hpp:811
CV_PROP_RW float size
diameter of the meaningful keypoint neighborhood
Definition: types.hpp:805
n-dimensional dense array class
Definition: mat.hpp:812
Template class for small matrices whose type and size are known at compilation time.
Definition: matx.hpp:100
_Tp val[m *n]
matrix elements
Definition: matx.hpp:218
Template class for 3D points specified by its coordinates x, y and z.
Definition: types.hpp:255
Template class for 2D points specified by its coordinates x and y.
Definition: types.hpp:163
_Tp y
y coordinate of the point
Definition: types.hpp:202
_Tp x
x coordinate of the point
Definition: types.hpp:201
Template class specifying a continuous subsequence (slice) of a sequence.
Definition: types.hpp:623
int end
Definition: types.hpp:631
int start
Definition: types.hpp:631
Template class for 2D rectangles.
Definition: types.hpp:444
Template class for a 4-element vector derived from Vec.
Definition: types.hpp:670
Template class for specifying the size of an image or rectangle.
Definition: types.hpp:335
_Tp height
the height
Definition: types.hpp:363
_Tp width
the width
Definition: types.hpp:362
The class SparseMat represents multi-dimensional sparse numerical arrays.
Definition: mat.hpp:2735
Template class for short numerical vectors, a partial case of Matx.
Definition: matx.hpp:369
InputArrayOfArrays Size InputOutputArray InputOutputArray OutputArrayOfArrays OutputArrayOfArrays OutputArray OutputArray OutputArray int flags
Definition: calib3d.hpp:1617
Point_< int > Point2i
Definition: types.hpp:205
std::string String
Definition: cvstd.hpp:151
static bool operator!=(const Matx< _Tp, m, n > &a, const Matx< _Tp, m, n > &b)
static bool operator==(const Matx< _Tp, m, n > &a, const Matx< _Tp, m, n > &b)
int CvScalar value
Definition: core_c.h:720
int int channels
Definition: core_c.h:100
CvArr const CvMat * mat
Definition: core_c.h:1308
int int type
Definition: core_c.h:221
int count
Definition: core_c.h:1413
const char const char ** filename
Definition: core_c.h:2630
const CvArr CvArr * x
Definition: core_c.h:1195
signed char schar
Definition: interface.h:48
unsigned char uchar
Definition: interface.h:51
unsigned short ushort
Definition: interface.h:52
CV_INLINE v_reg< _Tp, n > & operator+=(v_reg< _Tp, n > &a, const v_reg< _Tp, n > &b)
#define CV_EXPORTS_W_SIMPLE
Definition: cvdef.h:473
#define CV_EXPORTS
Definition: cvdef.h:435
uchar saturate_cast< uchar >(schar v)
Definition: saturate.hpp:101
#define CV_Error(code, msg)
Call the error handler.
Definition: base.hpp:320
#define CV_EXPORTS_W
Definition: cvdef.h:472
short saturate_cast< short >(ushort v)
Definition: saturate.hpp:130
ushort saturate_cast< ushort >(schar v)
Definition: saturate.hpp:121
schar saturate_cast< schar >(uchar v)
Definition: saturate.hpp:111
#define CV_WRAP
Definition: cvdef.h:481
#define CV_Assert(expr)
Checks a condition at runtime and throws exception if it fails.
Definition: base.hpp:342
class CV_EXPORTS FileNodeIterator
Definition: persistence.hpp:298
std::ostream & operator<<(std::ostream &, const DualQuat< _Tp > &)
CvPoint2D32f pt[4]
Definition: imgproc_c.h:571
CvRect r
Definition: imgproc_c.h:984
CvArr CvArr * temp
Definition: imgproc_c.h:329
@ StsError
unknown /unspecified error
Definition: base.hpp:71
"black box" representation of the file storage associated with a file on disk.
Definition: calib3d.hpp:441
CV_EXPORTS void read(const FileNode &node, int &value, int default_value)
CV_EXPORTS void writeScalar(FileStorage &fs, int value)
static bool operator<(const FileNodeIterator &it1, const FileNodeIterator &it2)
Definition: persistence.hpp:1303
DualQuat< T > operator*(const T a, const DualQuat< T > &q)
Definition: dualquaternion.inl.hpp:274
DualQuat< T > operator-(const DualQuat< T > &q, const T a)
Definition: dualquaternion.inl.hpp:255
CV_EXPORTS void write(FileStorage &fs, const String &name, int value)
static FileNodeIterator & operator>>(FileNodeIterator &it, _Tp &value)
Reads data from a file storage.
Definition: persistence.hpp:1227
float x
Definition: types_c.h:978
float y
Definition: types_c.h:979
int width
Definition: types_c.h:835
int y
Definition: types_c.h:834
int x
Definition: types_c.h:833
int height
Definition: types_c.h:836
Definition: traits.hpp:402