Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileStorage OpenCV

I am trying to save Camera matrix and distortion co efficients for later use but, the code I have written does not seem to work. It is not storing any kind of data on the yml file. Even when I read it back, it does not does not input anything to the specified matrices. Please help me understand if I am doing something wrong. I am using VS2010 with OpenCV 2.4.5

    cv::Mat CameraMatrix, DistCoeffs;
    CameraMatrix = (cv::Mat_<double>(3,3) << 1,2,3,4,5,6,7,8,9);
    DistCoeffs = (cv::Mat_<double>(1,5) << 10, 11, 12, 13, 15);
    cv::FileStorage fs("IntCali.yml", cv::FileStorage::WRITE);
    fs << "CameraMatrix" << CameraMatrix;
    fs << "DistCoeffs" << DistCoeffs;
    fs.release();

    cv::FileStorage fs2("IntCali.yml", cv::FileStorage::READ);
    cv::Mat cm; fs2["CameraMatrix"] >> cm;
    cv::Mat dc;
    fs2["DistCoeffs"] >> dc;
        fs2.release();
like image 958
amoghesturi Avatar asked Nov 29 '25 21:11

amoghesturi


1 Answers

<?xml version="1.0"?>
-<opencv_storage>
-<CameraMatrix type_id="opencv-matrix">
<rows>3</rows>
<cols>3</cols>
<dt>d</dt>
<data> 1. 2. 3. 4. 5. 6. 7. 8. 9.</data>

</CameraMatrix>-<DistCoeffs type_id="opencv-matrix">
<rows>1</rows>
<cols>5</cols>
<dt>d</dt>
<data> 10. 11. 12. 13. 15.</data>
</DistCoeffs>
</opencv_storage>

Works in xml file. If there is no special requirement for yml file only, try xml.

like image 187
Chris Su Avatar answered Dec 03 '25 19:12

Chris Su



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!