Converting a fisheye image into a panoramic, spherical or perspective projection

本文介绍了一种将鱼眼图像转换为全景、球形或透视投影的方法。通过不同的软件工具,如fish2persp、frontfish2pano等,可以实现鱼眼图像到不同投影类型的变换,包括标准透视、全景及球形投影。这些工具支持调整输出图像尺寸、视场角等参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Converting a fisheye image into a panoramic, spherical or perspective projection

Written by Paul Bourke
November 2004

The source code implementing the projections below is only availableon request for a small fee. It includes a demo application and an invitation toconvert an image of your choice to verify the code does what you seek. For more information please contact the author.


The following documents various transformations from fisheye into other projectiontypes, specifically standard perspective as per a pinhole camera, panorama andspherical projections.Fisheye images capture a wide field of view, traditionally one thinks of 180degrees but the mathematical definition extends past that and indeed there aremany physical fisheye lenses that extend past 180 degrees. The two main applicationsfor the following are: the inspection of images/video from security cameras wherepanorama or perspective views may be more natural to view, creating panorama orspherical images that are blended together to form even wider field of view images.

The general options for the software include the dimensions of the output image as wellas the aperture of the output panoramic or perspective frustum. Some otherrequirements arise from imperfect fisheye capture such as the fisheye notbeing centered on the input image, the fisheye not be aligned with theintended axis, and the fisheye being of any angle.Another characteristic of real fisheye images is their lack of linearitywith radius on the image, while this is not addressed here as it requiresa lens calibration, it is a straightforward correction to make.

The usual approach for such image transformations is to perform the inverse mapping. Thatis, one needs to consider each pixel in the output image and map backwards tofind the closest pixel in the input image (fisheye). In this way every pixelin the output image is found (compared to a forward mapping), it also meansthat the performance is governed by the resolution of the output image(and supersampling) irrespective of the size of the input image.A key aspect of these mappings is also to perform some sort of antialiasing, thesolutions here use a simple supersampling approach.

The code here are all plain vanilla C tested on Unix style gcc systems (specifically Mac and Linux),but the algorithms/code can readily be modified for otheroperating systems and programming languages.This is not meant to be a final application but rather something you integrate into your code base. Having said that it is wrapped up in a simple TGA image reader/writer for the purposes of algorithm testing, the intent is that one would be implementing the function into ones own code base. They all operate on a RGB buffer (fisheye image) in memory.For each test utility the usage message is provided. The source images for the examplesprovided are provided along with the command line that generated them.



Fisheye to perspective transformation
Software:
fish2persp

Usage: fish2persp [options] fisheyeimage
Options
   -w n     perspective image width, default = 800
   -h n     perspective image height, default = 600
   -t n     aperture of perspective (degrees), default = 100
            maximum is 170 degrees
   -s n     aperture of fisheye (degrees), default = 180
   -c x y   offset of the center of the fisheye image,
            default is fisheye image center
   -r n     fisheye radius, default is half height of fisheye image
   -x n     tilt angle (degrees), default: 0
   -y n     roll angle (degrees), default: 0
   -z n     pan angle (degrees), default: 0
   -a n     antialiasing level, default = 1 (no antialising)
            sensible maximum 3

It should be noted at the outset that a fisheye projection is not a "distorted" image, and the process isn’t a “dewarping”. A fisheye like other projections is one of many ways of mapping a 3D world onto a 2D plane, it is no more or less "distorted" than other projections including a rectangular perspective projection ... it is what it is.

Example source fisheye image.

A critical consideration is antialiasing, required when sampling any discrete signal. The approach here is a simple supersampling antialiasing, that is,each pixel in the output image is subdivided into a 2x2, 3x3....grid andthe inverse mapping applied to the subsamples. The final value for the outputpixel is the weighted average of the inverse mapped subsamples.There is a sense in which the image plane is considered to be a continuousfunction. Since the number of samples that are inverse mapped is the principle determinant ofperformance, high levels of antialiasing can be very expensive, typically2x2 or 3x3 are sufficient especially for images captured from video in whichneighbouring pixels are not independent in the first place.For example a 3x3 antialiasing is 9 times slower than no antialiasing.In general the jagged edges are more noticeable in featureswith a sharp colour/intensity boundary.

Default perspective view looking forwards, 100 degrees horizontal field of view.


fish2persp -w 800 -a 3

The vertical aperture is automatically adjusted to match the width and height.Controls are provided for any angle fisheye as well as fisheyes that are notlevel or tilted, noting that the exact order of the correction rotations mayneed to be considered for particular cases.Note that a perspective projection is not defined for greater than 180 degrees,indeed it gets increasingly inefficient past around 140 degrees.The field of view can be adjusted as well as the viewing direction.The following example is a 120 degrees horizontal field of view and looking upwards by 30 degrees.


fish2persp -w 800 -a 3 -x 30 -t 120

If "straight" lines are not straight that normally means the fisheye center or radius are not specified correctly or the angle is not defined correctly.Curvature in what should be straight lines near the rim of the fisheye normally meansthe fisheye lens has non-linearities near the rim (a deviation from the mathematically purefisheye projection) and corrections need to be applied.The following is looking right by 40 degrees and a narrower field of view of 80 degrees.


fish2persp -w 800 -a 3 -z 40 -t 80

The center of the fisheye on the input image can be found by projectinglines along vertical structure in the scene. Where these lines intersectis a close approximation to the center of the fisheye, assuming thecamera is mounted vertically. Alternatively, and perhaps easier, is to identify the edges of thefisheye and assume a perfect circular inscribed circle. Note that for the example utilities providedhere the origin is assumed to be the bottom left corner, unlike the more common top right thatimage editing programs use.

To test the algorithm a fisheye rendering inside a gridded cube is a good example,see image on left below. Any correct perspective projection should result in straight lines.


Sample input image

 

 

 




Front pointing fisheye to panorama
Software:
frontfish2pano

This case is developed mainly for "front pointing" fisheyes although it does have applicationfor other orientations. The projection is more correctly called a cylindrical panorama.

Usage: frontfish2pano [options] fisheyeimage
Options
   -w n     panoramic image width, default = 800
   -h n     panoramic image height, default = -1
  -ap n     vertical aperture of panoramic, default = 100
  -af n     aperture of fisheye (degrees), default = 180
  -cf x y   center of the fisheye image, default is image center
   -r n     radius of the fisheye image, default is half the image width
  -fa n     angle for tilted fisheye, default = 0
  -fb n     angle for rotated fisheye, default = 0
   -a n     antialiasing level, default = 1 (no antialising)

Source fisheye image.

Transformation with the default settings is shown below.


frontfish2pano -a 3 -w 800

Correct for the fact that the camera is not quite horizontal, this is thereason the vertical structure doesn't appear vertical in the panoramic projection.Of course nothing is for free, one looses a bit of the image in the bottomleft and right corners.


frontfish2pano -a 3 -w 800 -fa -20

Set the vertical field of view of the panorama, in the following cases narrowed fromthe default of 100 degrees to 80 degrees. As with perspective projections there is a limit, in this case, to the vertical field of view, a hard limit at 180 degrees but increasingly inefficientpast 140 degrees.


frontfish2pano -a 3 -w 800 -fa -20 -ap 80



Fisheye to (partial) spherical projection
Software:
fish2sphere

Usage: fish2sphere [options] imagefile
Options
   -w n     sets the output image size, default: 4 fisheye image width
   -a n     sets antialiasing level, default: 2
  -fa n     fisheye aperture (degrees), default: 180
   -c x y   fisheye center, default: center of image
   -r n     fisheye radius, default: half the fisheye image width
   -v n     rotate fisheye in latitude, default: 0
   -z n     roll fisheye, default: 0
   -d       debug mode

Source fisheye image.

Transformation using the default settings. Since a 180 degree (in this case) fisheyecaptures half the visible universe from a single position, so it makes sense that it occupieshalf of a spherical (equirectangular) projection, which captures the entire visibleuniverse from a single position.

In this case the camera is not perfectly horizontal, this and other adjustmentscan be made. In the example here the lens was pointing downwards slightly, thecorrection results in more of the south pole being visible and less of the northpole.

Note that the fisheye angle is not limited to 180 degrees, indeed one applicationfor this is in the pipeline to create 360 spherical panoramas from 2 cameras, eachwith a fisheye lens with a field of view greater than 180 to provide a blend zone.

This can be readily implemented in the OpenGL Shader Language, the followingexample was created in theQuartz Composer Core Image Filter.


// Fisheye to spherical conversion
// Assumes the fisheye image is square, centered, and the circle fills the image.
// Output (spherical) image should have 2:1 aspect.
// Strange (but helpful) that atan() == atan2(), normally they are different.

kernel vec4 fish2sphere(sampler src)
{
	vec2 pfish;
	float theta,phi,r;
	vec3 psph;
	
	float FOV = 3.141592654; // FOV of the fisheye, eg: 180 degrees
	float width = samplerSize(src).x;
	float height = samplerSize(src).y;

	// Polar angles
	theta = 2.0 * 3.14159265 * (destCoord().x / width - 0.5); // -pi to pi
	phi = 3.14159265 * (destCoord().y / height - 0.5);	// -pi/2 to pi/2

	// Vector in 3D space
	psph.x = cos(phi) * sin(theta);
	psph.y = cos(phi) * cos(theta);
	psph.z = sin(phi);
	
	// Calculate fisheye angle and radius
	theta = atan(psph.z,psph.x);
	phi = atan(sqrt(psph.x*psph.x+psph.z*psph.z),psph.y);
	r = width * phi / FOV; 

	// Pixel in fisheye space
	pfish.x = 0.5 * width + r * cos(theta);
	pfish.y = 0.5 * width + r * sin(theta);
	
	return sample(src, pfish);
}



The transformation can be performed in realtime using warp mesh files forsoftware such aswarpplayer or the VLC equivalentVLCwarp. A sample mesh file is givenhere:fish2sph.data. Showing the result in actionis below.

Test cases for various fisheye apertures.
180 degree fisheye
120 degree fisheye
220 degree fisheye
220 degree fisheye and 90 degree latitude rotation
220 degree fisheye and 60 degree latitude rotation



Fisheye to (full) panorama
Software:
fish2pano

The following is a slightly more general version of conversion to a panoramic projection.It supports both spherical and cylindrical projections, handles different fisheyeorientations but the main difference is it is designed to image into a full 360 projection obviously withparts not covered because of the limited field of view of a fisheye compared to a fullspherical projection.

Usage: fish2pano [options] fisheyeimage
Options
   -w n     panoramic image width, default = 1024
   -h n     panoramic image height, default = derived
  -af n     aperture of fisheye (degrees), default = 180
  -cf x y   center of the fisheye image, default is image center
   -x n     tilt fisheye about x (right) axis, default = 0
   -z n     rotate fisheye about lens axis, default = 0
   -r n     radius of the fisheye image, default is half the image width
   -a n     antialiasing level, default = 1 (no antialising)
   -c       cylindrical pano, default is spherical
   -v n     vertical aperture for cylindrical pano, default: 60

Example 1: Source fisheye image.

Black refers to the corners of the fisheye image and the grey to the unavailable data,that is, data outside the fisheye rectangle in which the circular fisheye is inscribed.Note that for a wider than 180 degree fisheye the black and grey regions will be correspondingly smaller. The "x" axis is to the right, the 90 degree rotation heregives the desired result for a forward pointing fisheye. A fisheye pointing straightup or straight down would more normally be transformed with "-x 0".


fish2pano -a 3 -w 800 -x 90

Cylindrical projection, vertical field 60 degrees and 100 degrees respectively.The vertical extent of the image is, normally, determined correctly given the vertical field of view requested but that can be overruled if desired.


fish2pano -a 3 -w 800 -x 90 -c

fish2pano -a 3 -w 800 -x 90 -c -v 100

Example 2: Source fisheye image

The default settings (no x axis rotation) provide what one expects for an upper hemisphereas per a standard Earth map. Note the apparent distortion towards the north pole, which againis not a strictly distortion but a natural consequence of the mathematics behind the projection.


fish2pano -a 3 -w 800

Cylindrical panorama with a 100 degree vertical field of view, that is, from the equator (0 degreeslatitude) to 100 degrees latitude.


fish2pano -a 3 -w 800 -c -v 100
数据集介绍:鱼眼图像目标检测数据集 一、基础信息 数据集名称:鱼眼图像目标检测数据集 图片数量: - 训练集:1,554张鱼眼镜头图像 - 验证集:135张鱼眼镜头图像 分类类别: - 单一目标类别(标签编号0):适用于工业检测场景的通用目标类别 标注格式: - YOLO格式标注文件,包含目标中心坐标及边界框尺寸 - 原始图像包含真实场景背景,增强模型泛化能力 数据特性: - 鱼眼镜头畸变校正图像 - 工业场景采集数据 - 多角度环境光照条件 二、适用场景 工业检测系统开发: 支持开发基于鱼眼镜头的自动化检测系统,适用于管道、密闭空间等特殊场景的缺陷识别 安防监控AI应用: 训练适应鱼眼监控摄像头的目标检测模型,提升全景监控场景下的目标识别准确率 自动驾驶环境感知: 优化车载鱼眼摄像头在泊车辅助、盲区监测等场景的物体检测能力 图像畸变校正研究: 提供原生鱼眼图像数据,支持镜头畸变校正算法的开发与验证 三、数据集优势 独特数据特性: - 专为鱼眼镜头场景优化,包含典型桶形畸变特征 - 覆盖多种工业环境背景,模拟真实检测场景 高效标注体系: - 标准化YOLO格式标注 - 统一目标类别标注规范,适用于快速模型训练 工业应用适配性: - 数据来源于真实工业检测场景 - 支持嵌入式设备部署的轻量化模型训练 - 兼容YOLOv5/v8等主流目标检测框架 科研价值突出: - 稀缺的鱼眼镜头专项数据集 - 支持计算机视觉在特殊成像场景下的算法研究
### 使用 `dd` 命令进行文件复制并带转换和格式化选项 `dd` 是一种强大的命令行工具,主要用于低级别的数据处理任务,例如文件复制、磁盘镜像创建以及数据转换等。通过其丰富的参数组合,可以实现复杂的文件操作需求。 #### 参数详解 以下是与文件复制及转换相关的常用参数: - **if=FILE**: 指定输入文件路径。如果未指定,则默认从标准输入读取。 - **of=FILE**: 指定输出文件路径。如果没有定义,默认会将结果发送到标准输出。 - **conv=CONVERSIONS**: 应用一组转换标志来修改数据流行为。常见的转换标志包括: - **ascii**: 转换 EBCDIC 到 ASCII 编码[^1]。 - **ebcdic**: 转换 ASCII 到 EBCDIC 编码。 - **ibm**: 转换 ASCII 到另一种 IBM 版本的 EBCDIC 编码。 - **lcase**: 将所有大写字母转为小写形式[^1]。 - **ucase**: 将所有小写字母转为大写形式[^1]。 - **swab**: 交换每一对字节位置。 - **noerror**: 遇到读取错误时忽略而不终止程序运行[^1]。 - **notrunc**: 不截断输出文件内容,仅追加新数据[^1]。 - **sync**: 如果输入块小于指定大小则填充零以补齐差异[^1]。 - **bs=BYTESIZE**: 同时设定了 ibs 和 obs 的数值,即统一规定了输入输出块大小,通常建议采用此方法简化配置流程[^1]。 #### 实际案例分析 假设存在这样一个实际应用场景:我们需要把一个名为 `source.txt` 的纯文本文档转化为全大写的版本,并将其保存至另一个叫做 `uppercase_output.txt` 的新文件当中去。那么我们可以这样编写对应的 shell script: ```bash dd if=source.txt of=uppercase_output.txt conv=ucase ``` 这条语句的作用就是打开原始文件 `source.txt` 并逐块读取其中的内容,与此同时执行大小写转换操作最后再把这些经过加工后的字符序列依次写回到目标文件 `uppercase_output.txt` 中完成整个工作流程[^1]。 另外还有一种稍微复杂一点的情况涉及到跨编码系统的互译过程比如说要把一份日志记录从原本使用的 Shift-JIS 字符集转变为 UTF-8 形式以便后续更广泛的支持兼容性考虑此时就可以借助如下所示的方式达成目的: ```bash iconv -f SHIFT_JIS -t UTF-8 input.log | dd of=output_utf8.log conv=sync,notrunc ``` 这里先调用了外部工具 iconv 来负责具体的编码映射事务接着管道传递给后面的 dd 步骤做最终落地存储安排同时加入了 sync 和 notrunc 两个额外属性确保即使原素材里含有不完整区块也能妥善处置不会丢失任何有效信息而且保留既有结构不变动只单纯增加新的条目而已。 --- ###
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值