-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBezier.py
More file actions
114 lines (84 loc) · 3.05 KB
/
Copy pathBezier.py
File metadata and controls
114 lines (84 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import math
import cv2
import numpy as np
img = np.zeros((1080,1920,3), dtype=np.int16)
def DrawBezier(pts, nPoints):
for x in range(nPoints):
t = (1.0 * x) /(nPoints * 1.0);
k_1_minus_t = 1.0 - t
k0 = k_1_minus_t * k_1_minus_t * k_1_minus_t
k1 = 3 * k_1_minus_t * k_1_minus_t * t;
k2 = 3 * k_1_minus_t * t * t;
k3 = t * t * t;
point = k0 * pts[0] + k1 * pts[1] + k2 * pts[2] + k3 * pts[3]
#pt = point
xx = (int)(point[0]+0.500001)
yy = (int)(point[1]+0.500001)
img[yy,xx,0] = 0
img[yy,xx,1] = 0
img[yy,xx,2] = 0
def AntiAlias(pts, nPoints):
for x in range(nPoints):
t = (1.0 * x) /(nPoints * 1.0);
k_1_minus_t = 1.0 - t
k0 = k_1_minus_t * k_1_minus_t * k_1_minus_t
k1 = 3 * k_1_minus_t * k_1_minus_t * t;
k2 = 3 * k_1_minus_t * t * t;
k3 = t * t * t;
point = k0 * pts[0] + k1 * pts[1] + k2 * pts[2] + k3 * pts[3]
pt = point
xx1 = int(point[0])
yy1 = int(point[1])
if 1: #2x2 anti alias
for ii in range(2):
for jj in range(2):
xx = xx1 + ii
yy = yy1 + jj
distance = (xx - point[0]) * (xx - point[0]) + (yy - point[1]) * (yy - point[1])
distance = math.sqrt(distance)
#Blender with original Color
img[yy,xx,0] = min(255,int(255 * distance)) * img[yy,xx,0] / 255
img[yy,xx,1] = min(255,int(255 * distance)) * img[yy,xx,0] / 255
img[yy,xx,2] = min(255,int(255 * distance)) * img[yy,xx,0] / 255
#img[yy,xx,0] = min(min(255,int(255 * distance)) , img[yy,xx,0])
#img[yy,xx,1] = min(min(255,int(255 * distance)) , img[yy,xx,0])
#img[yy,xx,2] = min(min(255,int(255 * distance)) , img[yy,xx,0])
if 0:
xx = (int)(point[0]+0.500001)
yy = (int)(point[1]+0.500001)
img[yy,xx,0] = 0
img[yy,xx,1] = 0
img[yy,xx,2] = 0
for y in range(1080):
for x in range(1920):
img[y,x,0]= 255
img[y,x,1]= 255
img[y,x,2]= 255
# B(t) = (1-t)^3*P0 + 3(1-t)^2*t*P1 + 3 (1-t)*t^2 * P3 + t^3 * P3
#4 Control Points
# [200, 50], [200, 650] , [800, 650], [800,50]
# 800 * 3.14 ~= 2500 Points, 2500 Points may have leaded Points
#control_points
pts = np.zeros((4,2), dtype=np.int16)
pts[0,0] = 200
pts[0,1] = 50
pts[1,0] = 200
pts[1,1] = 850
pts[2,0] = 1600
pts[2,1] = 850
pts[3,0] = 1600
pts[3,1] = 50
DrawBezier(pts, 2500)
#Increasing Points to 3000
pts[0,1] = pts[0,1] + 200
pts[1,1] = pts[1,1] + 200
pts[2,1] = pts[2,1] + 200
pts[3,1] = pts[3,1] + 200
DrawBezier(pts, 5000)
pts[0,1] = pts[0,1] + 200
pts[1,1] = pts[1,1] + 200
pts[2,1] = pts[2,1] + 200
pts[3,1] = pts[3,1] + 200
AntiAlias(pts, 2500)
cv2.imwrite('bezier.jpg', img)
cv2.imshow('image',img)