顔向き推定
dlibを用いて顔を認識することは出来るのですが、
そこから顔向き(Pitch,Yaw,Roll)に変換することができないです。
githubから顔向きについてのプログラムを実践したのですが、数値があてにならない状態です。
下記のプログラムのどこがまずいのでしょうか?
どなた教えていただけないでしょうか?
該当のソースコード
Python
1K = [6.5308391993466671e+002, 0.0, 3.1950000000000000e+002, 2 0.0, 6.5308391993466671e+002, 2.3950000000000000e+002, 3 0.0, 0.0, 1.0] 4D = [7.0834633684407095e-002, 6.9140193737175351e-002, 0.0, 0.0, -1.3073460323689292e+000] 5 6 7cam_matrix = np.array(K).reshape(3, 3).astype(np.float32) 8dist_coeffs = np.array(D).reshape(5, 1).astype(np.float32) 9 10object_pts = np.float32([[6.825897, 6.760612, 4.402142], 11 [1.330353, 7.122144, 6.903745], 12 [-1.330353, 7.122144, 6.903745], 13 [-6.825897, 6.760612, 4.402142], 14 [5.311432, 5.485328, 3.987654], 15 [1.789930, 5.393625, 4.413414], 16 [-1.789930, 5.393625, 4.413414], 17 [-5.311432, 5.485328, 3.987654], 18 [2.005628, 1.409845, 6.165652], 19 [-2.005628, 1.409845, 6.165652], 20 [2.774015, -2.080775, 5.048531], 21 [-2.774015, -2.080775, 5.048531], 22 [0.000000, -3.116408, 6.097667], 23 [0.000000, -7.415691, 4.070434]]) 24 25reprojectsrc = np.float32([[10.0, 10.0, 10.0], 26 [10.0, 10.0, -10.0], 27 [10.0, -10.0, -10.0], 28 [10.0, -10.0, 10.0], 29 [-10.0, 10.0, 10.0], 30 [-10.0, 10.0, -10.0], 31 [-10.0, -10.0, -10.0], 32 [-10.0, -10.0, 10.0]]) 33 34line_pairs = [[0, 1], [1, 2], [2, 3], [3, 0], 35 [4, 5], [5, 6], [6, 7], [7, 4], 36 [0, 4], [1, 5], [2, 6], [3, 7]] 37 38 39def get_head_pose(shape): 40 # 2D image points. If you change the image, you need to change vector 41 42 43 image_pts = np.float32([shape[17], shape[21], shape[22], shape[26], shape[36], 44 shape[39], shape[42], shape[45], shape[31], shape[35], 45 shape[48], shape[54], shape[57], shape[8]]) 46 47 _, rotation_vec, translation_vec = cv2.solvePnP(object_pts, image_pts, cam_matrix, dist_coeffs) 48 49 reprojectdst, _ = cv2.projectPoints(reprojectsrc, rotation_vec, translation_vec, cam_matrix, 50 dist_coeffs) 51 52 reprojectdst = tuple(map(tuple, reprojectdst.reshape(8, 2))) 53 54 # calc euler angle 55 rotation_mat, _ = cv2.Rodrigues(rotation_vec) 56 pose_mat = cv2.hconcat((rotation_mat, translation_vec)) 57 _, _, _, _, _, _, euler_angle = cv2.decomposeProjectionMatrix(pose_mat) 58 59 return reprojectdst, euler_angle 60 61
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/22 09:03
2018/09/22 09:11
2018/09/22 12:55