Skip to Content
Building Computer Vision Projects with OpenCV 4 and C++
book

Building Computer Vision Projects with OpenCV 4 and C++

by David Millan Escriva, Prateek Joshi, Vinicius G. Mendonca, Roy Shilkrot
March 2019
Intermediate to advanced
538 pages
13h 38m
English
Packt Publishing
Content preview from Building Computer Vision Projects with OpenCV 4 and C++

Writing to FileStorage

To write a file with some OpenCV or other numeric data, we can use the FileStorage class, using a streaming << operator such as STL streaming:

#include "opencv2/opencv.hpp" 
using namespace cv; 
 
int main(int, char** argv) 
{ 
   // create our writer 
    FileStorage fs("test.yml", FileStorage::WRITE); 
    // Save an int 
    int fps= 5; 
    fs << "fps" << fps; 
    // Create some mat sample 
    Mat m1= Mat::eye(2,3, CV_32F); 
    Mat m2= Mat::ones(3,2, CV_32F); 
    Mat result= (m1+1).mul(m1+3); 
    // write the result 
    fs << "Result" << result; 
    // release the file 
    fs.release(); 
 
    FileStorage fs2("test.yml", FileStorage::READ); 
 
    Mat r; 
    fs2["Result"] >> r; 
    std::cout << r << std::endl; 
 
    fs2.release(); 
 
    return 0; 
} 

To create a file storage where we save the data, we only ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning OpenCV 4 Computer Vision with Python 3 - Third Edition

Learning OpenCV 4 Computer Vision with Python 3 - Third Edition

Joseph Howse, Joe Minichino
Modern CMake for C++

Modern CMake for C++

Rafał Świdziński

Publisher Resources

ISBN: 9781838644673Supplemental Content