value = temp.size() != cn ? default_value : Vec<_Tp, cn>(&temp[0]);
}
+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>())
+{
+ Mat temp;
+ read(node, temp); // read as a Mat class
+
+ if (temp.empty())
+ value = default_matx;
+ else
+ value = Matx<_Tp, m, n>(temp);
+}
+
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;
write(fs, v.val[i]);
}
+template<typename _Tp, int m, int n> static inline
+void write(FileStorage& fs, const Matx<_Tp, m, n>& x )
+{
+ write(fs, Mat(x)); // write as a Mat class
+}
+
template<typename _Tp> static inline
void write(FileStorage& fs, const Scalar_<_Tp>& s )
{
write(fs, v);
}
+template<typename _Tp, int m, int n> static inline
+void write(FileStorage& fs, const String& name, const Matx<_Tp, m, n>& x )
+{
+ write(fs, name, Mat(x)); // write as a Mat class
+}
+
template<typename _Tp> static inline
void write(FileStorage& fs, const String& name, const Scalar_<_Tp>& s )
{
ASSERT_EQ(cv::norm(inputMatrix, actualMatrix, NORM_INF), 0.);
}
+TEST(Core_InputOutput, filestorage_matx_io)
+{
+ Matx33d matxTest(1.234, 2, 3, 4, 5, 6, 7, 8, 9.876);
+
+ FileStorage writer("", FileStorage::WRITE | FileStorage::MEMORY);
+ writer << "matxTest" << matxTest;
+ String content = writer.releaseAndGetString();
+
+ FileStorage reader(content, FileStorage::READ | FileStorage::MEMORY);
+ Matx33d matxTestRead;
+ reader["matxTest"] >> matxTestRead;
+ ASSERT_TRUE( cv::norm(matxTest, matxTestRead, NORM_INF) == 0 );
+
+ reader.release();
+}
+
+TEST(Core_InputOutput, filestorage_matx_io_size_mismatch)
+{
+ Matx32d matxTestWrongSize(1, 2, 3, 4, 5, 6);
+
+ FileStorage writer("", FileStorage::WRITE | FileStorage::MEMORY);
+ writer << "matxTestWrongSize" << matxTestWrongSize;
+ String content = writer.releaseAndGetString();
+
+ FileStorage reader(content, FileStorage::READ | FileStorage::MEMORY);
+ Matx33d matxTestRead;
+ try
+ {
+ reader["matxTestWrongSize"] >> matxTestRead;
+ FAIL() << "wrong size matrix read but no exception thrown";
+ }
+ catch (const std::exception&)
+ {
+ }
+
+ reader.release();
+}
+
+TEST(Core_InputOutput, filestorage_matx_io_with_mat)
+{
+ Mat normalMat = Mat::eye(3, 3, CV_64F);
+
+ FileStorage writer("", FileStorage::WRITE | FileStorage::MEMORY);
+ writer << "normalMat" << normalMat;
+ String content = writer.releaseAndGetString();
+
+ FileStorage reader(content, FileStorage::READ | FileStorage::MEMORY);
+ Matx33d matxTestRead;
+ reader["normalMat"] >> matxTestRead;
+ ASSERT_TRUE( cv::norm(Mat::eye(3, 3, CV_64F), matxTestRead, NORM_INF) == 0 );
+
+ reader.release();
+}
+
TEST(Core_InputOutput, filestorage_keypoints_vec_vec_io)
{
vector<vector<KeyPoint> > kptsVec;