-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_points.py
110 lines (101 loc) · 5.5 KB
/
draw_points.py
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
import cv2
import numpy as np
colors = [[0.3856775, 0.94859286, 0.9910683],
[0.3856775, 0.94859286, 0.9910683],
[0.3856775, 0.94859286, 0.9910683],
[0.3856775, 0.94859286, 0.9910683],
[0.3856775, 0.94859286, 0.9910683],
[0.3856775, 0.94859286, 0.9910683],
[0.3856775, 0.94859286, 0.9910683],
[0.3856775, 0.94859286, 0.9910683],
[0.3856775, 0.94859286, 0.9910683], # 10
[0.3856775, 0.94859286, 0.9910683],
[0.3856775, 0.94859286, 0.9910683],
[0.3856775, 0.94859286, 0.9910683],
[0.3856775, 0.94859286, 0.9910683], # [0.93240442, 0.8993321, 0.09901344],
[0.3856775, 0.94859286, 0.9910683],
[0.3856775, 0.94859286, 0.9910683],
[0.3856775, 0.94859286, 0.9910683],
[0.3856775, 0.94859286, 0.9910683],
] # 17组点17个颜色
# colors = [[0.76590096, 0.0266074, 0.9806378],
# [0.54197179, 0.81682527, 0.95081629],
# [0.0799733, 0.79737015, 0.15173816],
# [0.93240442, 0.8993321, 0.09901344],
# [0.73130136, 0.05366301, 0.98405681],
# [0.01664966, 0.16387004, 0.94158259],
# [0.54197179, 0.81682527, 0.45081629],
# # [0.92074915, 0.09919099 ,0.97590748],
# [0.83445145, 0.97921679, 0.12250426],
# [0.7300924, 0.23253621, 0.29764521],
# [0.3856775, 0.94859286, 0.9910683], # 10
# [0.45762137, 0.03766411, 0.98755338],
# [0.99496697, 0.09113071, 0.83322314],
# [0.96478873, 0.0233309, 0.13149931],
# [0.33240442, 0.9993321 , 0.59901344],
# # [0.77690519,0.81783954,0.56220024],
# # [0.93240442, 0.8993321, 0.09901344],
# [0.95815068, 0.88436046, 0.55782268],
# [0.03728425, 0.0618827, 0.88641827],
# [0.05281129, 0.89572238, 0.08913828],
#
# ] # 17个颜色
def draw_landmarks_regress_test(pts0, ori_image_regress, ori_image_points):
for i, pt in enumerate(pts0):
# color = np.random.rand(3)
color = colors[i]
# print(i+1, color)
color_255 = (255 * color[0], 255 * color[1], 255 * color[2])
cv2.circle(ori_image_regress, (int(pt[0]), int(pt[1])), 6, color_255, -1, 1)
# cv2.circle(ori_image, (int(pt[2]), int(pt[3])), 5, color_255, -1,1)
# cv2.circle(ori_image, (int(pt[4]), int(pt[5])), 5, color_255, -1,1)
# cv2.circle(ori_image, (int(pt[6]), int(pt[7])), 5, color_255, -1,1)
# cv2.circle(ori_image, (int(pt[8]), int(pt[9])), 5, color_255, -1,1)
cv2.arrowedLine(ori_image_regress, (int(pt[0]), int(pt[1])), (int(pt[2]), int(pt[3])), color_255, 2, 1,
tipLength=0.2)
cv2.arrowedLine(ori_image_regress, (int(pt[0]), int(pt[1])), (int(pt[4]), int(pt[5])), color_255, 2, 1,
tipLength=0.2)
cv2.arrowedLine(ori_image_regress, (int(pt[0]), int(pt[1])), (int(pt[6]), int(pt[7])), color_255, 2, 1,
tipLength=0.2)
cv2.arrowedLine(ori_image_regress, (int(pt[0]), int(pt[1])), (int(pt[8]), int(pt[9])), color_255, 2, 1,
tipLength=0.2)
cv2.putText(ori_image_regress, '{}'.format(i + 1),
(int(pt[4] + 10), int(pt[5] + 10)),
cv2.FONT_HERSHEY_DUPLEX,
1.2,
color_255, # (255,255,255),
1,
1)
cv2.circle(ori_image_points, (int(pt[0]), int(pt[1])), 6, (255,255,255), -1,1)
cv2.circle(ori_image_points, (int(pt[2]), int(pt[3])), 5, color_255, -1, 1)
cv2.circle(ori_image_points, (int(pt[4]), int(pt[5])), 5, color_255, -1, 1)
cv2.circle(ori_image_points, (int(pt[6]), int(pt[7])), 5, color_255, -1, 1)
cv2.circle(ori_image_points, (int(pt[8]), int(pt[9])), 5, color_255, -1, 1)
return ori_image_regress, ori_image_points
def draw_landmarks_pre_proc(out_image, pts):
for i in range(17):
pts_4 = pts[4 * i:4 * i + 4, :]
color = colors[i]
color_255 = (255 * color[0], 255 * color[1], 255 * color[2])
cv2.circle(out_image, (int(pts_4[0, 0]), int(pts_4[0, 1])), 5, color_255, -1, 1)
cv2.circle(out_image, (int(pts_4[1, 0]), int(pts_4[1, 1])), 5, color_255, -1, 1)
cv2.circle(out_image, (int(pts_4[2, 0]), int(pts_4[2, 1])), 5, color_255, -1, 1)
cv2.circle(out_image, (int(pts_4[3, 0]), int(pts_4[3, 1])), 5, color_255, -1, 1)
return np.uint8(out_image)
def draw_regress_pre_proc(out_image, pts):
for i in range(17):
pts_4 = pts[4 * i:4 * i + 4, :]
pt = np.mean(pts_4, axis=0)
color = colors[i]
color_255 = (255 * color[0], 255 * color[1], 255 * color[2])
cv2.arrowedLine(out_image, (int(pt[0]), int(pt[1])), (int(pts_4[0, 0]), int(pts_4[0, 1])), color_255, 2, 1,
tipLength=0.2)
cv2.arrowedLine(out_image, (int(pt[0]), int(pt[1])), (int(pts_4[1, 0]), int(pts_4[1, 1])), color_255, 2, 1,
tipLength=0.2)
cv2.arrowedLine(out_image, (int(pt[0]), int(pt[1])), (int(pts_4[2, 0]), int(pts_4[2, 1])), color_255, 2, 1,
tipLength=0.2)
cv2.arrowedLine(out_image, (int(pt[0]), int(pt[1])), (int(pts_4[3, 0]), int(pts_4[3, 1])), color_255, 2, 1,
tipLength=0.2)
cv2.putText(out_image, '{}'.format(i + 1), (int(pts_4[1, 0] + 10), int(pts_4[1, 1] + 10)),
cv2.FONT_HERSHEY_DUPLEX, 1.2, color_255, 1, 1)
return np.uint8(out_image)