Ask Your Question
0

How to read / write xml file in Java

asked 2015-08-02 07:11:03 -0600

JVorwald gravatar image

Has anyone written the calibration / distortion matrix from Java and have them read by a c++ code using xml?

edit retag flag offensive close merge delete

Comments

the FileStorage api is not available from java, so i guess, you better write a simple text file (it's just 9 numbers for the cam-matrix, and another 5 for the dist-coeffs)

berak gravatar imageberak ( 2015-08-03 09:11:32 -0600 )edit

OK, so what is the xml / yml format for cam/dist data? Did you down vote the question because you know the answer but think the question is trivial or not valid?

JVorwald gravatar imageJVorwald ( 2015-08-15 10:41:08 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-08-15 10:36:51 -0600

JVorwald gravatar image

updated 2015-08-15 10:43:58 -0600

This example writes the calibration and distortion matrix in c++ to either xml or yml, demonstrating the file format. Here's a copy of the code in case the link breaks. Change the suffix to xml to see that format.

#include "opencv2/opencv.hpp"
#include <time.h>

using namespace cv;

int main(int, char** argv)
{
    FileStorage fs("test.yml", FileStorage::WRITE);

    fs << "frameCount" << 5;
    time_t rawtime; time(&rawtime);
    fs << "calibrationDate" << asctime(localtime(&rawtime));
    Mat cameraMatrix = (Mat_<double>(3,3) << 1000, 0, 320, 0, 1000, 240, 0, 0, 1);
    Mat distCoeffs = (Mat_<double>(5,1) << 0.1, 0.01, -0.001, 0, 0);
    fs << "cameraMatrix" << cameraMatrix << "distCoeffs" << distCoeffs;
    fs << "features" << "[";
    for( int i = 0; i < 3; i++ )
    {
        int x = rand() % 640;
        int y = rand() % 480;
        uchar lbp = rand() % 256;

        fs << "{:" << "x" << x << "y" << y << "lbp" << "[:";
        for( int j = 0; j < 8; j++ )
            fs << ((lbp >> j) & 1);
        fs << "]" << "}";
    }
    fs << "]";
    fs.release();
    return 0;
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-08-02 07:11:03 -0600

Seen: 1,056 times

Last updated: Aug 15 '15