FileStorage module (YML)

One of the most useful things OpenCV has is YML file library. I canno't believe have easy to use they are. Before I learned this, I was making complicated algorithms and writing array of data like detected keypoints or descriptrs in "txt" file. But there is much simpler solution...


It's pretty straight forward how to use the FileStorage module in OpenCV, I don't think after showing the code snippets I need to explain anything.

Maybe if you don't know the concept of yml or xml files you should go here: http://en.wikipedia.org/wiki/YAML

 

Ok let's get down to bussiness!

 

To write array of data into yml file:

fileString = "keypoints.yml";
cv::FileStorage fs(fileString, cv::FileStorage::WRITE);
 
write(fs,"keyPointsSURF", keypointsSURF);              
write(fs,"descriptorsSURF", descriptorsSURF);  
fs.release()

 

And to access the data you do it like this:

fs.open("keypoints.yml", FileStorage::READ);
    if(fs.isOpened())
    {
        read(fs["descriptorsSURF"], descriptorsSURF); 
        read(fs["keyPointsSURF"], keypointsSURF);   
}   
fs.release();

Just a note:

The "read" command can be swapped with these lines, I personally prefer the "read" method

fs["descriptorsSURF"] >> descriptorsSURF;
fs["keyPointsSURF"] >> keypointsSURF;

 



Related Articles



ADVERTISEMENT

  • James J

    James J in Simple library for driving 20x4 LCD with 4bits

    Very good writeup. I thought had been fighting my code for a week or two and confirmed what I was dooing was right. This overview is the best I have seen for doing the code. You may wish to add one thing though that I have found on another website. Urge people to check the contrast dial on...

    Helpful friend

    Helpful friend in MEMS (Part 1) - Guide to using accelerometer ADXL345

    Start with reading about C language, proceed to reading about Arduino platform/ide proceed to reading about i2c bus proceed to reading about adxl345. Rather not the other way round, although that's probably also possible, but it will be more demanding, as you have already...

    Chris Sparks

    Chris Sparks in Simple TLS/SSL SMTP client for Qt5

    qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed

    Edward Martin

    Edward Martin in Introduction to data encryption

    The introduction to the data encryption is very much helpful as you will get to know about the data encryption procedure which might help you to protect the files and folders. You can check the 

    bean

    bean in DIY 3D printer, AKA RepRap

    The 3D printer creates the dimensional object and with the features of the 3D printer, it executes the process if need further query then visit fix error code 0xc004f074...

    preter jack

    preter jack in Single Cycle MIPS CPU in VHDL

    Single-cycle CPU is more improved than the normal and usual CPUs and it has a lot of advantages and all you can get from fix

    henrydevid

    henrydevid in nRF51 Makefile with Qt Creator

    It is great for all, I have some different tricks if you want to know it then for that I have some different tricks, for that, you want to learn to code. For that, if you want to know it then for that you just visit some tutorial. And from there it is great for all. If you faced any type...