44
44
#ifndef OPENCV_CORE_PERSISTENCE_HPP
45
45
#define OPENCV_CORE_PERSISTENCE_HPP
46
46
47
+ #ifndef CV_DOXYGEN
48
+ // / Define to support persistence legacy formats
49
+ #define CV__LEGACY_PERSISTENCE
50
+ #endif
51
+
47
52
#ifndef __cplusplus
48
53
# error persistence.hpp header must be compiled as C++
49
54
#endif
@@ -700,8 +705,10 @@ CV_EXPORTS void write( FileStorage& fs, const String& name, double value );
700
705
CV_EXPORTS void write ( FileStorage& fs, const String& name, const String& value );
701
706
CV_EXPORTS void write ( FileStorage& fs, const String& name, const Mat& value );
702
707
CV_EXPORTS void write ( FileStorage& fs, const String& name, const SparseMat& value );
708
+ #ifdef CV__LEGACY_PERSISTENCE
703
709
CV_EXPORTS void write ( FileStorage& fs, const String& name, const std::vector<KeyPoint>& value);
704
710
CV_EXPORTS void write ( FileStorage& fs, const String& name, const std::vector<DMatch>& value);
711
+ #endif
705
712
706
713
CV_EXPORTS void writeScalar ( FileStorage& fs, int value );
707
714
CV_EXPORTS void writeScalar ( FileStorage& fs, float value );
@@ -720,8 +727,12 @@ CV_EXPORTS void read(const FileNode& node, String& value, const String& default_
720
727
CV_EXPORTS void read (const FileNode& node, std::string& value, const std::string& default_value);
721
728
CV_EXPORTS void read (const FileNode& node, Mat& mat, const Mat& default_mat = Mat() );
722
729
CV_EXPORTS void read (const FileNode& node, SparseMat& mat, const SparseMat& default_mat = SparseMat() );
730
+ #ifdef CV__LEGACY_PERSISTENCE
723
731
CV_EXPORTS void read (const FileNode& node, std::vector<KeyPoint>& keypoints);
724
732
CV_EXPORTS void read (const FileNode& node, std::vector<DMatch>& matches);
733
+ #endif
734
+ CV_EXPORTS void read (const FileNode& node, KeyPoint& value, const KeyPoint& default_value);
735
+ CV_EXPORTS void read (const FileNode& node, DMatch& value, const DMatch& default_value);
725
736
726
737
template <typename _Tp> static inline void read (const FileNode& node, Point_<_Tp>& value, const Point_<_Tp>& default_value)
727
738
{
@@ -948,54 +959,13 @@ void write(FileStorage& fs, const Scalar_<_Tp>& s )
948
959
write (fs, s.val [3 ]);
949
960
}
950
961
951
- static inline
952
- void write (FileStorage& fs, const KeyPoint& kpt )
953
- {
954
- write (fs, kpt.pt .x );
955
- write (fs, kpt.pt .y );
956
- write (fs, kpt.size );
957
- write (fs, kpt.angle );
958
- write (fs, kpt.response );
959
- write (fs, kpt.octave );
960
- write (fs, kpt.class_id );
961
- }
962
-
963
- static inline
964
- void write (FileStorage& fs, const DMatch& m )
965
- {
966
- write (fs, m.queryIdx );
967
- write (fs, m.trainIdx );
968
- write (fs, m.imgIdx );
969
- write (fs, m.distance );
970
- }
971
-
972
962
static inline
973
963
void write (FileStorage& fs, const Range& r )
974
964
{
975
965
write (fs, r.start );
976
966
write (fs, r.end );
977
967
}
978
968
979
- static inline
980
- void write ( FileStorage& fs, const std::vector<KeyPoint>& vec )
981
- {
982
- size_t npoints = vec.size ();
983
- for (size_t i = 0 ; i < npoints; i++ )
984
- {
985
- write (fs, vec[i]);
986
- }
987
- }
988
-
989
- static inline
990
- void write ( FileStorage& fs, const std::vector<DMatch>& vec )
991
- {
992
- size_t npoints = vec.size ();
993
- for (size_t i = 0 ; i < npoints; i++ )
994
- {
995
- write (fs, vec[i]);
996
- }
997
- }
998
-
999
969
template <typename _Tp> static inline
1000
970
void write ( FileStorage& fs, const std::vector<_Tp>& vec )
1001
971
{
@@ -1060,17 +1030,26 @@ void write(FileStorage& fs, const String& name, const Range& r )
1060
1030
}
1061
1031
1062
1032
static inline
1063
- void write (FileStorage& fs, const String& name, const KeyPoint& r )
1033
+ void write (FileStorage& fs, const String& name, const KeyPoint& kpt )
1064
1034
{
1065
1035
cv::internal::WriteStructContext ws (fs, name, FileNode::SEQ+FileNode::FLOW);
1066
- write (fs, r);
1036
+ write (fs, kpt.pt .x );
1037
+ write (fs, kpt.pt .y );
1038
+ write (fs, kpt.size );
1039
+ write (fs, kpt.angle );
1040
+ write (fs, kpt.response );
1041
+ write (fs, kpt.octave );
1042
+ write (fs, kpt.class_id );
1067
1043
}
1068
1044
1069
1045
static inline
1070
- void write (FileStorage& fs, const String& name, const DMatch& r )
1046
+ void write (FileStorage& fs, const String& name, const DMatch& m )
1071
1047
{
1072
1048
cv::internal::WriteStructContext ws (fs, name, FileNode::SEQ+FileNode::FLOW);
1073
- write (fs, r);
1049
+ write (fs, m.queryIdx );
1050
+ write (fs, m.trainIdx );
1051
+ write (fs, m.imgIdx );
1052
+ write (fs, m.distance );
1074
1053
}
1075
1054
1076
1055
template <typename _Tp> static inline
@@ -1091,6 +1070,24 @@ void write( FileStorage& fs, const String& name, const std::vector< std::vector<
1091
1070
}
1092
1071
}
1093
1072
1073
+ #ifdef CV__LEGACY_PERSISTENCE
1074
+ // This code is not needed anymore, but it is preserved here to keep source compatibility
1075
+ // Implementation is similar to templates instantiations
1076
+ static inline void write (FileStorage& fs, const KeyPoint& kpt) { write (fs, String (), kpt); }
1077
+ static inline void write (FileStorage& fs, const DMatch& m) { write (fs, String (), m); }
1078
+ static inline void write (FileStorage& fs, const std::vector<KeyPoint>& vec)
1079
+ {
1080
+ cv::internal::VecWriterProxy<KeyPoint, 0 > w (&fs);
1081
+ w (vec);
1082
+ }
1083
+ static inline void write (FileStorage& fs, const std::vector<DMatch>& vec)
1084
+ {
1085
+ cv::internal::VecWriterProxy<DMatch, 0 > w (&fs);
1086
+ w (vec);
1087
+
1088
+ }
1089
+ #endif
1090
+
1094
1091
// ! @} FileStorage
1095
1092
1096
1093
// ! @relates cv::FileNode
@@ -1258,28 +1255,29 @@ void operator >> (const FileNode& n, std::vector<_Tp>& vec)
1258
1255
/* * @brief Reads KeyPoint from a file storage.
1259
1256
*/
1260
1257
// It needs special handling because it contains two types of fields, int & float.
1261
- static inline
1262
- void operator >> (const FileNode& n, std::vector<KeyPoint>& vec)
1263
- {
1264
- read (n, vec);
1265
- }
1266
-
1267
1258
static inline
1268
1259
void operator >> (const FileNode& n, KeyPoint& kpt)
1269
1260
{
1270
1261
FileNodeIterator it = n.begin ();
1271
1262
it >> kpt.pt .x >> kpt.pt .y >> kpt.size >> kpt.angle >> kpt.response >> kpt.octave >> kpt.class_id ;
1272
1263
}
1273
1264
1274
- /* * @brief Reads DMatch from a file storage.
1275
- */
1276
- // It needs special handling because it contains two types of fields, int & float.
1265
+ #ifdef CV__LEGACY_PERSISTENCE
1266
+ static inline
1267
+ void operator >> (const FileNode& n, std::vector<KeyPoint>& vec)
1268
+ {
1269
+ read (n, vec);
1270
+ }
1277
1271
static inline
1278
1272
void operator >> (const FileNode& n, std::vector<DMatch>& vec)
1279
1273
{
1280
1274
read (n, vec);
1281
1275
}
1276
+ #endif
1282
1277
1278
+ /* * @brief Reads DMatch from a file storage.
1279
+ */
1280
+ // It needs special handling because it contains two types of fields, int & float.
1283
1281
static inline
1284
1282
void operator >> (const FileNode& n, DMatch& m)
1285
1283
{
0 commit comments