Reputation: 106
I want to load some camera files in order to calculate the fundamental matrix of two images. The files are in .png.camera
format, space-delimited
, from a free dataset. They look like:
2759.48 0 1520.69
0 2764.16 1006.81
0 0 1
0 0 0
0.582226 -0.0983866 -0.807052
-0.813027 -0.0706383 -0.577925
-0.000148752 0.992638 -0.121118
-8.31326 -6.3181 0.16107
The first 3 lines are the camera matrix K, so I want to store them in a matrix cv::Mat called K.
Lines 5-7 are the rotation matrix and last line is the translation vector.
I want to use these matrices to do some further calculations.
I wonder if I can do it through OpenCV (I use version 2.4.5).
Any suggestion would be appreciated!!!
Upvotes: 0
Views: 411
Reputation: 2584
I don't know if there is some existing opencv api but you can easily do it yourself :
float K[3];
float Rot1[9];
float Rot2[9];
float T[3];
FILE* f = fopen(".png.camera", "r");
if (f) {
printf("File successfully opened.\n");
fscanf(f, "%f %f %f", &K[0], &K[1], &K[2]);
fscanf(f, "%f %f %f %f %f %f %f %f %f", &Rot1[0], &Rot1[1], &Rot1[2], &Rot1[3], &Rot1[4], &Rot1[5], &Rot1[6], &Rot1[7], &Rot1[8]);
fscanf(f, "%f %f %f %f %f %f %f %f %f", &Rot2[0], &Rot2[1], &Rot2[2], &Rot2[3], &Rot2[4], &Rot2[5], &Rot2[6], &Rot2[7], &Rot2[8]);
fscanf(f, "%f %f %f", &T[0], &T[1], &T[2]);
fclose(f);
}
else
{
printf("Cannot open file.\n");
}
Upvotes: 1