OpenCV/WishList/IO/WriteMatrix
From ProgrammingExamples
This works fine for integer valued matrices, but how do you write a float matrix to a file?
WriteMatrix.cxx
#include "cv.h" #include "opencv2/highgui/highgui.hpp" #include "opencv2/core/core.hpp" #include <iostream> int main(int argc, char*argv[]) { 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; cv::FileStorage fs("test.mat", cv::FileStorage::WRITE); fs << myMatrix; 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_core opencv_highgui opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect opencv_features2d opencv_calib3d opencv_legacy opencv_contrib )