OpenCV如何将相机失真应用于图像 [英] OpenCV How to apply camera distortion to an image

查看:54
本文介绍了OpenCV如何将相机失真应用于图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个渲染的图像.我想对从opencv获得的图像应用径向和切向畸变系数.即使有不失真功能,也没有失真功能.如何使用失真系数使图像失真?

I have an rendered Image. I want to apply radial and tangential distortion coefficients to my image that I got from opencv. Even though there is undistort function, there is no distort function. How can I distort my images with distortion coefficients?

推荐答案

我也在寻找相同类型的功能.我找不到它,所以我自己实现了它.这是C ++代码.

I was also looking for the same type of functionality. I couldn't find it, so I implemented it myself. Here is the C++ code.

首先,您需要使用焦距和中心对图像点进行归一化

First, you need to normalize the image point using the focal length and centers

rpt(0) = (pt_x - cx) / fx
rpt(1) = (pt_y - cy) / fy

然后扭曲归一化的图像点

then distort the normalized image point

double x = rpt(0), y = rpt(1);

//determining the radial distortion
double r2 = x*x + y*y;
double icdist = 1 / (1 - ((D.at<double>(4) * r2 + D.at<double>(1))*r2 + D.at<double>(0))*r2);

//determining the tangential distortion
double deltaX = 2 * D.at<double>(2) * x*y + D.at<double>(3) * (r2 + 2 * x*x);
double deltaY = D.at<double>(2) * (r2 + 2 * y*y) + 2 * D.at<double>(3) * x*y;
x = (x + deltaX)*icdist;
y = (y + deltaY)*icdist;

然后您可以使用投影的中心和焦距来平移和缩放点:

then you can translate and scale the point using the center of projection and focal length:

x = x * fx + cx
y = y * fy + cy

这篇关于OpenCV如何将相机失真应用于图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆