aurooj / Hand-Segmentation-in-the-Wild

MIT License
194 stars 38 forks source link

Hand over face (High Resolution Masks) #10

Closed test1230-lab closed 3 years ago

test1230-lab commented 4 years ago

Are there any higher res masks avalible?

aurooj commented 4 years ago

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 commented 4 years ago

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

aurooj commented 4 years ago

Correct, that would come from processing xml files. Great, if you already processed the xml annotations. Sure, you can share with me and I will put them on the project page with the acknowledgement.

On Fri, Sep 25, 2020, 9:27 PM test1230-lab notifications@github.com wrote:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/aurooj/Hand-Segmentation-in-the-Wild/issues/10#issuecomment-699263133, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADRLQXKEUBMM4S4JRXCAPRTSHU7OJANCNFSM4RRLPDDA .

zenoli commented 3 years ago

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

test1230-lab commented 3 years ago

out.zip here, manually clean iirc

zenoli commented 3 years ago

@test1230-lab Thank you very much!

test1230-lab commented 3 years ago

no problem

On Wed, Feb 24, 2021 at 9:38 AM zenoli notifications@github.com wrote:

@test1230-lab https://github.com/test1230-lab Thank you very much!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/aurooj/Hand-Segmentation-in-the-Wild/issues/10#issuecomment-785120901, or unsubscribe https://github.com/notifications/unsubscribe-auth/APLSDRETCAJ6L7ZP3XR7K23TAUFQDANCNFSM4RRLPDDA .

zenoli commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

Awesome, thx!

aurooj commented 3 years ago

Thanks @test1230-lab! closing this issue now.