• 大小: 0.03M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-05-09
  • 语言: Python
  • 标签: opencv  计算机  视觉  pe  

资源简介

哈哈哈哈镜子代码

资源截图

代码片段和文件信息

#哈哈镜的原理:输入图像f(xy) 设置图像中心坐标Center(cx xy)为缩放中心点。
#图像上任意一点到中心点的相对坐标tx= x-cxty=y-cy.哈哈镜效果分为图像拉伸放大和图像缩小。
#对于图像拉伸放大,设置图像变换的半径为radius哈哈镜变换后的图像为p(xy).
# x = (tx/2)*(sqrt(tx*tx + ty*ty)/radius)+cx
# y = (ty/2)*(sqrt(tx*tx + ty*ty)/radius)+cy
#对于图像缩小,设置图像变换的半径为radius哈哈镜变换后的图像为p(xy).
# x = cos(atan2(ty  tx))* 12*(sqrt(tx*tx + ty*ty))+cx
# y = sin(atan2(ty  tx))* 12*(sqrt(tx*tx + ty*ty))+cy

# -*- coding: UTF-8 -*-
import cv2
import numpy as np
import math

def Maxframe(frame):                 #定义图像拉伸放大函数
    height width n = frame.shape    #获取输入图像的长宽和通道
    center_X = width / 2              #计算公式
    center_Y = height / 2
    radius = 400                     #这里直接定义半径了
    newX = 0                         #初始变换后的坐标
    newY = 0
    real_radius =int(radius / 2.0)   #计算公式
    new_data = frame.copy()         #复制一个与原图像一样的图片

    for i in range(width):                #建立循环移动像素遍历宽度方向的像素
        for j in range(height):               #遍历高度方向的像素
            tX = i - center_X                  #计算公式
            tY = j - center_Y

            distance = tX * tX + tY * tY
            if distance < radius * radius:    #变换点的距离是否太远

                newX = int(tX/ 2.0)
                newY = int(tY/ 2.0)

                newX = int(newX * (math.sqrt(distance) / real_radius))
                newX = int(newX * (math.sqrt(distance)/ real_radius))

                newX = int(newX + center_X)
                newY = int(newY + center_Y)
                if newX                    new_data[j i][0] = frame[newY newX][0]        #将计算后的坐标移动到原坐标
                    new_data[j i][1] = frame[newY newX][1]
                    new_data[j i][2] = frame[newY newX][2]

            else:                                          #若变换点距离太远,图像像素不变动
                new_data[j i][0] = frame[j i][0]
                new_data[j i][1] = frame[j i][1]
                new_data[j i][2] = frame[j i][2]

    return new_data

def Minframe(frame):                  #定义图像缩小函数
    height width n = frame.shape
    center_X = width / 2
    center_Y = height / 2
    radius = 400
    newX = 0
    newY = 0
    real_radius =int(radius / 2.0)
    new_data = frame.copy()

    for i in range(width):
        for j in range(height):
            tX = i - center_X
            tY = j - center_Y
            theta = math.atan2(tY tX)
            radius = math.sqrt((tX * tX) + (tY * tY))             #与上面一样,计算公式不一样

            newR = math.sqrt(radius) *12
            newX = int(center_X + (newR * math.cos(theta)))
            newY = int(center_Y + (newR * math.sin(theta)))

            if newX < 0 and  newX >width:
                newX = 0

            if newY <0 and newY >height:
                newY = 0

            if newX                new_data[j i][0] = frame[newY newX][0]
                new_data[j i][1] = frame[newY newX][1]
  

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        4336  2020-10-08 06:22  01鍝堝搱闀滃師鐞嗗強浠g爜.py
     文件         788  2020-10-08 06:22  __MACOSX\._01鍝堝搱闀滃師鐞嗗強浠g爜.py
     文件       25928  2020-10-08 06:24  1.jpg
     文件         387  2020-10-08 06:24  __MACOSX\._1.jpg

评论

共有 条评论