Opencv-FileStorage类的数据存取操作与示例
Write cv::Mat Image To File
// C++ code to write an image with arbitrary type
cv::FileStorage fs_i("matrix.yml", cv::FileStorage::WRITE);
fs_i << "mat" << distance_matrix; // distance_matrix is a cv::Mat object
fs_i.release();
# Python code to write the image (OpenCV 3.2)
fs = cv2.FileStorage('matrix.yml', cv2.FILE_STORAGE_WRITE)
fs.write('mat', distance_matrix)
fs.release()
Read cv::Mat Image From File
// C++ code to read the image
cv::FileStorage fs_o("matrix.yml", cv::FileStorage::READ);
fs_o["mat"] >> distance_matrix;
fs_o.release();
# Python code to read the image (OpenCV 3.2)
import cv2
fs = cv2.FileStorage("matrix.yml", cv2.FILE_STORAGE_READ)
fn = fs.getNode("mat")
distance_matrix = fn.mat()
fs.release()