如何加载txt/.pgn.COM文件并将其存储在c++/opencv中的矩阵中

How to load a txt/.pgn.camera file and store it in matrices in c++/opencv

本文关键字:存储 c++ opencv 文件 加载 何加载 txt COM pgn      更新时间:2023-10-16

我想加载一些相机文件,以便计算两幅图像的基本矩阵。这些文件采用.png.camera格式,即space-delimited,来自一个免费数据集。它们看起来像:

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

前3行是相机矩阵K,所以我想把它们存储在一个称为K的矩阵cv::Mat中。

第5-7行是旋转矩阵,最后一行是平移矢量。

我想用这些矩阵做一些进一步的计算。

我想知道我是否可以通过OpenCV(我使用的是2.4.5版本)做到这一点

任何建议都将不胜感激!!!

我不知道是否有一些现有的opencv api,但你自己可以很容易地做到:

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");
}