(src_img,
                       facial_pts,
                       reference_pts = None,
                       crop_size=(96, 112),
                       align_type = 'smilarity')
return face_img
Function:
    ----------
        apply affine transform 'trans' to uv
    Parameters:
    ----------
        @src_img: 3x3 np.array
            input image
        @facial_pts: could be
            1)a list of K coordinates (x,y)
        or
            2) Kx2 or 2xK np.array
            each row or col is a pair of coordinates (x, y)
        @reference_pts: could be
            1) a list of K coordinates (x,y)
        or
            2) Kx2 or 2xK np.array
            each row or col is a pair of coordinates (x, y)
        or
            3) None
            if None, use default reference facial points
        @crop_size: (w, h)
            output face image size
        @align_type: transform type, could be one of
            1) 'similarity': use similarity transform
            2) 'cv2_affine': use the first 3 points to do affine transform,
                    by calling cv2.getAffineTransform()
            3) 'affine': use all points to do affine transform
    Returns:
    ----------
        @face_img: output face image with size (w, h) = @crop_size
Function:
    ----------
        apply affine transform 'trans' to uv
    Parameters:
    ----------
Function : ---------- apply affine transform trans to uv Parameters : ----------
def warp_and_crop_face(src_img,
                       facial_pts,
                       reference_pts = None,
                       crop_size=(96, 112),
                       align_type = 'smilarity'):
    """
    Function:
    ----------
        apply affine transform 'trans' to uv
    Parameters:
    ----------
        @src_img: 3x3 np.array
            input image
        @facial_pts: could be
            1)a list of K coordinates (x,y)
        or
            2) Kx2 or 2xK np.array
            each row or col is a pair of coordinates (x, y)
        @reference_pts: could be
            1) a list of K coordinates (x,y)
        or
            2) Kx2 or 2xK np.array
            each row or col is a pair of coordinates (x, y)
        or
            3) None
            if None, use default reference facial points
        @crop_size: (w, h)
            output face image size
        @align_type: transform type, could be one of
            1) 'similarity': use similarity transform
            2) 'cv2_affine': use the first 3 points to do affine transform,
                    by calling cv2.getAffineTransform()
            3) 'affine': use all points to do affine transform
    Returns:
    ----------
        @face_img: output face image with size (w, h) = @crop_size
    """

    if reference_pts is None:
        if crop_size[0] == 96 and crop_size[1] == 112:
            reference_pts = REFERENCE_FACIAL_POINTS
        else:
            default_square = False
            inner_padding_factor = 0
            outer_padding = (0, 0)
            output_size = crop_size

            reference_pts = get_reference_facial_points(output_size,
                                                        inner_padding_factor,
                                                        outer_padding,
                                                        default_square)

    ref_pts = np.float32(reference_pts)
    ref_pts_shp = ref_pts.shape
    if max(ref_pts_shp) < 3 or min(ref_pts_shp) != 2:
        raise FaceWarpException(
            'reference_pts.shape must be (K,2) or (2,K) and K>2')

    if ref_pts_shp[0] == 2:
        ref_pts = ref_pts.T

    src_pts = np.float32(facial_pts)
    src_pts_shp = src_pts.shape
    if max(src_pts_shp) < 3 or min(src_pts_shp) != 2:
        raise FaceWarpException(
            'facial_pts.shape must be (K,2) or (2,K) and K>2')

    if src_pts_shp[0] == 2:
        src_pts = src_pts.T

#    #print('--->src_pts:\n', src_pts
#    #print('--->ref_pts\n', ref_pts

    if src_pts.shape != ref_pts.shape:
        raise FaceWarpException(
            'facial_pts and reference_pts must have the same shape')

    if align_type is 'cv2_affine':
        tfm = cv2.getAffineTransform(src_pts[0:3], ref_pts[0:3])
#        #print(('cv2.getAffineTransform() returns tfm=\n' + str(tfm))
    elif align_type is 'affine':
        tfm = get_affine_transform_matrix(src_pts, ref_pts)
#        #print(('get_affine_transform_matrix() returns tfm=\n' + str(tfm))
    else:
        tfm = get_similarity_transform_for_cv2(src_pts, ref_pts)
#        #print(('get_similarity_transform_for_cv2() returns tfm=\n' + str(tfm))

#    #print('--->Transform matrix: '
#    #print(('type(tfm):' + str(type(tfm)))
#    #print(('tfm.dtype:' + str(tfm.dtype))
#    #print( tfm

    face_img = cv2.warpAffine(src_img, tfm, (crop_size[0], crop_size[1]))

    return face_img
def warp_and_crop_face ( src_img , facial_pts , reference_pts = None , crop_size = ( 96 , 112 ) , align_type = 'smilarity' ) : if reference_pts is None : if crop_size [ 0 ] == 96 and crop_size [ 1 ] == 112 : reference_pts = REFERENCE_FACIAL_POINTS else : default_square = False inner_padding_factor = 0 outer_padding = ( 0 , 0 ) output_size = crop_size reference_pts = get_reference_facial_points ( output_size , inner_padding_factor , outer_padding , default_square ) ref_pts = np . float32 ( reference_pts ) ref_pts_shp = ref_pts . shape if max ( ref_pts_shp ) < 3 or min ( ref_pts_shp ) != 2 : raise FaceWarpException ( 'reference_pts.shape must be (K,2) or (2,K) and K>2' ) if ref_pts_shp [ 0 ] == 2 : ref_pts = ref_pts . T src_pts = np . float32 ( facial_pts ) src_pts_shp = src_pts . shape if max ( src_pts_shp ) < 3 or min ( src_pts_shp ) != 2 : raise FaceWarpException ( 'facial_pts.shape must be (K,2) or (2,K) and K>2' ) if src_pts_shp [ 0 ] == 2 : src_pts = src_pts . T #    #print('--->src_pts:\n', src_pts #    #print('--->ref_pts\n', ref_pts if src_pts . shape != ref_pts . shape : raise FaceWarpException ( 'facial_pts and reference_pts must have the same shape' ) if align_type is 'cv2_affine' : tfm = cv2 . getAffineTransform ( src_pts [ 0 : 3 ] , ref_pts [ 0 : 3 ] ) #        #print(('cv2.getAffineTransform() returns tfm=\n' + str(tfm)) elif align_type is 'affine' : tfm = get_affine_transform_matrix ( src_pts , ref_pts ) #        #print(('get_affine_transform_matrix() returns tfm=\n' + str(tfm)) else : tfm = get_similarity_transform_for_cv2 ( src_pts , ref_pts ) #        #print(('get_similarity_transform_for_cv2() returns tfm=\n' + str(tfm)) #    #print('--->Transform matrix: ' #    #print(('type(tfm):' + str(type(tfm))) #    #print(('tfm.dtype:' + str(tfm.dtype)) #    #print( tfm face_img = cv2 . warpAffine ( src_img , tfm , ( crop_size [ 0 ] , crop_size [ 1 ] ) ) return face_img