def getFaceKeypoints(img, detector, predictor, maxImgSizeForDetection=640):
imgScale = 1
scaledImg = img
if max(img.shape) > maxImgSizeForDetection:
imgScale = maxImgSizeForDetection / float(max(img.shape))
scaledImg = cv2.resize(img, (int(img.shape[1] * imgScale), int(img.shape[0] * imgScale)))
#detekcja twarzy
dets = detector(scaledImg, 1)
if len(dets) == 0:
return None
shapes2D = []
for det in dets:
faceRectangle = rectangle(int(det.left() / imgScale), int(det.top() / imgScale), int(det.right() / imgScale), int(det.bottom() / imgScale))
#detekcja punktow charakterystycznych twarzy
dlibShape = predictor(img, faceRectangle)
shape2D = np.array([[p.x, p.y] for p in dlibShape.parts()])
#transpozycja, zeby ksztalt byl 2 x n a nie n x 2, pozniej ulatwia to obliczenia
shape2D = shape2D.T
shapes2D.append(shape2D)
return shapes2D
评论列表
文章目录