コード例 #1
0
def make_temp_animated_gif_cmdline(seq,
                                   duration=0.5,
                                   dir=None,
                                   tmp_ext='.ppm'):
    seq_fname = ut.make_temp('.gif', dir=dir)
    # avoid ffmpeg prompt
    os.system('rm %s' % seq_fname)
    base = ut.make_temp('')
    #fnames = ['%s_%d.jpg' % (base, i) for i in xrange(len(seq))]
    fnames = ['%s_%04d%s' % (base, i, tmp_ext) for i in xrange(len(seq))]

    # for fname, x in zip(fnames, seq):
    #   ig.save(fname, x)

    # def f((fname, x)):
    #   ig.save(fname, x)

    ut.parmap(save_helper, zip(fnames, seq))

    ut.prn_sys('convert -layers OptimizePlus -delay %f -loop 0 %s_*%s %s' %
               (duration, base, tmp_ext, seq_fname))

    #fps = 1./duration
    # ut.prn_sys('ffmpeg -r %f -i %s_%%d.jpg %s.avi' % (fps, base, base))
    # ut.prn_sys('ffmpeg -i %s.avi -pix_fmt rgb24 %s' % (base, seq_fname))
    return seq_fname
コード例 #2
0
ファイル: imtable.py プロジェクト: abhishah/camo
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)))
コード例 #3
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)))
コード例 #4
0
def play(samples_or_snd, sr=None, compress=True):
    if sr is None:
        samples = samples_or_snd.samples
        sr = samples_or_snd.rate
    else:
        samples = samples_or_snd
    snd = Sound(None, sr, samples)  # .unnormalized('int16')

    path = ut.pjoin(imtable.get_www_path(), 'sounds')
    if compress:
        with ut.temp_file('.wav') as wav_fname:
            fname = ut.make_temp('.mp3', dir=path)
            #scipy.io.wavfile.write(wav_fname, snd.rate, snd.samples)
            snd.save(wav_fname)
            os.system('ffmpeg -loglevel error -y -i "%s" "%s"' %
                      (wav_fname, fname))
    else:
        fname = ut.make_temp('.wav', dir=path)
        scipy.io.wavfile.write(fname, snd.rate, snd.samples)

    os.system('chmod a+rwx %s' % fname)
    #url = ut.pjoin(imtable.PUBLIC_URL, 'sounds', os.path.split(fname)[1])
    url = ut.pjoin(imtable.get_url(), 'sounds', os.path.split(fname)[1])
    print(url)
    return url
コード例 #5
0
ファイル: imtable.py プロジェクト: xsingit/multisensory
    def make_html(self, out_dir, ext='.mp4'):
        if self.video_url is None:
            if self.video_fname is None:
                fname = ut.make_temp(ext, dir=out_dir)
                os.remove(fname)
                make_video(fname, self.ims, self.fps, sound=self.sound)
            else:
                fname = ut.make_temp(ext, dir=out_dir)
                os.remove(fname)
                if self.copy_method == 'copy':
                    os.system('cp "%s" %s' % (self.video_fname, fname))
                elif self.copy_method == 'symlink':
                    os.system('ln -s "%s" %s' % (self.video_fname, fname))
                else:
                    raise RuntimeError()
            rel_fname = fname.split('/')[-1]
        else:
            rel_fname = self.video_url

        vid_id = str(random.random())

        return """
    <table>
      <tr>
        <td>
          <video controls id = "%(vid_id)s" onplay = "vid_focus = null;" onpause = "vid_focus = document.getElementById('%(vid_id)s');" onloadedmetadata = "var t = getParameterByName('videoStart'); if (t != null) { this.currentTime = t; } if (getParameterByName('videoAutoplay')) { this.play(); }">
          <source src = "%(rel_fname)s" type = "video/mp4" preload = "none"> </video>
        </td>
        <td>
          Speed: <input type = "text" size = "5" value = "1" oninput = "document.getElementById('%(vid_id)s').playbackRate = parseFloat(event.target.value);">
        </td>
      </tr>
    </table>
          """ % locals()
コード例 #6
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
コード例 #7
0
ファイル: imtable.py プロジェクト: abhishah/camo
def make_temp_animated_gif_cmdline(seq, duration = 0.5, dir = None, tmp_ext = '.ppm'):
  seq_fname = ut.make_temp('.gif', dir = dir)
  # avoid ffmpeg prompt
  os.system('rm %s' % seq_fname)
  base = ut.make_temp('')
  #fnames = ['%s_%d.jpg' % (base, i) for i in xrange(len(seq))]
  fnames = ['%s_%04d%s' % (base, i, tmp_ext) for i in xrange(len(seq))]
  
  # for fname, x in zip(fnames, seq):
  #   ig.save(fname, x)

  # def f((fname, x)):
  #   ig.save(fname, x)
    
  ut.parmap(save_helper, zip(fnames, seq))
  
  ut.prn_sys('convert -layers OptimizePlus -delay %f -loop 0 %s_*%s %s' % (duration, base, tmp_ext, seq_fname))
             
  #fps = 1./duration
  # ut.prn_sys('ffmpeg -r %f -i %s_%%d.jpg %s.avi' % (fps, base, base))
  # ut.prn_sys('ffmpeg -i %s.avi -pix_fmt rgb24 %s' % (base, seq_fname))
  return seq_fname
コード例 #8
0
def play(samples_or_snd, sr=None):
    if sr is None:
        samples = samples_or_snd.samples
        sr = samples_or_snd.rate
    else:
        samples = samples_or_snd
    snd = Sound(None, sr, samples).unnormalized('int16')

    path = ut.pjoin(imtable.WWW_PATH, 'sounds')
    fname = ut.make_temp('.wav', dir=path)
    scipy.io.wavfile.write(fname, snd.rate, snd.samples)
    os.system('chmod a+rwx %s' % fname)
    url = ut.pjoin(imtable.PUBLIC_URL, 'sounds', os.path.split(fname)[1])
    print url
    return url
コード例 #9
0
    def make_html(self, out_dir, ext='.mp4'):
        #print 'HACK'
        fname = ut.make_temp(ext, dir=out_dir)
        os.remove(fname)
        make_video(fname, self.ims, self.fps)
        #return """<video controls> <source src = "%s" type = "video/mp4"> </video> """ % fname.split('/')[-1]

        rel_fname = fname.split('/')[-1]
        vid_id = str(random.random())
        return """
    <table>
      <tr>
        <td>
          <video controls id = "%(vid_id)s" onplay = "vid_focus = null;" onpause = "vid_focus = document.getElementById('%(vid_id)s');"> <source src = "%(rel_fname)s" type = "video/mp4"> </video>
        </td>
        <td>
          Speed: <input type = "text" value = "1" oninput = "document.getElementById('%(vid_id)s').playbackRate = parseFloat(event.target.value);">
        </td>
      </tr>
    </table>
          """ % locals()
コード例 #10
0
ファイル: imtable.py プロジェクト: abhishah/camo
  def make_html(self, out_dir, ext = '.mp4'):
    #print 'HACK'
    fname = ut.make_temp(ext, dir = out_dir)
    os.remove(fname)
    make_video(fname, self.ims, self.fps)
    #return """<video controls> <source src = "%s" type = "video/mp4"> </video> """ % fname.split('/')[-1]

    rel_fname = fname.split('/')[-1]
    vid_id = str(random.random())
    return """
    <table>
      <tr>
        <td>
          <video controls id = "%(vid_id)s" onplay = "vid_focus = null;" onpause = "vid_focus = document.getElementById('%(vid_id)s');"> <source src = "%(rel_fname)s" type = "video/mp4"> </video>
        </td>
        <td>
          Speed: <input type = "text" value = "1" oninput = "document.getElementById('%(vid_id)s').playbackRate = parseFloat(event.target.value);">
        </td>
      </tr>
    </table>
          """ % locals()
コード例 #11
0
 def __init__(self, in_fname):
     self.in_fname = in_fname
     self.out_fname = ut.make_temp('.wav')
     os.remove(self.out_fname)
コード例 #12
0
ファイル: img.py プロジェクト: abhishah/camo
def save_tmp(im, encoding = '.png', dir = None):
  fname = ut.make_temp(encoding, dir = dir)
  save(fname, im)
  return fname
コード例 #13
0
ファイル: img.py プロジェクト: abhishah/camo
def show_html(html):
  page = ut.make_temp('.html')
  ut.make_file(page, html)
  print 'opening', page
  webbrowser.open(page)
コード例 #14
0
def save_tmp(im, encoding='.png', dir=None):
    fname = ut.make_temp(encoding, dir=dir)
    save(fname, im)
    return fname
コード例 #15
0
def show_html(html):
    page = ut.make_temp('.html')
    ut.make_file(page, html)
    print 'opening', page
    webbrowser.open(page)