Skip to content

Commit

Permalink
headcrop now based on width of the head
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterwolfert committed May 25, 2018
1 parent 9d99b40 commit fa4c191
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
10 changes: 6 additions & 4 deletions script/headdetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
gazemachine = Gaze(model_def, model_weights)
faceCascade=cv2.CascadeClassifier('/home/pieter/projects/engagement-l2tor/data/haarcascade_frontalface_alt.xml')
print(faceCascade.empty())
video = cv2.VideoCapture(0)
video = cv2.VideoCapture('/home/pieter/projects/engagement-l2tor/data/403059_les2_fragment1.mp4')
while True:
# Capture frame-by-frame
#time.sleep(1)
Expand All @@ -21,17 +21,19 @@
# Draw a rectangle around the faces
x_face = 0
y_face = 0
alpha = 0
for (x, y, w, h) in faces:
x_face = int((x + (x+w))/2)
y_face = int((y+ (y+h))/2)
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
alpha = w / x_frame
#cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
# Display the resulting frame
e = [x_face/x_frame, y_face/y_frame,]
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
if e[0] != 0.0 and e[1] != 0.0:
predictions = gazemachine.getGaze(image, e)
predictions = gazemachine.getGaze(image, e, alpha)
cv2.imshow('Eyeframe', gazemachine.getEyeImage())
#cv2.circle(frame, (predictions[0], predictions[1]), 10, (0, 255,0), 2)
cv2.circle(frame, (predictions[0], predictions[1]), 10, (0, 255,0), 2)
cv2.line(frame, (x_face, y_face), (predictions[0], predictions[1]), (0, 255, 0), 2)
print(predictions)
cv2.imshow('Video', frame)
Expand Down
11 changes: 7 additions & 4 deletions script/predict_gaze.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def getHeatmap(self):
"""Get heatmap to see where the gaze is predicted."""
return self.heatmap

def getGaze(self, image, headloc):
def getGaze(self, image, headloc, alpha=0.3):
"""Returns x,y coordinates of the gaze location
Keyword Arguments:
Expand All @@ -34,7 +34,7 @@ def getGaze(self, image, headloc):
self.head_x = int(headloc[0] * np.shape(self.image)[1])
self.head_y = int(headloc[1] * np.shape(self.image)[0])
self.img_resize, self.eye_image_resize, self.z =\
self.prepImages(self.image, self.headloc)
self.prepImages(self.image, self.headloc, alpha)
self.network_outputs = self.predictGaze()
self.heatmap, self.predictions =\
self.postProcessing(self.network_outputs)
Expand All @@ -60,7 +60,7 @@ def visualizeGaze(self):
ax.add_patch(Circle((self.head_x, self.head_y), 10, color = 'r'))
plt.show()

def prepImages(self, img, e):
def prepImages(self, img, e, alpha):
"""
Output images of prepImages are exactly the same as the matlab ones
Expand All @@ -69,7 +69,6 @@ def prepImages(self, img, e):
e -- head location (relative) [x, y]
"""
input_shape = [227, 227]
alpha = 0.3
img_resize = None

wy = int(alpha * img.shape[0])
Expand All @@ -80,6 +79,10 @@ def prepImages(self, img, e):
x1 = int(center[0]-.5*wx) - 1
x2 = int(center[0]+.5*wx) - 1
#make crop of face from image
if y1 < 0:
y1 = 0
if x1 < 0:
x1 = 0
im_face = img[y1:y2, x1:x2, :]

#subtract mean from images
Expand Down

0 comments on commit fa4c191

Please sign in to comment.