将鱼眼视频转换为普通视频

Convert Fisheye Video into regular Video

我有一个来自 180 度鱼眼相机的视频流。我想做一些图像处理,将鱼眼视图转换为普通视图。

经过一些研究和阅读大量文章后,我发现 this paper

他们描述了解决这个问题的算法(和一些公式)。

我曾尝试在 Matlab 中实现此方法。不幸的是它不起作用,我没能让它起作用。 "corrected" 图像看起来与原始照片完全一样,没有任何失真消除,其次我只接收图像的左上角,而不是完整图像,但将 'K' 的值更改为 1.9 给出mw 整个图像,但它完全相同的图像。

输入图像:

结果:

When the value of K is 1.15 as mentioned in the article

When the value of K is 1.9

这是我的代码:

image = imread('image2.png');
[Cx, Cy, channel] = size(image);

k = 1.5;
f = (Cx * Cy)/3;
opw = fix(f * tan(asin(sin(atan((Cx/2)/f)) * k)));
oph = fix(f * tan(asin(sin(atan((Cy/2)/f)) * k)));
image_new  = zeros(opw, oph,channel);

for i = 1: opw    
    for j = 1: oph        
        [theta,rho] = cart2pol(i,j);        
        R = f * tan(asin(sin(atan(rho/f)) * k));        
        r = f * tan(asin(sin(atan(R/f))/k));        
        X = ceil(r * cos(theta));        
        Y = ceil(r * sin(theta));

        for k = 1: 3            
            image_new(i,j,k) = image(X,Y,k);            
        end
    end
end

image_new = uint8(image_new);
warning('off', 'Images:initSize:adjustingMag');
imshow(image_new);

这就是解决了我的问题。

输入: 浮点强度 >= 0。0 = 无变化,高数字等于更强的修正。 缩放为浮点 >= 1。(1 = 缩放无变化)

算法:

set halfWidth = imageWidth / 2
set halfHeight = imageHeight / 2

if strength = 0 then strength = 0.00001
set correctionRadius = squareroot(imageWidth ^ 2 + imageHeight ^ 2) / strength

for each pixel (x,y) in destinationImage
    set newX = x - halfWidth
    set newY = y - halfHeight

    set distance = squareroot(newX ^ 2 + newY ^ 2)
    set r = distance / correctionRadius

    if r = 0 then
        set theta = 1
    else
        set theta = arctangent(r) / r

    set sourceX = halfWidth + theta * newX * zoom
    set sourceY = halfHeight + theta * newY * zoom

    set color of pixel (x, y) to color of source image pixel at (sourceX, sourceY)