首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >鱼眼镜头效果

鱼眼镜头效果

作者头像
裴来凡
发布2022-05-29 09:57:48
发布2022-05-29 09:57:48
4600
举报
代码语言:javascript
复制
import cv2
import numpy as np 
import math
def transform1(img):
    rows,cols,c=img.shape
    R=np.int(cols/2/math.pi)
    D=R*2
    cx=R
    cy=R
    print(rows,cols,c,R,D,cx,cy)
    new_img=np.zeros((D,D,c),dtype=np.uint8) 
    new_img1=np.zeros((D,D,c),dtype=np.uint8)
    for i in range(D):
        for j in range(D):
            r=math.sqrt((i-cx)**2+(j-cy)**2)
            if r>R:
                continue
            tan_inv=np.arctan((j-cy)/(i-cx+1e-10))
            if(i<cx):
                theta=math.pi/2+tan_inv
            else:
                theta=math.pi*3/2+tan_inv  
            xp=np.int(np.floor(theta/2/math.pi*cols))
            yp=np.int(np.floor(r/R*rows))
            new_img[j,i]=img[rows-yp-1,xp]
    return new_img
def transform2(img):
    rows,cols,c=img.shape
    R=np.int(cols/2/math.pi)
    D=R*2
    cx=R
    cy=R
    print(rows,cols,c,R,D,cx,cy)
    new_img=np.zeros((D,D,c),dtype=np.uint8) 
    new_img1=np.zeros((D,D,c),dtype=np.uint8)
    for i in range(D):
        for j in range(D):
            r=math.sqrt((i-cx)**2+(j-cy)**2)
            if r>R:
                continue
            tan_inv=np.arctan((j-cy)/(i-cx+1e-10))
            if(i<cx):
                theta=math.pi/2+tan_inv
            else:
                theta=math.pi*3/2+tan_inv  
            xp=np.int(np.floor(theta/2/math.pi*cols))
            yp=np.int(np.floor(r/R*rows)-1)
            new_img[j,i]=img[yp,xp]
    return new_img
img=cv2.imread('C:/Users/xpp/Desktop/Lena.png')
img1=transform1(img)
img2=transform2(img)
cv2.imshow('C:/Users/xpp/Desktop/result1',img1)
cv2.imshow('C:/Users/xpp/Desktop/result2',img2)
cv2.waitKey(0)
cv2.imwrite('C:/Users/xpp/Desktop/result1.jpg',img1)
cv2.imwrite('C:/Users/xpp/Desktop/result2.jpg',img2)

460 460 3 73 146 73 73 460 460 3 73 146 73 73

算法:鱼眼镜头效果是视觉效果类似于鱼在水中观察水面上的事物。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-12-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 图像处理与模式识别研究所 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档