Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confused about image saved and transformtransformed #4

Open
MoonBunnyZZZ opened this issue Sep 18, 2019 · 4 comments
Open

Confused about image saved and transformtransformed #4

MoonBunnyZZZ opened this issue Sep 18, 2019 · 4 comments

Comments

@MoonBunnyZZZ
Copy link

Hi, @StevenBanama
First in preprocessing/dataset_proc.py, you filter the more-than-one-face and no-crops images.In other words,the only-one-face images are reversed, Exactly, the image saved in pd.DataFrame are a lot of first align face,i.e. crops[0], while trible boxes.

Second in utils/image_transforn.py, every first align face is padded with (200, 200, 200, 200).

Here is the question. The trible box coordinates are uesd as slice on padded image.I think it is unreasonable.Because the coordinates base on origin input image.I also try some pictures from imdb-wiki dataset to prove what I say is right

@StevenBanama
Copy link
Owner

StevenBanama commented Sep 18, 2019

@MoonBunnyZZZ Problem (I): You can use only once detection with rotation. if you use alignment for face, meanwhile you should change the postion of landmarks. The second detection is just for get landmark without rotation, that is why i detect face twice.
Problem (II) : the 200 padding around image aims to keep origin scale of tri-box and add padding for the box out of bounds with less noise.

@MoonBunnyZZZ
Copy link
Author

@MoonBunnyZZZ Problem (I): You can use only once detection with rotation. if you use alignment for face, meanwhile you should change the postion of landmarks. The second detection is just for get landmark without rotation, that is why i detect face twice.
Problem (II) : the 200 padding around image aims to keep origin scale of tri-box and add padding for the box out of bounds with less noise.

@StevenBanama
Thank you for replay.Could you tell me where the second detection in code is ?I think it is missing the second detection that make me confused about data preprocess.

@StevenBanama
Copy link
Owner

cascad_imgs, padding = [], 200
#### step 1. add extra padding for aliagn image!!!!!!
new_bd_img = cv2.copyMakeBorder(img, padding, padding, padding, padding, cv2.BORDER_CONSTANT)   
#### offset for add for extra padding, so that keep same as before !!!!!!
    cascad_imgs.append(cv2.resize(new_bd_img[w_min+padding:w_max+padding, h_min+padding: h_max+padding,:], shape))   #### 

@StevenBanama
Copy link
Owner

StevenBanama commented Sep 19, 2019

@MoonBunnyZZZ Problem (I): You can use only once detection with rotation. if you use alignment for face, meanwhile you should change the postion of landmarks. The second detection is just for get landmark without rotation, that is why i detect face twice.
Problem (II) : the 200 padding around image aims to keep origin scale of tri-box and add padding for the box out of bounds with less noise.

@StevenBanama
Thank you for replay.Could you tell me where the second detection in code is ?I think it is missing the second detection that make me confused about data preprocess.

@MoonBunnyZZZ detection is wrapped by function named "gen_face"

def crop_and_trans_images(self, detector, series):
    # imdb 数据存在多张人脸,所以对于多人脸的数据直接清除掉
    image_path = os.path.join(self.data_dir, series.full_path[0])
    try:
        print(image_path)
        image = cv2.imread(image_path, cv2.IMREAD_COLOR)
        if not np.isnan(series.second_face_score):
            raise Exception("more than one face~---%s~-%s- %s"%(series.name, series.age, image_path))
        bounds, lmarks = gen_face(detector, image, image_path)     
        crops = detector.extract_image_chips(image, lmarks, padding=0.4)  # aligned face with padding 0.4 in papper
        if len(crops) == 0:
            raise Exception("no crops~~ %s---%s"%(image_path, series.age))
        if len(crops) > 1:
            raise Exception("more than one face~---%s~-- %s"%(series.name, image_path))
        bounds, lmarks = gen_face(detector, crops[0], image_path)  # recaculate landmar
        org_box, first_lmarks = bounds[0], lmarks[0]
        trible_box = gen_boundbox(org_box, first_lmarks)
        pitch, yaw, roll = get_rotation_angle(crops[0], first_lmarks) # gen face rotation for filtering
        image = crops[0]   # select the first align face and replace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants