Computational biology PhD researcher. Interested in science, software development, and machine learning. I write about medical research at BioSky.co and contribute content to a variety of additional publications.CVAbout
Recently I needed to save some matrices I had generated with OpenCV and C++. This snippet of code shows you how you can do this this and then open the files to retrieve the matrices. You can save the files as either the .yml or .xml format. In the example below, “trainData” and “trainLabels” are the two matrices I want to save:
cv::FileStorage file("tag_data.yml", cv::FileStorage::WRITE); file << "data" << trainData; file << "classes" << trainLabels; file.release(); // later (in another program when you want to get the stored matrices) cv::Mat trainDataCopy, trainLabelsCopy; cv::FileStorage file("tag_data.yml", cv::FileStorage::READ); file["data"] >> trainDataCopy; file["classes"] >> trainLabelsCopy; file.release();
Done. You should now be able to use both matrices.
Latest posts by Jack Simpson (see all)
- Fruit flies, honeybees, and alcohol - October 18, 2017
- I’m going to Silicon Valley! - October 15, 2017
- Sometimes working in the biology department is pretty neat - October 10, 2017