我尝试使用openCV编写代码,基于Trucco& Verri book pp.159。,以纠正立体图像。整改的目的是在生成DSM时使用它们,尽管代码工作正常但结果是错误的。
小组中的任何人都可以帮我解决问题。
输入如下:
目前的结果是:
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <iomanip>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat input, output;
input = imread("E:\\Gray_Image.bmp", 1);
double alpha = -0.0426, beta = -0.1871, gamma = -179.8781,
dx =1, dy = 1, dz = 16750., f = 16750.;
double w = (double)input.cols;
double h = (double)input.rows;
//the cmera intresic file is
Mat CAM = (Mat_<double>(3, 3) <<
f, 0, w / 2,
0, f, h / 2 - 20,
0, 0, 1 );
// Rotation matrices around the X, Y, and Z axis
Mat RX = (Mat_<double>(3, 3) <<
1, 0, 0,
0, cos(alpha), sin(alpha),
0, -sin(alpha), cos(alpha));
Mat RY = (Mat_<double>(3, 3) <<
cos(beta), 0, -sin(beta),
0, 1, 0,
sin(beta), 0, cos(beta));
Mat RZ = (Mat_<double>(3, 3) <<
cos(gamma), sin(gamma), 0,
-sin(gamma), cos(gamma), 0,
0, 0, 1);
// Composed rotation matrix with (RX, RY, RZ)
Mat R = RX * RY * RZ;
// cout << R << endl;
Mat Te1 = (Mat_<double>(3, 1) <<
dx,
dy,
dz);
Mat Te2 = (Mat_<double>(3, 1) <<
-dy,
dx,
0);
Mat Te3 = (Mat_<double>(3, 1) <<
-(dx * dz),
-(dy * dz),
-(dx*dx + dy*dy));
Mat e1 = Te1 * (1.0 / (sqrt(dx*dx + dy*dy + dz*dz)));// * T;
transpose(e1, Te1);
Mat e2 = Te2 * (1.0 / (sqrt(dx*dx + dy*dy)));// * T;
transpose(e2, Te2);
Mat e3 = Te3 * (1.0 / (sqrt((dx*dx + dy*dy)*(dx*dx + dy*dy + dz*dz))));// * T;
transpose(e3, Te3);
Mat Re(3, 3, CV_32F); //
// add the above row matrix into one
Te1.copyTo(Re.row(0));
Te2.copyTo(Re.row(1));
Te3.copyTo(Re.row(2));
cout << CAM << endl;
cout << Re << endl;
warpPerspective(input, output, Re, input.size(), INTER_LANCZOS4);
imshow("Input", input);
imshow("Output", output);
////////////////////////////
waitKey(0);
return 0;
}