问题:在下面的代码中为什么要进行float angelT = nRows* tan(theta/180*CV_PI)/nCols;这样的角度转换?我不明白这个公式的是怎么得出的?
```c++
int nRows = grayImg.rows;
int nCols = grayImg.cols;
std::cout << "srcImage row:" << nRows << std::endl;
std::cout << "srcImage col:" << nCols << std::endl;
// 获取DFT尺寸
int cRows = cv::getOptimalDFTSize(nRows);
int cCols = cv::getOptimalDFTSize(nCols);
std::cout << "DFTImage row:" << cRows << std::endl;
std::cout << "DFTImage col:" << cCols << std::endl;
cv::Mat sizeConvMat;
copyMakeBorder(grayImg, sizeConvMat, 0, cRows -nRows, 0,
cCols-nCols, cv::BORDER_CONSTANT, cv::Scalar::all(0));
// 通道组建立,
cv::Mat groupMats[] = {cv::Mat_<float>(sizeConvMat),
cv::Mat::zeros(sizeConvMat.size(), CV_32F)};
cv::Mat mergeMat;
// 通道合并
merge(groupMats,2,mergeMat);
// DFT变换
dft(mergeMat, mergeMat);
// 分离通道
split(mergeMat, groupMats);
// 计算幅值
magnitude(groupMats[0], groupMats[1], groupMats[0]);
cv::Mat magnitudeMat = groupMats[0].clone();
// 归一化操作
magnitudeMat += Scalar::all(1);
log(magnitudeMat, magnitudeMat);
normalize(magnitudeMat, magnitudeMat, 0, 1, CV_MINMAX);
magnitudeMat.convertTo(magnitudeMat,CV_8UC1,255,0);
// 中心平移
int cx = magnitudeMat.cols/2;
int cy = magnitudeMat.rows/2;
Mat tmp;
// Top-Left - 为每一个象限创建ROI
Mat q0(magnitudeMat,Rect(0,0,cx,cy));
// Top-Right
Mat q1(magnitudeMat,Rect(cx,0,cx,cy));
// Bottom-Left
Mat q2(magnitudeMat,Rect(0,cy,cx,cy));
// Bottom-Right
Mat q3(magnitudeMat,Rect(cx,cy,cx,cy));
// 交换象限 (Top-Left with Bottom-Right)
q0.copyTo(tmp);
q3.copyTo(q0);
tmp.copyTo(q3);
// 交换象限 (Top-Right with Bottom-Left)
q1.copyTo(tmp);
q2.copyTo(q1);
tmp.copyTo(q2);
//cv::imshow("magnitudeMat2", magnitudeMat);
// 固定阈值二值化处理
cv::Mat binaryMagnMat;
threshold(magnitudeMat,binaryMagnMat,132,255,CV_THRESH_BINARY);
//cv::imshow("binaryMagnMat", binaryMagnMat);
// 霍夫变换
std::vector<Vec2f> lines;
binaryMagnMat.convertTo(binaryMagnMat,CV_8UC1,255,0);
HoughLines(binaryMagnMat, lines, 1, CV_PI/180, 100, 0, 0 );
float theta = 0;
// 检测线角度判断
for( size_t i = 0; i < lines.size(); i++ )
{
float thetaTemp = lines[i][1]*180/CV_PI;
if(thetaTemp > 0 && thetaTemp < 90)
{
theta = thetaTemp;
break;
}
}
// 角度转换
float angelT = nRows* tan(theta/180*CV_PI)/nCols;
theta = atan(angelT)*180/CV_PI;
std::cout << "theta:" << theta << std::endl;
// 取图像中心
cv::Point2f centerPoint = cv::Point2f(nCols/2, nRows/2);
double scale = 1;//不进行缩放
// 计算旋转矩阵
cv::Mat warpMat = getRotationMatrix2D(centerPoint, theta, scale);
// 仿射变换
cv::Mat resultImage(grayImg.size(), grayImg.type());
cv::warpAffine(grayImg, resultImage,
warpMat, resultImage.size());
//imshow("resultImage",resultImage);
cvtColor(resultImage, outputImage, CV_GRAY2BGR);
```