Difference between revisions of "OpenCV/WishList/IO/WriteMatrix"
From ProgrammingExamples
< OpenCV
Daviddoria (Talk | contribs) |
Daviddoria (Talk | contribs) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | + | OpenCV Error: Parsing error (test.mat(0): Valid XML should start with '<?xml ...?>') in icvXMLParse, file /home/doriad/src/OpenCV/modules/core/src/persistence.cpp, line 2136 | |
+ | terminate called after throwing an instance of 'cv::Exception' | ||
+ | what(): /home/doriad/src/OpenCV/modules/core/src/persistence.cpp:2136: error: (-212) test.mat(0): Valid XML should start with '<?xml ...?>' in function icvXMLParse | ||
==WriteMatrix.cxx== | ==WriteMatrix.cxx== | ||
Line 11: | Line 13: | ||
int main(int argc, char*argv[]) | int main(int argc, char*argv[]) | ||
{ | { | ||
+ | // Create a matrix | ||
cv::Mat myMatrix(3,3,CV_32FC1); | cv::Mat myMatrix(3,3,CV_32FC1); | ||
std::cout << "Input:" << std::endl; | std::cout << "Input:" << std::endl; | ||
Line 22: | Line 25: | ||
std::cout << myMatrix << std::endl; | std::cout << myMatrix << std::endl; | ||
− | + | ||
− | cv::FileStorage | + | // Write the matrix to a file |
− | + | cv::FileStorage fsout("test.yml", cv::FileStorage::WRITE); | |
− | + | fsout << "myMatrix" << myMatrix; | |
+ | |||
+ | // Read the file back in to test that it was written correctly | ||
+ | cv::Mat myMatrix2(3,3,CV_32FC1); | ||
+ | cv::FileStorage fsin("test.yml", cv::FileStorage::READ); | ||
+ | fsin["myMatrix"] >> myMatrix2; | ||
+ | |||
+ | std::cout << myMatrix2 << std::endl; | ||
return 0; | return 0; | ||
} | } | ||
+ | |||
Line 44: | Line 55: | ||
ADD_EXECUTABLE(WriteMatrix WriteMatrix.cxx) | ADD_EXECUTABLE(WriteMatrix WriteMatrix.cxx) | ||
− | TARGET_LINK_LIBRARIES(WriteMatrix | + | TARGET_LINK_LIBRARIES(WriteMatrix ${OpenCV_LIBS}) |
− | + | ||
− | + | ||
− | ) | + | |
</source> | </source> |
Latest revision as of 11:25, 20 September 2011
OpenCV Error: Parsing error (test.mat(0): Valid XML should start with '<?xml ...?>') in icvXMLParse, file /home/doriad/src/OpenCV/modules/core/src/persistence.cpp, line 2136 terminate called after throwing an instance of 'cv::Exception'
what(): /home/doriad/src/OpenCV/modules/core/src/persistence.cpp:2136: error: (-212) test.mat(0): Valid XML should start with '<?xml ...?>' in function icvXMLParse
WriteMatrix.cxx
#include "cv.h" #include "opencv2/highgui/highgui.hpp" #include "opencv2/core/core.hpp" #include <iostream> int main(int argc, char*argv[]) { // Create a matrix cv::Mat myMatrix(3,3,CV_32FC1); std::cout << "Input:" << std::endl; for(unsigned int i = 0; i < 3; i++) { for(unsigned int j = 0; j < 3; j++) { myMatrix.at<float>(i,j) = 2.1; } } std::cout << myMatrix << std::endl; // Write the matrix to a file cv::FileStorage fsout("test.yml", cv::FileStorage::WRITE); fsout << "myMatrix" << myMatrix; // Read the file back in to test that it was written correctly cv::Mat myMatrix2(3,3,CV_32FC1); cv::FileStorage fsin("test.yml", cv::FileStorage::READ); fsin["myMatrix"] >> myMatrix2; std::cout << myMatrix2 << std::endl; return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(WriteMatrix) FIND_PACKAGE(OpenCV REQUIRED ) INCLUDE_DIRECTORIES( ${OPENCV_INCLUDE_DIR} ) ADD_EXECUTABLE(WriteMatrix WriteMatrix.cxx) TARGET_LINK_LIBRARIES(WriteMatrix ${OpenCV_LIBS})