'@brief: äždlib C++çæ¬å®ç°çè£åªå¯¹éœæ¹æ³äžèŽã
@attention'

def align_dlib_cpp(self, imgDim, rgbImg, bb=None):

    assert (imgDim is not None)
    assert (rgbImg is not None)
    if (bb is None):
        bb = self.getLargestFaceBoundingBox(rgbImg)
        if (bb is None):
            return
    landmarks = self.findLandmarks(rgbImg, bb)
    shape_x = [landmarks[i][0] for i in range(68)]
    shape_y = [landmarks[i][1] for i in range(68)]
    from_points = []
    to_points = []
    for i in range(17, 68):
        if ((i >= 55) and (i <= 59)):
            continue
        if ((i >= 17) and (i <= 26)):
            continue
        new_ref_x = ((self.padding + self.mean_shape_x[(i - 17)]) / ((2 * self.padding) + 1))
        new_ref_y = ((self.padding + self.mean_shape_y[(i - 17)]) / ((2 * self.padding) + 1))
        from_points.append((shape_x[i], shape_y[i]))
        to_points.append(((imgDim * new_ref_x), (imgDim * new_ref_y)))
    source = np.array(from_points).astype(np.int)
    target = np.array(to_points).astype(np.int)
    source = np.reshape(source, (1, 36, 2))
    target = np.reshape(target, (1, 36, 2))
    H = cv2.estimateRigidTransform(source, target, False)
    if (H is None):
        return
    else:
        aligned_face = cv2.warpAffine(rgbImg, H, (imgDim, imgDim))
        return aligned_face
