【个人】项目实训 | 鱼眼效果


一、鱼眼效果核心代码

import cv2 as cv
import math
import numpy as np

def qingxin_fun(instance):
    src_img = instance.m_image
    row = src_img.shape[0]
    col = src_img.shape[1]
    channel = src_img.shape[2]
    new_img = np.zeros([row, col, channel], dtype=np.uint8)
    center_x = row / 2
    center_y = col / 2
    # radius=math.sqrt(center_x*center_x+center_y*center_y)/2
    radius = min(center_x, center_y)
    for i in range(row):
        for j in range(col):

            distance = ((i - center_x) * (i - center_x) + (j - center_y) * (j - center_y))
            new_dist = math.sqrt(distance)
            new_img[i, j, :] = src_img[i, j, :]
            if distance <= radius ** 2:
                new_i = np.int(np.floor(new_dist * (i - center_x) / radius + center_x))
                new_j = np.int(np.floor(new_dist * (j - center_y) / radius + center_y))
                new_img[i, j, :] = src_img[new_i, new_j, :]

    instance.m_image = new_img
    instance.updata_image()

二、UI界面

    # 创建一个action,当该action被触发时显示鱼眼特效处理后的图片
    action_qingxin_show = QAction('&鱼眼效果', instance)
    action_qingxin_show.triggered.connect(instance.qingxin_effect_emit)

    # 艺术风格迁移选项新增一个action:鱼眼滤镜
    tempMenu.addAction(action_qingxin_show)
    def qingxin_effect_emit(self):
        qingxin_effect.qingxin_fun(self)

三、效果

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值