teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

コードの再提示

2019/07/04 03:54

投稿

masayuki.west
masayuki.west

スコア13

title CHANGED
File without changes
body CHANGED
@@ -16,6 +16,64 @@
16
16
  ### 該当のソースコード
17
17
 
18
18
  ```python
19
+ import cv2
20
+ import dlib
21
+ import numpy as np
22
+ import os
23
+
24
+ K = [977.93097999805309,0.00000000000000,645.97763974817144,0.00000000000000,979.76590271719897,358.70241515058876,0.00000000000000,0.00000000000000,1.00000000000000]
25
+ D = [-0.12590017568789,0.78177975429702,-0.00352001270650,0.00261067326856,-1.50761837519630]
26
+
27
+ cam_matrix = np.array(K).reshape(3, 3).astype(np.float32)
28
+ dist_coeffs = np.array(D).reshape(5, 1).astype(np.float32)
29
+
30
+ P3D_RIGHT_SIDE = np.float32([-100.0, -77.5, -5.0]) #0
31
+ P3D_GONION_RIGHT = np.float32([-110.0, -77.5, -85.0]) #4
32
+ P3D_MENTON = np.float32([0.0, 0.0, -122.7]) #8
33
+ P3D_GONION_LEFT = np.float32([-110.0, 77.5, -85.0]) #12
34
+ P3D_LEFT_SIDE = np.float32([-100.0, 77.5, -5.0]) #16
35
+ P3D_FRONTAL_BREADTH_RIGHT = np.float32([-20.0, -56.1, 10.0]) #17
36
+ P3D_FRONTAL_BREADTH_LEFT = np.float32([-20.0, 56.1, 10.0]) #26
37
+ P3D_SELLION = np.float32([0.0, 0.0, 0.0]) #27
38
+ P3D_NOSE = np.float32([21.1, 0.0, -48.0]) #30
39
+ P3D_SUB_NOSE = np.float32([5.0, 0.0, -52.0]) #33
40
+ P3D_RIGHT_EYE = np.float32([-20.0, -65.5,-5.0]) #36
41
+ P3D_RIGHT_TEAR = np.float32([-10.0, -40.5,-5.0]) #39
42
+ P3D_LEFT_TEAR = np.float32([-10.0, 40.5,-5.0]) #42
43
+ P3D_LEFT_EYE = np.float32([-20.0, 65.5,-5.0]) #45
44
+ #P3D_LIP_RIGHT = np.float32([-20.0, 65.5,-5.0]) #48
45
+ #P3D_LIP_LEFT = np.float32([-20.0, 65.5,-5.0]) #54
46
+ P3D_STOMION = np.float32([10.0, 0.0, -75.0]) #62
47
+ landmarks_3D = np.float32([P3D_RIGHT_SIDE,
48
+ P3D_GONION_RIGHT,
49
+ P3D_MENTON,
50
+ P3D_GONION_LEFT,
51
+ P3D_LEFT_SIDE,
52
+ P3D_FRONTAL_BREADTH_RIGHT,
53
+ P3D_FRONTAL_BREADTH_LEFT,
54
+ P3D_SELLION,
55
+ P3D_NOSE,
56
+ P3D_SUB_NOSE,
57
+ P3D_RIGHT_EYE,
58
+ P3D_RIGHT_TEAR,
59
+ P3D_LEFT_TEAR,
60
+ P3D_LEFT_EYE,
61
+ P3D_STOMION])
62
+ TRACKED_POINTS = (0, 4, 8, 12, 16, 17, 26, 27, 30, 33, 36, 39, 42, 45, 62)
63
+
64
+ def main():
65
+ cap = cv2.VideoCapture(0)
66
+ if not cap.isOpened():
67
+ print("Unable to connect to camera.")
68
+ return
69
+ #Declaring the two classifiers
70
+ dlib_landmarks_file = "./shape_predictor_68_face_landmarks.dat"
71
+ if(os.path.isfile(dlib_landmarks_file)==False):
72
+ print("The dlib landmarks file is missing! Use the following commands to download and unzip: ")
73
+ print(">> wget dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2")
74
+ print(">> bzip2 -d shape_predictor_68_face_landmarks.dat.bz2")
75
+ return
76
+
19
77
  my_detector = face_landmark_detection.faceLandmarkDetection(dlib_landmarks_file)
20
78
  my_face_detector = dlib.get_frontal_face_detector()
21
79