Skip to content

Hand over face (High Resolution Masks) #10

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

Closed
test1230-lab opened this issue Sep 18, 2020 · 11 comments
Closed

Hand over face (High Resolution Masks) #10

test1230-lab opened this issue Sep 18, 2020 · 11 comments

Comments

@test1230-lab
Copy link

Are there any higher res masks avalible?

@aurooj
Copy link
Owner

aurooj commented Sep 24, 2020

Hi! Sorry for the late reply. It's crazy times. I will need to generate higher res masks for HOF, but it is definitely possible.

@test1230-lab
Copy link
Author

Would this be done using xml annotations? If so I already made them and I could send them if you like.

@aurooj
Copy link
Owner

aurooj commented Sep 26, 2020 via email

@zenoli
Copy link

zenoli commented Feb 23, 2021

Hi,
Are the high-res masks already online? I could not find them.

@test1230-lab
Copy link
Author

out.zip
here, manually clean iirc

@zenoli
Copy link

zenoli commented Feb 24, 2021

@test1230-lab Thank you very much!

@test1230-lab
Copy link
Author

test1230-lab commented Feb 24, 2021 via email

@zenoli
Copy link

zenoli commented Feb 25, 2021

@test1230-lab
So the images you sent me are created using the polygon data from the XML right? I noticed two things:

  1. There are two hand masks missing (298 files in 'out.zip' vs 300 in 'images_orig_size').
  2. The indices in 'out.zip' do not lign up with the indices in 'imgages_orig_size'.

While these are both minor inconveniences (I can fix issue 2 manually without too much effort), I was wondering what the root of these two issues is? Do you have the script that created 'out.zip' available? Would you be willing to share it?

And I guess you don't have a "manually cleaned" version of the images?

@test1230-lab
Copy link
Author

test1230-lab commented Feb 25, 2021

i think this is the one.

`import xmltodict
import glob
import os
from PIL import Image
from PIL import Image, ImageDraw
import argparse
from tqdm import tqdm


parser = argparse.ArgumentParser(description='simple parser')

parser.add_argument('--input_folder', type=str, default="./xml/",
                    help='path to only xml files', required=False)

parser.add_argument('--output_folder', type=str, default="output/", help='path to store the images ', required=False)
args = parser.parse_args()


def draw(image, pt_dict):
  pt_arr = []
  for p in pt_dict:
    pt_arr.append((int(p["x"]),int(p["y"])))
  image_draw = ImageDraw.Draw(image)
  image_draw.polygon(pt_arr, fill="#FFFFFF", outline ="white")
  del image_draw
  return image


def run_prog(in_folder, out_folder):
  #print(in_folder, out_folder)
  my_files = sorted(glob.glob(os.path.join(in_folder, "*.xml")))
  #print(my_files)
  for f in tqdm(my_files):
      try:
        if f.split(".")[-1].lower() not in "xml":
          print(f.split(".")[-1].lower())
          continue
        with open(f, 'r') as file:
          data = file.read().replace('\n', '')
          my_dict = xmltodict.parse(data)
          #print(data)
        #print(data)

        #print(my_dict)
        fname=my_dict['annotation']["filename"]
        fname_no = int(fname.replace(".jpg", ""))
        img_size_w =  int(my_dict['annotation']["imagesize"]["nrows"])
        img_size_h =  int(my_dict['annotation']["imagesize"]["ncols"])
        my_object = my_dict['annotation']['object']

        image = Image.new('RGB', (img_size_h, img_size_w))

        if  isinstance(my_object, dict):
          poly_pt_dict=my_object['polygon']
          pt_dict = poly_pt_dict['pt']
          image = draw(image, pt_dict)
        elif isinstance(my_object, list):
          #print(type(my_object))
          for el in my_object:
            #print(el)
            poly_pt_dict = el['polygon']
            pt_dict = poly_pt_dict['pt']
            image = draw(image, pt_dict)
            # pass
          #poly_pt_dict = my_object[-1]
          #continue
        #print(my_object)
        #poly_pt_dict=my_object['polygon']
        #print(poly_pt_dict)

        #print(pt_dict)


        #display(image)
        xx = (os.path.join(out_folder, f"{str(fname_no)}.jpg"))

        xx = xx[23:]
        #print(xx)

        test = './output2/' + xx
        xx = './images_original_size/' + xx
        print('xx',xx)
        #print(test)
        #break
        #print(xx,test)
        #print('xx',xx)
        #img = Image.open(xx)
        #img.save(test)
        os.rename(xx,test)
        image.save(os.path.join(out_folder, f"{str(fname_no)}.png"))
        #del image_draw
        del image
        del my_dict

      except:
          continue

if __name__ == "__main__":
  run_prog(args.input_folder, args.output_folder)

`

@zenoli
Copy link

zenoli commented Feb 25, 2021

Awesome, thx!

@aurooj
Copy link
Owner

aurooj commented Feb 26, 2021

Thanks @test1230-lab! closing this issue now.

@aurooj aurooj closed this as completed Feb 26, 2021
@aurooj aurooj pinned this issue Feb 26, 2021
@aurooj aurooj changed the title Hand over face Hand over face (High Resolution Masks) Feb 26, 2021
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

3 participants