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 マトリックスでそれを返すものです。
static void my_PerspectiveFOV(double fov, doubleアスペクト, double near, double far, double* mret) {
ダブル D2R = M_PI / 180.0;
double yScale = 1.0 / tan(D2R * fov / 2);
double xScale = yScale / アスペクト;
double nearmfar = 近く - 遠く;
double m[] = {
xScale, 0, 0, 0,
0、y スケール、0、0、
0, 0, (遠い + 近い) / nearmfar, -1,
0, 0, 2*遠*近/遠近, 0
};
memcpy(mret, m, sizeof(double)*16);
}
OpenCV 2.0を使用すると、疑似コードをほぼ実装できます。
Mat行列perspectiveTransform用と透視投影用のクラスがあります。恒等Mat::eye行列を返します。
私がリンクしたドキュメントは OpenCV 1.1 (C 言語) 用ですがMat、マニュアルから OpenCV 2.0 (クラスを含む) での正しい使用法を推測するのは非常に簡単です。