OpenGL中的相机镜头变形 [英] Camera lens distortion in OpenGL

查看:375
本文介绍了OpenGL中的相机镜头变形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的SLAM项目模拟镜头失真效果. 已提供扫描的彩色3D点云并将其加载到OpenGL中. 我想做的是在给定的姿势下渲染2D场景,并在鱼眼镜头的真实图像和渲染的图像之间进行一些视觉测距. 由于相机的镜头畸变严重,因此在渲染阶段也应予以考虑.

I'm trying to simulate lens distortion effect for my SLAM project. A scanned color 3D point cloud is already given and loaded in OpenGL. What I'm trying to do is render 2D scene at a given pose and do some visual odometry between the real image from a fisheye camera and the rendered image. As the camera has severe lens distortion, it should be considered in the rendering stage too.

问题是我不知道该在哪里放置镜头畸变.着色器?

The problem is that I have no idea where to put the lens distortion. Shaders?

我发现了一些开放代码,这些畸变使几何着色器变形.但是我想这个畸变模型不同于Computer Vision社区中的镜头畸变模型.在CV社区中,镜头畸变通常发生在投影平面上.

I've found some open codes that put the distortion in the geometry shader. But this one I guess the distortion model is different from the lens distortion model in Computer Vision community. In CV community, lens distortion usually occurs on the projected plane.

这一个与我的作品非常相似,但是他们没有使用失真模型.

This one is quite similar to my work but they didn't used distortion model.

有人有个好主意吗?

我刚刚发现

I just found another implementation. Their code implemented the distortion in both of fragment shader and geometry shader. But fragment shader version can be applied in my situation. Thus, I guess the following will work:

# vertex shader
p'=T.model x T.view x p
p_f = FisheyeProjection(p') // custom fish eye projection

推荐答案

镜头变形通常会将直线变成曲线.使用OpenGL栅格化线和三角形时,无论如何变换顶点,图元的边缘都保持笔直.

Lens distortion usually turns straight lines into curves. When rasterizing lines and triangles using OpenGL, the primitives' edges however stay straight, no matter how you transform the vertices.

如果您的模型具有足够精细的镶嵌,则将变形合并到顶点变换中是可行的.如果只渲染点,它也可以使用.

If your models have fine enough tesselation, then incorporating the distortion into the vertex transformation is viable. It also works if you're rendering only points.

但是,当您的目标是一般适用时,您必须以某种方式处理直边的基元.一种方法是使用几何着色器进一步细分传入的模型.或者您可以使用镶嵌着色器.

However when your aim is general applicability you have to somehow deal with the straight edged primitives. One way is by using a geometry shader to further subdivide incoming models; or you can use a tesselation shader.

另一种方法是渲染到立方体贴图中,然后使用着色器为其创建等效的镜头.实际上,我建议您使用它来生成鱼眼图像.

Another method is rendering into a cubemap and then use a shader to create a lens equivalent for that. I'd actually recommend that for generating fisheye images.

畸变本身通常由3到5的多项式表示,将从光学中心轴到畸变角距离的未畸变角距离映射.

The distortion itself is usually represented by a polynomial of order 3 to 5, mapping undistorted angular distance from the optical center axis to the distorted angular distance.

这篇关于OpenGL中的相机镜头变形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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