如何加载txt/.pgn.COM文件并将其存储在c++/opencv中的矩阵中
How to load a txt/.pgn.camera file and store it in matrices in c++/opencv
我想加载一些相机文件,以便计算两幅图像的基本矩阵。这些文件采用.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");
}
相关文章:
- 将字符串存储在c++中的稳定内存中
- std::原子加载和存储都需要吗
- C++:将控制台输出存储在宏中更好吗
- 使用QProcess执行命令,并将结果存储在QStringList中
- 访问存储在向量C++中的结构的多态成员
- 如何从存储在std::映射中的std::集中删除元素
- 存储模板类型以强制转换回派生<T>
- 类型总是使用其大小存储在内存中吗
- 当字符串存储在变量中时,如何将字符串转换为wchar_t
- 使用无符号字符数组有效存储内存
- 如何在cpp.中使用协议缓冲区存储大缓冲区/数组(char/int)
- 使用 pqxx 将 std::vector 存储在 postgresql 中,并从数据库中检索它
- 带结构的二维矢量:如何存储元素
- 添加存储在向量中的大整数的函数出现问题
- 从文件中读取多个字节,并将它们存储在C++中进行比较
- 在std::vector上存储带有模板的类实例
- 谷歌测试中的期望值存储在哪里
- 为什么C中的通用链表中存储的数据已损坏
- 在c++中获取两个大int,并将它们存储在数组中
- 在reactor中存储eventHandlers的最佳方式是什么