(face, landmark)
return (face_, landmark_flip)
flip a face and its landmark
flip a face and its landmark
flip a face and its landmark
def flip(face, landmark):
    '''
    flip a face and its landmark
    '''
    face_ = cv2.flip(face, 1) # 1 means flip horizontal
    landmark_flip = np.asarray(np.zeros(landmark.shape))
    for i, point in enumerate(landmark):
        landmark_flip[i] = (1-point[0], point[1])
    # for 5-point flip
        landmark_flip[[0,1]] = landmark_flip[[1,0]]
    landmark_flip[[3,4]] = landmark_flip[[4,3]]
    # for 19-point flip
        #landmark_flip[[0,9]] = landmark_flip[[9,0]]
    #landmark_flip[[1,8]] = landmark_flip[[8,1]]
    #landmark_flip[[2,7]] = landmark_flip[[7,2]]
    #landmark_flip[[3,6]] = landmark_flip[[6,3]]
    #landmark_flip[[4,11]] = landmark_flip[[11,4]]
    #landmark_flip[[5,10]] = landmark_flip[[10,5]]
    #landmark_flip[[12,14]] = landmark_flip[[14,12]]
    #landmark_flip[[15,17]] = landmark_flip[[17,15]]
    return (face_, landmark_flip)
def flip ( face , landmark ) : face_ = cv2 . flip ( face , 1 ) # 1 means flip horizontal landmark_flip = np . asarray ( np . zeros ( landmark . shape ) ) for i , point in enumerate ( landmark ) : landmark_flip [ i ] = ( 1 - point [ 0 ] , point [ 1 ] ) # for 5-point flip landmark_flip [ [ 0 , 1 ] ] = landmark_flip [ [ 1 , 0 ] ] landmark_flip [ [ 3 , 4 ] ] = landmark_flip [ [ 4 , 3 ] ] # for 19-point flip #landmark_flip[[0,9]] = landmark_flip[[9,0]] #landmark_flip[[1,8]] = landmark_flip[[8,1]] #landmark_flip[[2,7]] = landmark_flip[[7,2]] #landmark_flip[[3,6]] = landmark_flip[[6,3]] #landmark_flip[[4,11]] = landmark_flip[[11,4]] #landmark_flip[[5,10]] = landmark_flip[[10,5]] #landmark_flip[[12,14]] = landmark_flip[[14,12]] #landmark_flip[[15,17]] = landmark_flip[[17,15]] return ( face_ , landmark_flip )