#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
using namespace cv;
using namespace std;
int main() {
double fx = 2881.14449010057;
double fy = 2.881638851956911e+03;
double cx = 1824.70227334361;
double cy = 1354.12045513096;
double k1 = 0.0581431802285456;
double k2 = -0.482743008085280;
double k3 = 1.42969637056893;
double p1 = 0.000577638969267163;
double p2 = -0.000758381099812397;
Point2f point = { 2067,902 };//像素坐标
Point2f image;//有畸变的图像坐标
image.x = (point.x - cx) / fx;
image.y = (point.y - cy) / fy;
cout << image.x << endl;
cout << image.y << endl;
// 输入的特征点坐标
vector<Point2f> distortedPoints = { { 2067,902 } ,{773,613} };
// 畸变校正后的特征点坐标
vector<Point2f> undistortedPoints;
// 构建相机矩阵
Mat cameraMatrix = (Mat_<double>(3, 3) << fx, 0, cx, 0, fy, cy, 0, 0, 1);
// 填写畸变系数
Mat distortionCoefficients = Mat::zeros(1, 5, CV_64F);// 根据实际情况填写畸变系数
distortionCoefficients.at<double>(0) = k1;
distortionCoefficients.at<double>(1) = k2;
distortionCoefficients.at<double>(2) = p1;
distortionCoefficients.at<double>(3) = p2;
distortionCoefficients.at<double>(4) = k3;
// 进行畸变校正
undistortPoints(distortedPoints, undistortedPoints, cameraMatrix, distortionCoefficients);
// 打印校正后的特征点坐标
for (const Point2f& point : undistortedPoints) {
cout << "Undistorted point: (" << point.x << ", " << point.y << ")" << endl;
}
Point2f undistortedpix;
undistortedpix.x=undistortedPoints[1].x*fx + cx;
undistortedpix.y = undistortedPoints[1].y*fy + cy;
cout << "Undistorted pixpoint: (" << undistortedpix.x << ", " << undistortedpix.y << ")" << endl;
}
已知相机内参计算畸变矫正的像素点坐标
最新推荐文章于 2024-07-20 22:56:53 发布