AirSim中针孔相机畸变的实现

查阅AirSim的文档可知,AirSim支持通过simSetDistortionParams设置K1, K2, K3, P1, P2这5个畸变系数。UE镜头畸变模拟:OpenCV Lens Distortion一文提及过,Unreal的OpenCV Lens Distortion插件是通过生成的Post Process Material对UV坐标施加偏移来模拟镜头畸变。那么,AirSim又是如何处理的呢? 基本流程探究 打开任意集成了AirSim插件的Unreal工程,用Visual Studio翻阅工程源码,重点是AirSim插件的cpp代码。 在整个项目中搜索simSetDistortionParams,找到RPC客户端和服务端的实现。客户端: // <path-to-project>\Plugins\AirSim\Source\AirLib\src\api\RpcLibClientBase.cpp void RpcLibClientBase::simSetDistortionParam(const std::string& camera_name, const std::string& param_name, float value, const std::string& vehicle_name, bool external) { pimpl_->client.call("simSetDistortionParam", camera_name, param_name, value, vehicle_name, external); } 服务端: // <path-to-project>\Plugins\AirSim\Source\AirLib\src\api\RpcLibServerBase.cpp // 省略其余binding... pimpl_->server.bind("simSetDistortionParam", [&](const std::string& camera_name, const std::string& param_name, float value, const std::string& vehicle_name, bool external) -> void { getWorldSimApi()->setDistortionParam(param_name, value, CameraDetails(camera_name, vehicle_name, external)); }); // ... 顺藤摸瓜,找到WorldSimApi::setDistortionParam:...

2023-05-04 · Qiao

UE镜头畸变模拟:OpenCV Lens Distortion

出于仿真的需要,希望在Unreal中能模拟鱼眼镜头的畸变效果,看到UE官方提供了Lens Distortion和OpenCV Lens Distortion两款插件用于模拟镜头畸变,但可惜相关资料不多。UE的博文UE中的相机标定、畸变模拟与矫正 - Unreal Engine做了些介绍,但步骤却又不是很详尽,初学者如我使用时不免多绕了些路,遂写下此文。 插件介绍 这里结合UE中的相机标定、畸变模拟与矫正 - Unreal Engine的介绍,总结如下: Lens Distortion和OpenCV Lens Distortion用的camera model是一样的,背后的原理也类似。都是根据相机畸变参数生成displacement map,以此模拟镜头畸变 Lens Distortion没有标定功能,且只包含了畸变系数的前几项 Lens Distortion通过shader生成displacement map,而OpenCV Lens Distortion通过OpenCV的API用CPU计算生成,前者效率更快。不过由于displacement map通常只生成一次,这里的效率差异不太重要 补充:什么是displacement map? A displacement map is a type of texture that is used in 3D computer graphics to create the illusion of depth and detail on a surface without actually changing the geometry of the mesh. A displacement map is typically a grayscale image where the brightness values of each pixel correspond to the amount of displacement that should be applied to the surface at that point....

2023-04-28 · Qiao