Beispiel #1
0
 def dump(mat, refs, pid, cam, im_dir):
     """Save the images of a person under one camera."""
     for i, ref in enumerate(refs):
         im = deref(mat, ref)
         if im.size == 0 or im.ndim < 2: break
         fname = new_im_name_tmpl.format(pid, cam, i)
         imsave(osp.join(im_dir, fname), im)
 def dump(mat, refs, pid, cam, im_dir):
   """Save the images of a person under one camera."""
   for i, ref in enumerate(refs):
     im = deref(mat, ref)
     if im.size == 0 or im.ndim < 2: break
     fname = new_im_name_tmpl.format(pid, cam, i)
     imsave(osp.join(im_dir, fname), im)
Beispiel #3
0
def map_im_names(ori_im_names, parse_im_name, new_im_name_tmpl):
    """Map original im names to new im names."""
    cnt = defaultdict(int)
    new_im_names = []
    for im_name in ori_im_names:
        im_name = osp.basename(im_name)
        id = parse_im_name(im_name, 'id')
        cam = parse_im_name(im_name, 'cam')
        cnt[(id, cam)] += 1
        new_im_name = new_im_name_tmpl.format(id, cam, cnt[(id, cam)] - 1)
        new_im_names.append(new_im_name)
    return new_im_names
def map_im_names(ori_im_names, parse_im_name, new_im_name_tmpl):
  """Map original im names to new im names."""
  cnt = defaultdict(int)
  new_im_names = []
  for im_name in ori_im_names:
    im_name = osp.basename(im_name)
    id = parse_im_name(im_name, 'id')
    cam = parse_im_name(im_name, 'cam')
    cnt[(id, cam)] += 1
    new_im_name = new_im_name_tmpl.format(id, cam, cnt[(id, cam)] - 1)
    new_im_names.append(new_im_name)
  return new_im_names
Beispiel #5
0
def move_ims(ori_im_paths, new_im_dir, parse_im_name, new_im_name_tmpl,
             new_start_id):
    """Rename and move images to new directory."""
    ids = [parse_im_name(osp.basename(p), 'id') for p in ori_im_paths]
    cams = [parse_im_name(osp.basename(p), 'cam') for p in ori_im_paths]

    unique_ids = list(set(ids))
    unique_ids.sort()
    id_mapping = dict(
        zip(unique_ids, range(new_start_id, new_start_id + len(unique_ids))))

    new_im_names = []
    cnt = defaultdict(int)
    for im_path, id, cam in zip(ori_im_paths, ids, cams):
        new_id = id_mapping[id]
        cnt[(new_id, cam)] += 1
        new_im_name = new_im_name_tmpl.format(new_id, cam,
                                              cnt[(new_id, cam)] - 1)
        shutil.copy(im_path, ospj(new_im_dir, new_im_name))
        new_im_names.append(new_im_name)
    return new_im_names, id_mapping
def move_ims(
    ori_im_paths,
    new_im_dir,
    parse_im_name,
    new_im_name_tmpl,
    new_start_id):
  """Rename and move images to new directory."""
  ids = [parse_im_name(osp.basename(p), 'id') for p in ori_im_paths]
  cams = [parse_im_name(osp.basename(p), 'cam') for p in ori_im_paths]

  unique_ids = list(set(ids))
  unique_ids.sort()
  id_mapping = dict(
    zip(unique_ids, range(new_start_id, new_start_id + len(unique_ids))))

  new_im_names = []
  cnt = defaultdict(int)
  for im_path, id, cam in zip(ori_im_paths, ids, cams):
    new_id = id_mapping[id]
    cnt[(new_id, cam)] += 1
    new_im_name = new_im_name_tmpl.format(new_id, cam, cnt[(new_id, cam)] - 1)
    shutil.copy(im_path, ospj(new_im_dir, new_im_name))
    new_im_names.append(new_im_name)
  return new_im_names, id_mapping