Esempio n. 1
0
def path_from_im(x, output_dir, img_encoding = '.png'):
  if type(x) == type((1,)):
    x = list(x)
    assert x[0] in ('img', 'img_mv')
    mv_im = (x[0] == 'img_mv')
    if type(x[1]) == type(''):
      x[1] = os.path.abspath(x[1])
    im = x[1]
  else:
    mv_im = False
    im = x
  if type(im) == type(''):
    if mv_im:
      new_path = ut.make_temp(os.path.splitext(im)[1], dir = output_dir)
      #new_path = ut.make_temp(img_encoding, dir = output_dir)
      #os.rename(im, new_path)
      ut.sys_check_silent('mv', im, new_path)
      return os.path.split(new_path)[1]
    else:
      return im
  elif type(im) == type(np.array([])):
    path = ut.make_temp(img_encoding, dir = output_dir)
    ig.save(path, im)
    # use relative path in webpage so the directory can be moved
    return os.path.split(path)[1]
  else:
    ut.fail("Don't know how to handle image type: %s" % str(type(im)))
Esempio n. 2
0
def path_from_im(x, output_dir, img_encoding='.png'):
    if type(x) == type((1, )):
        x = list(x)
        assert x[0] in ('img', 'img_mv')
        mv_im = (x[0] == 'img_mv')
        if type(x[1]) == type(''):
            x[1] = os.path.abspath(x[1])
        im = x[1]
    else:
        mv_im = False
        im = x
    if type(im) == type(''):
        if mv_im:
            new_path = ut.make_temp(os.path.splitext(im)[1], dir=output_dir)
            #new_path = ut.make_temp(img_encoding, dir = output_dir)
            #os.rename(im, new_path)
            ut.sys_check_silent('mv', im, new_path)
            return os.path.split(new_path)[1]
        else:
            return im
    elif type(im) == type(np.array([])):
        path = ut.make_temp(img_encoding, dir=output_dir)
        ig.save(path, im)
        # use relative path in webpage so the directory can be moved
        return os.path.split(path)[1]
    else:
        ut.fail("Don't know how to handle image type: %s" % str(type(im)))
Esempio n. 3
0
def vl_sift(im,
            frames=None,
            orientations=False,
            peak_thresh=None,
            edge_thresh=None):
    """ Compute SIFT keypoints and descriptors using VLFeat binary.
  Should be thread-safe. """
    ut.check(frames is None or frames.shape[1] == 4)
    # frame_fname = '../tmp/vl_frames.frame'
    # im_fname1 = '../tmp/vl_im.png'
    # im_fname2 = '../tmp/vl_im.pgm'
    # out_fname = '../tmp/vl_out.sift'
    frame_fname = ut.make_temp('.frame')
    im_fname1 = ut.make_temp('.png')
    im_fname2 = ut.make_temp('.pgm')
    out_fname = ut.make_temp('.sift')
    #ut.write_lines(frame_fname, ('%f %f %f 0 0 %f' % (pt[0], pt[1], s, s) for pt in pts for s in scales))
    ig.save(im_fname1, im)
    os.system('convert %s %s' % (im_fname1, im_fname2))
    frame_opt = ''
    if frames is not None:
        ut.write_lines(frame_fname, ('%f %f %f %f' % tuple(f) for f in frames))
        frame_opt = '--read-frames %s' % frame_fname
    orientation_opt = '--orientations' if orientations else ''
    peak_opt = '--peak-thresh %f' % peak_thresh if peak_thresh is not None else ''
    edge_opt = '--edge-thresh %f' % edge_thresh if edge_thresh is not None else ''
    ut.sys_check("%s %s %s %s -o %s %s %s" %
                 (SiftPath, im_fname2, frame_opt, orientation_opt, out_fname,
                  peak_opt, edge_opt))
    sift = read_sift(out_fname)
    os.system('rm %s %s %s' % (im_fname1, im_fname2, out_fname))
    return sift
Esempio n. 4
0
def make_video_helper((i, x, in_dir, tmp_ext)):
    out_fname = ut.pjoin(in_dir, 'ao-video-frame%05d%s' % (i, tmp_ext))
    if type(x) == type(''):
        f = open(out_fname, 'wb')
        f.write(x)
        f.close()
    else:
        # pad to be even
        x = pad_im_even(x)
        ig.save(out_fname, x)
Esempio n. 5
0
 def onConvertToICO(self, event):
     pngfile = self.parent.listItem[self.item][0]
     icofile = pngfile.replace('.png', '.ico')
     if os.path.exists(icofile):
         wx.MessageBox(
             'A named "%s" is available.' % (os.path.basename(icofile)),
             'Attention')
     else:
         img = Image.open(pngfile)
         img.save(icofile)
         self.parent.reloadTree(self.parent.path)
Esempio n. 6
0
def load_screenshot(path):
    """Copy the selected image, changing format if needed."""
    img = Image.open(path).convert('RGB')  # Remove alpha channel if present.
    COMPILE_CFG['Screenshot']['LOC'] = SCREENSHOT_LOC
    img.save(SCREENSHOT_LOC)
    set_screenshot(img)
Esempio n. 7
0
def make_video_helper((i, x, in_dir, tmp_ext)):
    # pad to be even
    if x.shape[0] % 2 == 1 or x.shape[1] % 2 == 1:
        x = ig.pad_corner(x, x.shape[1] % 2, x.shape[0] % 2)
    ig.save(ut.pjoin(in_dir, 'ao-video-frame%05d%s' % (i, tmp_ext)), x)
Esempio n. 8
0
def save_helper((fname, x)):
    ig.save(fname, x)
Esempio n. 9
0
def make_video_helper((i, x, in_dir, tmp_ext)):
  # pad to be even
  if x.shape[0] % 2 == 1 or x.shape[1] % 2 == 1:
    x = ig.pad_corner(x, x.shape[1] % 2, x.shape[0] % 2)
  ig.save(ut.pjoin(in_dir, 'ao-video-frame%05d%s' % (i, tmp_ext)), x)
Esempio n. 10
0
def save_helper((fname, x)):
  ig.save(fname, x)