Skip to content

update this line  #8

Description

@2blackbar

Img = cv2.resize(Img, (512,512), interpolation = cv2.INTER_AREA)
This is how it should be, cause current code is limiting bigger images than 512 res from processing which is very weird, not all 512 res image are actual 512 res
updated func

def read_img_tensor(img_path=None, return_landmark=True): #rgb -1~1
Img = cv2.imread(img_path, cv2.IMREAD_UNCHANGED) # BGR or G
if Img.ndim == 2:
Img = cv2.cvtColor(Img, cv2.COLOR_GRAY2RGB) # GGG
else:
Img = cv2.cvtColor(Img, cv2.COLOR_BGR2RGB) # RGB

Img = cv2.resize(Img, (512,512), interpolation = cv2.INTER_AREA)

ImgForLands = Img.copy()
Img = Img.transpose((2, 0, 1))/255.0
Img = torch.from_numpy(Img).float()
normalize(Img, [0.5,0.5,0.5], [0.5,0.5,0.5], inplace=True)
ImgTensor = Img.unsqueeze(0)
SelectPred = None
if return_landmark:
    try:
        PredsAll = FaceDetection.get_landmarks(ImgForLands)
    except:
        print('Error in detecting this face {}. Continue...'.format(img_path))
    if PredsAll is None:
        print('Warning: No face is detected in {}. Continue...'.format(img_path))
        return ImgTensor, None
    ins = 0
    if len(PredsAll)!=1:
        hights = []
        for l in PredsAll:
            hights.append(l[8,1] - l[19,1])
        ins = hights.index(max(hights))
        print('Warning: Too many faces are detected, only handle the largest one...')
    SelectPred = PredsAll[ins]
return ImgTensor, SelectPred

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions