已知相机内参计算畸变矫正的像素点坐标

#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;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值