有没有人有一个函数可以在 C++ 中返回 3x3 矩阵的透视投影?
Matrix Perspective()
{
Matrix m(0, 0, 0); // Creates identity matrix
// Perspective projection formulas here
return m;
}
有没有人有一个函数可以在 C++ 中返回 3x3 矩阵的透视投影?
Matrix Perspective()
{
Matrix m(0, 0, 0); // Creates identity matrix
// Perspective projection formulas here
return m;
}
这是一个使用 OpenGL gluPerspective 手册页中的公式以 4x4 矩阵返回它的方法:
静态无效my_PerspectiveFOV(双视场,双方面,双近,双远,双* mret){
双 D2R = M_PI / 180.0;
双 yScale = 1.0 / tan(D2R * fov / 2);
双 xScale = yScale / 方面;
double nearmfar = 近 - 远;
双米[] = {
xScale, 0, 0, 0,
0, yScale, 0, 0,
0, 0, (远 + 近) / nearmfar, -1,
0, 0, 2*far*near / nearmfar, 0
};
memcpy(mret, m, sizeof(double)*16);
}
使用OpenCV 2.0,您几乎可以实现您的伪代码。
有一个Mat用于矩阵和perspectiveTransform透视投影的类。并Mat::eye返回一个单位矩阵。
我链接到的文档适用于 OpenCV 1.1(在 C 中),但从Mat手册中推断 OpenCV 2.0(带有类)中的正确用法非常简单。