-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangle_of_face.py
More file actions
executable file
·99 lines (67 loc) · 3.48 KB
/
Copy pathangle_of_face.py
File metadata and controls
executable file
·99 lines (67 loc) · 3.48 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
import cv2
import numpy as np
import os, sys
import argparse
ABS_PATh = os.path.dirname(os.path.abspath(__file__)) + "/"
import argparse
#2D image points. If you change the image, you need to change vector
image_points = np.array([
(359, 391), # Nose tip
(399, 561), # Chin
(337, 297), # Left eye left corner
(513, 301), # Right eye right corne
(345, 465), # Left Mouth corner
(453, 469) # Right mouth corner
], dtype="double")
# 3D model points.
model_points = np.array([
(0.0, 0.0, 0.0), # Nose tip
(0.0, -330.0, -65.0), # Chin
(-225.0, 170.0, -135.0), # Left eye left corner
(225.0, 170.0, -135.0), # Right eye right corne
(-150.0, -150.0, -125.0), # Left Mouth corner
(150.0, -150.0, -125.0) # Right mouth corner
])
parser = argparse.ArgumentParser(description='a crop utility')
parser.add_argument('--dir_to_process', type=str, nargs='?',
help='dir_to_process')
FLAGS = parser.parse_args()
if FLAGS.dir_to_process == "":
paths = [] #specify static here
else:
paths = [FLAGS.dir_to_process+"/" ]
def resize( path ):
items = os.listdir( path )
for item in items:
# print(item)
if item == '.DS_Store':
continue
if os.path.isfile(path+item):
size = item.shape
print("HelloHereHowAreYou",size)
# # Camera internals
# focal_length = size[1]
# center = (size[1]/2, size[0]/2)
# camera_matrix = np.array(
# [[focal_length, 0, center[0]],
# [0, focal_length, center[1]],
# [0, 0, 1]], dtype = "double"
# )
# # print "Camera Matrix :\n {0}".format(camera_matrix)
# dist_coeffs = np.zeros((4,1)) # Assuming no lens distortion
# (success, rotation_vector, translation_vector) = cv2.solvePnP(model_points, image_points, camera_matrix, dist_coeffs)
# # print "Rotation Vector:\n {0}".format(rotation_vector)
# # print "Translation Vector:\n {0}".format(translation_vector)
# # Project a 3D point (0, 0, 1000.0) onto the image plane.
# # We use this to draw a line sticking out of the nose
# (nose_end_point2D, jacobian) = cv2.projectPoints(np.array([(0.0, 0.0, 1000.0)]), rotation_vector, translation_vector, camera_matrix, dist_coeffs)
# for p in image_points:
# cv2.circle(item, (int(p[0]), int(p[1])), 3, (0,0,255), -1)
# p1 = ( int(image_points[0][0]), int(image_points[0][1]))
# p2 = ( int(nose_end_point2D[0][0][0]), int(nose_end_point2D[0][0][1]))
# cv2.line(item, p1, p2, (255,0,0), 2)
# # Display image
# cv2.imshow("Output", item)
# cv2.waitKey(0)
for path in paths:
resize( path )