質問編集履歴
1
コードの再提示
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,6 +34,122 @@
|
|
34
34
|
|
35
35
|
```python
|
36
36
|
|
37
|
+
import cv2
|
38
|
+
|
39
|
+
import dlib
|
40
|
+
|
41
|
+
import numpy as np
|
42
|
+
|
43
|
+
import os
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
K = [977.93097999805309,0.00000000000000,645.97763974817144,0.00000000000000,979.76590271719897,358.70241515058876,0.00000000000000,0.00000000000000,1.00000000000000]
|
48
|
+
|
49
|
+
D = [-0.12590017568789,0.78177975429702,-0.00352001270650,0.00261067326856,-1.50761837519630]
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
cam_matrix = np.array(K).reshape(3, 3).astype(np.float32)
|
54
|
+
|
55
|
+
dist_coeffs = np.array(D).reshape(5, 1).astype(np.float32)
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
P3D_RIGHT_SIDE = np.float32([-100.0, -77.5, -5.0]) #0
|
60
|
+
|
61
|
+
P3D_GONION_RIGHT = np.float32([-110.0, -77.5, -85.0]) #4
|
62
|
+
|
63
|
+
P3D_MENTON = np.float32([0.0, 0.0, -122.7]) #8
|
64
|
+
|
65
|
+
P3D_GONION_LEFT = np.float32([-110.0, 77.5, -85.0]) #12
|
66
|
+
|
67
|
+
P3D_LEFT_SIDE = np.float32([-100.0, 77.5, -5.0]) #16
|
68
|
+
|
69
|
+
P3D_FRONTAL_BREADTH_RIGHT = np.float32([-20.0, -56.1, 10.0]) #17
|
70
|
+
|
71
|
+
P3D_FRONTAL_BREADTH_LEFT = np.float32([-20.0, 56.1, 10.0]) #26
|
72
|
+
|
73
|
+
P3D_SELLION = np.float32([0.0, 0.0, 0.0]) #27
|
74
|
+
|
75
|
+
P3D_NOSE = np.float32([21.1, 0.0, -48.0]) #30
|
76
|
+
|
77
|
+
P3D_SUB_NOSE = np.float32([5.0, 0.0, -52.0]) #33
|
78
|
+
|
79
|
+
P3D_RIGHT_EYE = np.float32([-20.0, -65.5,-5.0]) #36
|
80
|
+
|
81
|
+
P3D_RIGHT_TEAR = np.float32([-10.0, -40.5,-5.0]) #39
|
82
|
+
|
83
|
+
P3D_LEFT_TEAR = np.float32([-10.0, 40.5,-5.0]) #42
|
84
|
+
|
85
|
+
P3D_LEFT_EYE = np.float32([-20.0, 65.5,-5.0]) #45
|
86
|
+
|
87
|
+
#P3D_LIP_RIGHT = np.float32([-20.0, 65.5,-5.0]) #48
|
88
|
+
|
89
|
+
#P3D_LIP_LEFT = np.float32([-20.0, 65.5,-5.0]) #54
|
90
|
+
|
91
|
+
P3D_STOMION = np.float32([10.0, 0.0, -75.0]) #62
|
92
|
+
|
93
|
+
landmarks_3D = np.float32([P3D_RIGHT_SIDE,
|
94
|
+
|
95
|
+
P3D_GONION_RIGHT,
|
96
|
+
|
97
|
+
P3D_MENTON,
|
98
|
+
|
99
|
+
P3D_GONION_LEFT,
|
100
|
+
|
101
|
+
P3D_LEFT_SIDE,
|
102
|
+
|
103
|
+
P3D_FRONTAL_BREADTH_RIGHT,
|
104
|
+
|
105
|
+
P3D_FRONTAL_BREADTH_LEFT,
|
106
|
+
|
107
|
+
P3D_SELLION,
|
108
|
+
|
109
|
+
P3D_NOSE,
|
110
|
+
|
111
|
+
P3D_SUB_NOSE,
|
112
|
+
|
113
|
+
P3D_RIGHT_EYE,
|
114
|
+
|
115
|
+
P3D_RIGHT_TEAR,
|
116
|
+
|
117
|
+
P3D_LEFT_TEAR,
|
118
|
+
|
119
|
+
P3D_LEFT_EYE,
|
120
|
+
|
121
|
+
P3D_STOMION])
|
122
|
+
|
123
|
+
TRACKED_POINTS = (0, 4, 8, 12, 16, 17, 26, 27, 30, 33, 36, 39, 42, 45, 62)
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
def main():
|
128
|
+
|
129
|
+
cap = cv2.VideoCapture(0)
|
130
|
+
|
131
|
+
if not cap.isOpened():
|
132
|
+
|
133
|
+
print("Unable to connect to camera.")
|
134
|
+
|
135
|
+
return
|
136
|
+
|
137
|
+
#Declaring the two classifiers
|
138
|
+
|
139
|
+
dlib_landmarks_file = "./shape_predictor_68_face_landmarks.dat"
|
140
|
+
|
141
|
+
if(os.path.isfile(dlib_landmarks_file)==False):
|
142
|
+
|
143
|
+
print("The dlib landmarks file is missing! Use the following commands to download and unzip: ")
|
144
|
+
|
145
|
+
print(">> wget dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2")
|
146
|
+
|
147
|
+
print(">> bzip2 -d shape_predictor_68_face_landmarks.dat.bz2")
|
148
|
+
|
149
|
+
return
|
150
|
+
|
151
|
+
|
152
|
+
|
37
153
|
my_detector = face_landmark_detection.faceLandmarkDetection(dlib_landmarks_file)
|
38
154
|
|
39
155
|
my_face_detector = dlib.get_frontal_face_detector()
|