Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matthew pr #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions util/align_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,21 +302,24 @@ def align(self, imgDim, rgbImg, bb=None, pad=None, ts=None,
dlib_rects = []
for (x,y,w,h) in faces:
dlib_rects.append(dlib.rectangle(int(x), int(y), int(x+w), int(y+h)))
if len(faces) > 0:
bb = max(dlib_rects, key=lambda rect: rect.width() * rect.height())
else:
bb = None
if len(faces) > 0:
bb = max(dlib_rects, key=lambda rect: rect.width() * rect.height())
else:
bb = None
else:
bb = self.getLargestFaceBoundingBox(rgbImg)
if bb is None:
return
if pad is not None:
left = int(max(0, bb.left() - bb.width()*float(pad[0])))
top = int(max(0, bb.top() - bb.height()*float(pad[1])))
right = int(min(rgbImg.shape[1], bb.right() + bb.width()*float(pad[2])))
bottom = int(min(rgbImg.shape[0], bb.bottom()+bb.height()*float(pad[3])))
right = int(min(rgbImg.shape[1]-1, bb.right() + bb.width()*float(pad[2])))
bottom = int(min(rgbImg.shape[0]-1, bb.bottom()+bb.height()*float(pad[3])))
bb = dlib.rectangle(left, top, right, bottom)

if only_crop:
return rgbImg[bb.top():bb.bottom(), bb.left():bb.right()]
# crop is rgbImg[y: y + h, x: x + w]
if landmarks is None:
landmarks = self.findLandmarks(rgbImg, bb)

Expand All @@ -328,11 +331,8 @@ def align(self, imgDim, rgbImg, bb=None, pad=None, ts=None,
# reserve more area of forehead on a face
dstLandmarks[(0,1),1] = dstLandmarks[(0,1),1] + imgDim * float(ts)
dstLandmarks[2,1] = dstLandmarks[2,1] + imgDim * float(ts) / 2
if not only_crop:
H = cv2.getAffineTransform(npLandmarks[npLandmarkIndices],dstLandmarks)
return cv2.warpAffine(rgbImg, H, (imgDim, imgDim))
else:
return rgbImg[top:bottom, left:right] # crop is rgbImg[y: y + h, x: x + w]
H = cv2.getAffineTransform(npLandmarks[npLandmarkIndices],dstLandmarks)
return cv2.warpAffine(rgbImg, H, (imgDim, imgDim))


def write(vals, fName):
Expand Down