12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364 |
- #ifndef OPENCV_CORE_PERSISTENCE_HPP
- #define OPENCV_CORE_PERSISTENCE_HPP
- #ifndef CV_DOXYGEN
- #define CV__LEGACY_PERSISTENCE
- #endif
- #ifndef __cplusplus
- # error persistence.hpp header must be compiled as C++
- #endif
- typedef struct CvFileStorage CvFileStorage;
- typedef struct CvFileNode CvFileNode;
- typedef struct CvMat CvMat;
- typedef struct CvMatND CvMatND;
- #include "opencv2/core/types.hpp"
- #include "opencv2/core/mat.hpp"
- namespace cv {
- class CV_EXPORTS FileNode;
- class CV_EXPORTS FileNodeIterator;
- class CV_EXPORTS_W FileStorage
- {
- public:
-
- enum Mode
- {
- READ = 0,
- WRITE = 1,
- APPEND = 2,
- MEMORY = 4,
-
- FORMAT_MASK = (7<<3),
- FORMAT_AUTO = 0,
- FORMAT_XML = (1<<3),
- FORMAT_YAML = (2<<3),
- FORMAT_JSON = (3<<3),
- BASE64 = 64,
- WRITE_BASE64 = BASE64 | WRITE,
- };
- enum
- {
- UNDEFINED = 0,
- VALUE_EXPECTED = 1,
- NAME_EXPECTED = 2,
- INSIDE_MAP = 4
- };
-
- CV_WRAP FileStorage();
-
- CV_WRAP FileStorage(const String& source, int flags, const String& encoding=String());
-
- FileStorage(CvFileStorage* fs, bool owning=true);
-
- virtual ~FileStorage();
-
- CV_WRAP virtual bool open(const String& filename, int flags, const String& encoding=String());
-
- CV_WRAP virtual bool isOpened() const;
-
- CV_WRAP virtual void release();
-
- CV_WRAP virtual String releaseAndGetString();
-
- CV_WRAP FileNode getFirstTopLevelNode() const;
-
- CV_WRAP FileNode root(int streamidx=0) const;
-
- FileNode operator[](const String& nodename) const;
-
- CV_WRAP_AS(getNode) FileNode operator[](const char* nodename) const;
-
- CvFileStorage* operator *() { return fs.get(); }
-
- const CvFileStorage* operator *() const { return fs.get(); }
-
- void writeRaw( const String& fmt, const uchar* vec, size_t len );
-
- void writeObj( const String& name, const void* obj );
-
- CV_WRAP void write(const String& name, double val);
-
- CV_WRAP void write(const String& name, const String& val);
-
- CV_WRAP void write(const String& name, InputArray val);
-
- CV_WRAP void writeComment(const String& comment, bool append = false);
-
- static String getDefaultObjectName(const String& filename);
-
- CV_WRAP int getFormat() const;
- Ptr<CvFileStorage> fs;
- String elname;
- std::vector<char> structs;
- int state;
- };
- template<> CV_EXPORTS void DefaultDeleter<CvFileStorage>::operator ()(CvFileStorage* obj) const;
- class CV_EXPORTS_W_SIMPLE FileNode
- {
- public:
-
- enum Type
- {
- NONE = 0,
- INT = 1,
- REAL = 2,
- FLOAT = REAL,
- STR = 3,
- STRING = STR,
- REF = 4,
- SEQ = 5,
- MAP = 6,
- TYPE_MASK = 7,
- FLOW = 8,
- USER = 16,
- EMPTY = 32,
- NAMED = 64
- };
-
- CV_WRAP FileNode();
-
- FileNode(const CvFileStorage* fs, const CvFileNode* node);
-
- FileNode(const FileNode& node);
-
- FileNode operator[](const String& nodename) const;
-
- CV_WRAP_AS(getNode) FileNode operator[](const char* nodename) const;
-
- CV_WRAP_AS(at) FileNode operator[](int i) const;
-
- CV_WRAP int type() const;
-
- CV_WRAP bool empty() const;
-
- CV_WRAP bool isNone() const;
-
- CV_WRAP bool isSeq() const;
-
- CV_WRAP bool isMap() const;
-
- CV_WRAP bool isInt() const;
-
- CV_WRAP bool isReal() const;
-
- CV_WRAP bool isString() const;
-
- CV_WRAP bool isNamed() const;
-
- CV_WRAP String name() const;
-
- CV_WRAP size_t size() const;
-
- operator int() const;
-
- operator float() const;
-
- operator double() const;
-
- operator String() const;
- operator std::string() const;
-
- CvFileNode* operator *();
-
- const CvFileNode* operator* () const;
-
- FileNodeIterator begin() const;
-
- FileNodeIterator end() const;
-
- void readRaw( const String& fmt, uchar* vec, size_t len ) const;
-
- void* readObj() const;
-
- CV_WRAP double real() const;
-
- CV_WRAP String string() const;
-
- CV_WRAP Mat mat() const;
-
- const CvFileStorage* fs;
- const CvFileNode* node;
- };
- class CV_EXPORTS FileNodeIterator
- {
- public:
-
- FileNodeIterator();
-
- FileNodeIterator(const CvFileStorage* fs, const CvFileNode* node, size_t ofs=0);
-
- FileNodeIterator(const FileNodeIterator& it);
-
- FileNode operator *() const;
-
- FileNode operator ->() const;
-
- FileNodeIterator& operator ++ ();
-
- FileNodeIterator operator ++ (int);
-
- FileNodeIterator& operator -- ();
-
- FileNodeIterator operator -- (int);
-
- FileNodeIterator& operator += (int ofs);
-
- FileNodeIterator& operator -= (int ofs);
-
- FileNodeIterator& readRaw( const String& fmt, uchar* vec,
- size_t maxCount=(size_t)INT_MAX );
- struct SeqReader
- {
- int header_size;
- void* seq;
- void* block;
- schar* ptr;
- schar* block_min;
- schar* block_max;
- int delta_index;
- schar* prev_elem;
- };
- const CvFileStorage* fs;
- const CvFileNode* container;
- SeqReader reader;
- size_t remaining;
- };
- CV_EXPORTS void write( FileStorage& fs, const String& name, int value );
- CV_EXPORTS void write( FileStorage& fs, const String& name, float value );
- CV_EXPORTS void write( FileStorage& fs, const String& name, double value );
- CV_EXPORTS void write( FileStorage& fs, const String& name, const String& value );
- CV_EXPORTS void write( FileStorage& fs, const String& name, const Mat& value );
- CV_EXPORTS void write( FileStorage& fs, const String& name, const SparseMat& value );
- #ifdef CV__LEGACY_PERSISTENCE
- CV_EXPORTS void write( FileStorage& fs, const String& name, const std::vector<KeyPoint>& value);
- CV_EXPORTS void write( FileStorage& fs, const String& name, const std::vector<DMatch>& value);
- #endif
- CV_EXPORTS void writeScalar( FileStorage& fs, int value );
- CV_EXPORTS void writeScalar( FileStorage& fs, float value );
- CV_EXPORTS void writeScalar( FileStorage& fs, double value );
- CV_EXPORTS void writeScalar( FileStorage& fs, const String& value );
- CV_EXPORTS void read(const FileNode& node, int& value, int default_value);
- CV_EXPORTS void read(const FileNode& node, float& value, float default_value);
- CV_EXPORTS void read(const FileNode& node, double& value, double default_value);
- CV_EXPORTS void read(const FileNode& node, String& value, const String& default_value);
- CV_EXPORTS void read(const FileNode& node, std::string& value, const std::string& default_value);
- CV_EXPORTS void read(const FileNode& node, Mat& mat, const Mat& default_mat = Mat() );
- CV_EXPORTS void read(const FileNode& node, SparseMat& mat, const SparseMat& default_mat = SparseMat() );
- #ifdef CV__LEGACY_PERSISTENCE
- CV_EXPORTS void read(const FileNode& node, std::vector<KeyPoint>& keypoints);
- CV_EXPORTS void read(const FileNode& node, std::vector<DMatch>& matches);
- #endif
- CV_EXPORTS void read(const FileNode& node, KeyPoint& value, const KeyPoint& default_value);
- CV_EXPORTS void read(const FileNode& node, DMatch& value, const DMatch& default_value);
- template<typename _Tp> static inline void read(const FileNode& node, Point_<_Tp>& value, const Point_<_Tp>& default_value)
- {
- std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp;
- value = temp.size() != 2 ? default_value : Point_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]));
- }
- template<typename _Tp> static inline void read(const FileNode& node, Point3_<_Tp>& value, const Point3_<_Tp>& default_value)
- {
- std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp;
- value = temp.size() != 3 ? default_value : Point3_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]),
- saturate_cast<_Tp>(temp[2]));
- }
- template<typename _Tp> static inline void read(const FileNode& node, Size_<_Tp>& value, const Size_<_Tp>& default_value)
- {
- std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp;
- value = temp.size() != 2 ? default_value : Size_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]));
- }
- template<typename _Tp> static inline void read(const FileNode& node, Complex<_Tp>& value, const Complex<_Tp>& default_value)
- {
- std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp;
- value = temp.size() != 2 ? default_value : Complex<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]));
- }
- template<typename _Tp> static inline void read(const FileNode& node, Rect_<_Tp>& value, const Rect_<_Tp>& default_value)
- {
- std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp;
- value = temp.size() != 4 ? default_value : Rect_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]),
- saturate_cast<_Tp>(temp[2]), saturate_cast<_Tp>(temp[3]));
- }
- template<typename _Tp, int cn> static inline void read(const FileNode& node, Vec<_Tp, cn>& value, const Vec<_Tp, cn>& default_value)
- {
- std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp;
- value = temp.size() != cn ? default_value : Vec<_Tp, cn>(&temp[0]);
- }
- template<typename _Tp> static inline void read(const FileNode& node, Scalar_<_Tp>& value, const Scalar_<_Tp>& default_value)
- {
- std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp;
- value = temp.size() != 4 ? default_value : Scalar_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]),
- saturate_cast<_Tp>(temp[2]), saturate_cast<_Tp>(temp[3]));
- }
- static inline void read(const FileNode& node, Range& value, const Range& default_value)
- {
- Point2i temp(value.start, value.end); const Point2i default_temp = Point2i(default_value.start, default_value.end);
- read(node, temp, default_temp);
- value.start = temp.x; value.end = temp.y;
- }
- CV_EXPORTS FileStorage& operator << (FileStorage& fs, const String& str);
- namespace internal
- {
- class CV_EXPORTS WriteStructContext
- {
- public:
- WriteStructContext(FileStorage& _fs, const String& name, int flags, const String& typeName = String());
- ~WriteStructContext();
- private:
- FileStorage* fs;
- };
- template<typename _Tp, int numflag> class VecWriterProxy
- {
- public:
- VecWriterProxy( FileStorage* _fs ) : fs(_fs) {}
- void operator()(const std::vector<_Tp>& vec) const
- {
- size_t count = vec.size();
- for (size_t i = 0; i < count; i++)
- write(*fs, vec[i]);
- }
- private:
- FileStorage* fs;
- };
- template<typename _Tp> class VecWriterProxy<_Tp, 1>
- {
- public:
- VecWriterProxy( FileStorage* _fs ) : fs(_fs) {}
- void operator()(const std::vector<_Tp>& vec) const
- {
- int _fmt = traits::SafeFmt<_Tp>::fmt;
- char fmt[] = { (char)((_fmt >> 8) + '1'), (char)_fmt, '\0' };
- fs->writeRaw(fmt, !vec.empty() ? (uchar*)&vec[0] : 0, vec.size() * sizeof(_Tp));
- }
- private:
- FileStorage* fs;
- };
- template<typename _Tp, int numflag> class VecReaderProxy
- {
- public:
- VecReaderProxy( FileNodeIterator* _it ) : it(_it) {}
- void operator()(std::vector<_Tp>& vec, size_t count) const
- {
- count = std::min(count, it->remaining);
- vec.resize(count);
- for (size_t i = 0; i < count; i++, ++(*it))
- read(**it, vec[i], _Tp());
- }
- private:
- FileNodeIterator* it;
- };
- template<typename _Tp> class VecReaderProxy<_Tp, 1>
- {
- public:
- VecReaderProxy( FileNodeIterator* _it ) : it(_it) {}
- void operator()(std::vector<_Tp>& vec, size_t count) const
- {
- size_t remaining = it->remaining;
- size_t cn = DataType<_Tp>::channels;
- int _fmt = traits::SafeFmt<_Tp>::fmt;
- char fmt[] = { (char)((_fmt >> 8)+'1'), (char)_fmt, '\0' };
- size_t remaining1 = remaining / cn;
- count = count < remaining1 ? count : remaining1;
- vec.resize(count);
- it->readRaw(fmt, !vec.empty() ? (uchar*)&vec[0] : 0, count*sizeof(_Tp));
- }
- private:
- FileNodeIterator* it;
- };
- }
- template<typename _Tp> static inline
- void write(FileStorage& fs, const _Tp& value)
- {
- write(fs, String(), value);
- }
- template<> inline
- void write( FileStorage& fs, const int& value )
- {
- writeScalar(fs, value);
- }
- template<> inline
- void write( FileStorage& fs, const float& value )
- {
- writeScalar(fs, value);
- }
- template<> inline
- void write( FileStorage& fs, const double& value )
- {
- writeScalar(fs, value);
- }
- template<> inline
- void write( FileStorage& fs, const String& value )
- {
- writeScalar(fs, value);
- }
- template<typename _Tp> static inline
- void write(FileStorage& fs, const Point_<_Tp>& pt )
- {
- write(fs, pt.x);
- write(fs, pt.y);
- }
- template<typename _Tp> static inline
- void write(FileStorage& fs, const Point3_<_Tp>& pt )
- {
- write(fs, pt.x);
- write(fs, pt.y);
- write(fs, pt.z);
- }
- template<typename _Tp> static inline
- void write(FileStorage& fs, const Size_<_Tp>& sz )
- {
- write(fs, sz.width);
- write(fs, sz.height);
- }
- template<typename _Tp> static inline
- void write(FileStorage& fs, const Complex<_Tp>& c )
- {
- write(fs, c.re);
- write(fs, c.im);
- }
- template<typename _Tp> static inline
- void write(FileStorage& fs, const Rect_<_Tp>& r )
- {
- write(fs, r.x);
- write(fs, r.y);
- write(fs, r.width);
- write(fs, r.height);
- }
- template<typename _Tp, int cn> static inline
- void write(FileStorage& fs, const Vec<_Tp, cn>& v )
- {
- for(int i = 0; i < cn; i++)
- write(fs, v.val[i]);
- }
- template<typename _Tp> static inline
- void write(FileStorage& fs, const Scalar_<_Tp>& s )
- {
- write(fs, s.val[0]);
- write(fs, s.val[1]);
- write(fs, s.val[2]);
- write(fs, s.val[3]);
- }
- static inline
- void write(FileStorage& fs, const Range& r )
- {
- write(fs, r.start);
- write(fs, r.end);
- }
- template<typename _Tp> static inline
- void write( FileStorage& fs, const std::vector<_Tp>& vec )
- {
- cv::internal::VecWriterProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0> w(&fs);
- w(vec);
- }
- template<typename _Tp> static inline
- void write(FileStorage& fs, const String& name, const Point_<_Tp>& pt )
- {
- cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW);
- write(fs, pt);
- }
- template<typename _Tp> static inline
- void write(FileStorage& fs, const String& name, const Point3_<_Tp>& pt )
- {
- cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW);
- write(fs, pt);
- }
- template<typename _Tp> static inline
- void write(FileStorage& fs, const String& name, const Size_<_Tp>& sz )
- {
- cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW);
- write(fs, sz);
- }
- template<typename _Tp> static inline
- void write(FileStorage& fs, const String& name, const Complex<_Tp>& c )
- {
- cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW);
- write(fs, c);
- }
- template<typename _Tp> static inline
- void write(FileStorage& fs, const String& name, const Rect_<_Tp>& r )
- {
- cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW);
- write(fs, r);
- }
- template<typename _Tp, int cn> static inline
- void write(FileStorage& fs, const String& name, const Vec<_Tp, cn>& v )
- {
- cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW);
- write(fs, v);
- }
- template<typename _Tp> static inline
- void write(FileStorage& fs, const String& name, const Scalar_<_Tp>& s )
- {
- cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW);
- write(fs, s);
- }
- static inline
- void write(FileStorage& fs, const String& name, const Range& r )
- {
- cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW);
- write(fs, r);
- }
- static inline
- void write(FileStorage& fs, const String& name, const KeyPoint& kpt)
- {
- cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW);
- write(fs, kpt.pt.x);
- write(fs, kpt.pt.y);
- write(fs, kpt.size);
- write(fs, kpt.angle);
- write(fs, kpt.response);
- write(fs, kpt.octave);
- write(fs, kpt.class_id);
- }
- static inline
- void write(FileStorage& fs, const String& name, const DMatch& m)
- {
- cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW);
- write(fs, m.queryIdx);
- write(fs, m.trainIdx);
- write(fs, m.imgIdx);
- write(fs, m.distance);
- }
- template<typename _Tp> static inline
- void write( FileStorage& fs, const String& name, const std::vector<_Tp>& vec )
- {
- cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+(traits::SafeFmt<_Tp>::fmt != 0 ? FileNode::FLOW : 0));
- write(fs, vec);
- }
- template<typename _Tp> static inline
- void write( FileStorage& fs, const String& name, const std::vector< std::vector<_Tp> >& vec )
- {
- cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ);
- for(size_t i = 0; i < vec.size(); i++)
- {
- cv::internal::WriteStructContext ws_(fs, name, FileNode::SEQ+(traits::SafeFmt<_Tp>::fmt != 0 ? FileNode::FLOW : 0));
- write(fs, vec[i]);
- }
- }
- #ifdef CV__LEGACY_PERSISTENCE
- static inline void write(FileStorage& fs, const KeyPoint& kpt) { write(fs, String(), kpt); }
- static inline void write(FileStorage& fs, const DMatch& m) { write(fs, String(), m); }
- static inline void write(FileStorage& fs, const std::vector<KeyPoint>& vec)
- {
- cv::internal::VecWriterProxy<KeyPoint, 0> w(&fs);
- w(vec);
- }
- static inline void write(FileStorage& fs, const std::vector<DMatch>& vec)
- {
- cv::internal::VecWriterProxy<DMatch, 0> w(&fs);
- w(vec);
- }
- #endif
- static inline
- void read(const FileNode& node, bool& value, bool default_value)
- {
- int temp;
- read(node, temp, (int)default_value);
- value = temp != 0;
- }
- static inline
- void read(const FileNode& node, uchar& value, uchar default_value)
- {
- int temp;
- read(node, temp, (int)default_value);
- value = saturate_cast<uchar>(temp);
- }
- static inline
- void read(const FileNode& node, schar& value, schar default_value)
- {
- int temp;
- read(node, temp, (int)default_value);
- value = saturate_cast<schar>(temp);
- }
- static inline
- void read(const FileNode& node, ushort& value, ushort default_value)
- {
- int temp;
- read(node, temp, (int)default_value);
- value = saturate_cast<ushort>(temp);
- }
- static inline
- void read(const FileNode& node, short& value, short default_value)
- {
- int temp;
- read(node, temp, (int)default_value);
- value = saturate_cast<short>(temp);
- }
- template<typename _Tp> static inline
- void read( FileNodeIterator& it, std::vector<_Tp>& vec, size_t maxCount = (size_t)INT_MAX )
- {
- cv::internal::VecReaderProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0> r(&it);
- r(vec, maxCount);
- }
- template<typename _Tp> static inline
- void read( const FileNode& node, std::vector<_Tp>& vec, const std::vector<_Tp>& default_value = std::vector<_Tp>() )
- {
- if(!node.node)
- vec = default_value;
- else
- {
- FileNodeIterator it = node.begin();
- read( it, vec );
- }
- }
- static inline
- void read( const FileNode& node, std::vector<KeyPoint>& vec, const std::vector<KeyPoint>& default_value )
- {
- if(!node.node)
- vec = default_value;
- else
- read(node, vec);
- }
- static inline
- void read( const FileNode& node, std::vector<DMatch>& vec, const std::vector<DMatch>& default_value )
- {
- if(!node.node)
- vec = default_value;
- else
- read(node, vec);
- }
- template<typename _Tp> static inline
- FileStorage& operator << (FileStorage& fs, const _Tp& value)
- {
- if( !fs.isOpened() )
- return fs;
- if( fs.state == FileStorage::NAME_EXPECTED + FileStorage::INSIDE_MAP )
- CV_Error( Error::StsError, "No element name has been given" );
- write( fs, fs.elname, value );
- if( fs.state & FileStorage::INSIDE_MAP )
- fs.state = FileStorage::NAME_EXPECTED + FileStorage::INSIDE_MAP;
- return fs;
- }
- static inline
- FileStorage& operator << (FileStorage& fs, const char* str)
- {
- return (fs << String(str));
- }
- static inline
- FileStorage& operator << (FileStorage& fs, char* value)
- {
- return (fs << String(value));
- }
- template<typename _Tp> static inline
- FileNodeIterator& operator >> (FileNodeIterator& it, _Tp& value)
- {
- read( *it, value, _Tp());
- return ++it;
- }
- template<typename _Tp> static inline
- FileNodeIterator& operator >> (FileNodeIterator& it, std::vector<_Tp>& vec)
- {
- cv::internal::VecReaderProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0> r(&it);
- r(vec, (size_t)INT_MAX);
- return it;
- }
- template<typename _Tp> static inline
- void operator >> (const FileNode& n, _Tp& value)
- {
- read( n, value, _Tp());
- }
- template<typename _Tp> static inline
- void operator >> (const FileNode& n, std::vector<_Tp>& vec)
- {
- FileNodeIterator it = n.begin();
- it >> vec;
- }
- static inline
- void operator >> (const FileNode& n, KeyPoint& kpt)
- {
- FileNodeIterator it = n.begin();
- it >> kpt.pt.x >> kpt.pt.y >> kpt.size >> kpt.angle >> kpt.response >> kpt.octave >> kpt.class_id;
- }
- #ifdef CV__LEGACY_PERSISTENCE
- static inline
- void operator >> (const FileNode& n, std::vector<KeyPoint>& vec)
- {
- read(n, vec);
- }
- static inline
- void operator >> (const FileNode& n, std::vector<DMatch>& vec)
- {
- read(n, vec);
- }
- #endif
- static inline
- void operator >> (const FileNode& n, DMatch& m)
- {
- FileNodeIterator it = n.begin();
- it >> m.queryIdx >> m.trainIdx >> m.imgIdx >> m.distance;
- }
- static inline
- bool operator == (const FileNodeIterator& it1, const FileNodeIterator& it2)
- {
- return it1.fs == it2.fs && it1.container == it2.container &&
- it1.reader.ptr == it2.reader.ptr && it1.remaining == it2.remaining;
- }
- static inline
- bool operator != (const FileNodeIterator& it1, const FileNodeIterator& it2)
- {
- return !(it1 == it2);
- }
- static inline
- ptrdiff_t operator - (const FileNodeIterator& it1, const FileNodeIterator& it2)
- {
- return it2.remaining - it1.remaining;
- }
- static inline
- bool operator < (const FileNodeIterator& it1, const FileNodeIterator& it2)
- {
- return it1.remaining > it2.remaining;
- }
- inline FileNode FileStorage::getFirstTopLevelNode() const { FileNode r = root(); FileNodeIterator it = r.begin(); return it != r.end() ? *it : FileNode(); }
- inline FileNode::FileNode() : fs(0), node(0) {}
- inline FileNode::FileNode(const CvFileStorage* _fs, const CvFileNode* _node) : fs(_fs), node(_node) {}
- inline FileNode::FileNode(const FileNode& _node) : fs(_node.fs), node(_node.node) {}
- inline bool FileNode::empty() const { return node == 0; }
- inline bool FileNode::isNone() const { return type() == NONE; }
- inline bool FileNode::isSeq() const { return type() == SEQ; }
- inline bool FileNode::isMap() const { return type() == MAP; }
- inline bool FileNode::isInt() const { return type() == INT; }
- inline bool FileNode::isReal() const { return type() == REAL; }
- inline bool FileNode::isString() const { return type() == STR; }
- inline CvFileNode* FileNode::operator *() { return (CvFileNode*)node; }
- inline const CvFileNode* FileNode::operator* () const { return node; }
- inline FileNode::operator int() const { int value; read(*this, value, 0); return value; }
- inline FileNode::operator float() const { float value; read(*this, value, 0.f); return value; }
- inline FileNode::operator double() const { double value; read(*this, value, 0.); return value; }
- inline FileNode::operator String() const { String value; read(*this, value, value); return value; }
- inline double FileNode::real() const { return double(*this); }
- inline String FileNode::string() const { return String(*this); }
- inline Mat FileNode::mat() const { Mat value; read(*this, value, value); return value; }
- inline FileNodeIterator FileNode::begin() const { return FileNodeIterator(fs, node); }
- inline FileNodeIterator FileNode::end() const { return FileNodeIterator(fs, node, size()); }
- inline void FileNode::readRaw( const String& fmt, uchar* vec, size_t len ) const { begin().readRaw( fmt, vec, len ); }
- inline FileNode FileNodeIterator::operator *() const { return FileNode(fs, (const CvFileNode*)(const void*)reader.ptr); }
- inline FileNode FileNodeIterator::operator ->() const { return FileNode(fs, (const CvFileNode*)(const void*)reader.ptr); }
- inline String::String(const FileNode& fn): cstr_(0), len_(0) { read(fn, *this, *this); }
- CV_EXPORTS void cvStartWriteRawData_Base64(::CvFileStorage * fs, const char* name, int len, const char* dt);
- CV_EXPORTS void cvWriteRawData_Base64(::CvFileStorage * fs, const void* _data, int len);
- CV_EXPORTS void cvEndWriteRawData_Base64(::CvFileStorage * fs);
- CV_EXPORTS void cvWriteMat_Base64(::CvFileStorage* fs, const char* name, const ::CvMat* mat);
- CV_EXPORTS void cvWriteMatND_Base64(::CvFileStorage* fs, const char* name, const ::CvMatND* mat);
- }
- #endif
|