fast-yolo4/fast/ImageCalibrator.cpp

49 lines
1.5 KiB
C++
Raw Permalink Normal View History

2024-09-29 13:58:12 +08:00
#include "stdafx.h"
#include "ImageCalibrator.h"
#include <opencv2\opencv.hpp>
using namespace std;
CImageCalibrator::CImageCalibrator()
{
}
CImageCalibrator::~CImageCalibrator()
{
}
cv::Mat CImageCalibrator::imageCalibration(cv::Mat inImg)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD>ڲξ<DAB2><CEBE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD>ڰ<EFBFBD><DAB0><EFBFBD><EFBFBD≯<EFBFBD><CCB8><EFBFBD><EAB6A8><EFBFBD><EFBFBD>õ<EFBFBD>
cv::Mat cameraMatrix = (cv::Mat_ <double>(3, 3) << 720.689879, 0, 957.57171, 0, 721.705519, 935.484724, 0, 0, 1),
distCoeffs = (cv::Mat_ <double>(1, 4) << -0.0765657862, 0.0190079504, -0.032948619, 0.0159874152); //<2F><>ͶӰ<CDB6><D3B0><EFBFBD><EFBFBD>rms<6D><73>0.601462
//ƽ<>Ʋ<EFBFBD><C6B2><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>λ<EFBFBD><CEBB>ƫ<EFBFBD><EFBFBD><EEA3AC><EFBFBD>ղⶨ<D5B2><E2B6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>ͼƬ
cv::Mat warp_matrix = (cv::Mat_<float>(2, 3) <<
cos(0), -sin(0), -63, //x<><78>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sin(0), cos(0), -68); //y<><79>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cv::warpAffine(inImg, inImg, warp_matrix, inImg.size(), cv::INTER_LINEAR);
//ȡ<><C8A1>Ч<EFBFBD><D0A7><EFBFBD>۾<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>
cv::Mat inImg2(inImg, cv::Rect(324, 0, 1944, 1944));
//<2F><><EFBFBD>ۻ<EFBFBD><DBBB><EFBFBD>չƽ
cv::Mat outImg, new_intrinsic_mat;
cameraMatrix.copyTo(new_intrinsic_mat);
//<2F><><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD>С<EFBFBD><D0A1><EFBFBD>˵<EFBFBD>ϵ<EFBFBD><CFB5>ԽС<D4BD>ӳ<EFBFBD>Խ<EFBFBD>󣬿ɵ<F3A3ACBF><C9B5><EFBFBD>
new_intrinsic_mat.at<double>(0, 0) *= 0.7;
new_intrinsic_mat.at<double>(1, 1) *= 0.7;
//<2F><><EFBFBD><EFBFBD>У<EFBFBD><D0A3>ͼ<EFBFBD><CDBC><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>
new_intrinsic_mat.at<double>(0, 2) = 0.5 * inImg2.cols;
new_intrinsic_mat.at<double>(1, 2) = 0.5 * inImg2.rows;
cv::fisheye::undistortImage(inImg2, outImg, cameraMatrix, distCoeffs, new_intrinsic_mat);
//չƽ<D5B9><C6BD><EFBFBD>۳<EFBFBD><DBB3><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//Mat roi(outImg, cv::Rect(711, 465, 557, 941));
//<2F><>ʾչƽ<D5B9><C6BD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
//cv::imshow("<22>궨Ч<EAB6A8><D0A7>", outImg); cv::waitKey(0);
return outImg;
}