Skip to content

Commit 4d2fb5f

Browse files
authored
Add files via upload
1 parent 1f09c48 commit 4d2fb5f

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#coding:utf-8
2+
#By:Eastmount CSDN 2020-12-22
3+
#该效果有点丑,读者可以设置透明度进一步优化,可能效果会好看些。
4+
import cv2
5+
import math
6+
import numpy as np
7+
8+
#读取原始图像
9+
img = cv2.imread('nv.png')
10+
11+
#获取图像行和列
12+
rows, cols = img.shape[:2]
13+
14+
#新建目标图像
15+
dst = np.zeros((rows, cols, 3), dtype="uint8")
16+
17+
#定义水波特效参数
18+
wavelength = 20
19+
amplitude = 30
20+
phase = math.pi / 4
21+
22+
#获取中心点
23+
centreX = 0.5
24+
centreY = 0.5
25+
radius = min(rows, cols) / 2
26+
27+
#设置水波覆盖面积
28+
icentreX = cols*centreX
29+
icentreY = rows*centreY
30+
31+
#图像水波特效
32+
for i in range(rows):
33+
for j in range(cols):
34+
dx = j - icentreX
35+
dy = i - icentreY
36+
distance = dx*dx + dy*dy
37+
38+
if distance>radius*radius:
39+
x = j
40+
y = i
41+
else:
42+
#计算水波区域
43+
distance = math.sqrt(distance)
44+
45+
amount = amplitude * math.sin(distance / wavelength * 2*math.pi - phase)
46+
amount = amount * (radius-distance) / radius
47+
amount = amount * wavelength / (distance+0.0001)
48+
x = j + dx * amount
49+
y = i + dy * amount
50+
51+
#边界判断
52+
if x<0:
53+
x = 0
54+
if x>=cols-1:
55+
x = cols - 2
56+
if y<0:
57+
y = 0
58+
if y>=rows-1:
59+
y = rows - 2
60+
61+
p = x - int(x)
62+
q = y - int(y)
63+
64+
#图像水波赋值
65+
dst[i, j, :] = (1-p)*(1-q)*img[int(y),int(x),:] + p*(1-q)*img[int(y),int(x),:]
66+
+ (1-p)*q*img[int(y),int(x),:] + p*q*img[int(y),int(x),:]
67+
68+
#显示图像
69+
cv2.imshow('src', img)
70+
cv2.imshow('dst', dst)
71+
72+
cv2.waitKey()
73+
cv2.destroyAllWindows()
74+

0 commit comments

Comments
 (0)