def get_antfarm_config(vid,fignum=1,cfg_fn=cfg_fn,force=False): cfg = cfg_fn(vid) if os.path.exists(cfg): config = eval(open(cfg).read()) else: config = {} pylab.close(fignum) fr = vidtools.extract_change_over_vid(vid,1) pylab.matshow(fr,fignum=fignum) if force or not config.has_key('burrow_entrance'): print >> sys.stderr, 'click burrow entrance' config['burrow_entrance'] = ginput_int(1)[0] if force or not config.has_key('hill_bounds'): print >> sys.stderr, 'click excavated sand hill bounds' config['hill_bounds'] = [x for x,y in ginput_int(2)] pylab.close(fignum) fr = vidtools.extract_keyframe(vid,1) pylab.matshow(fr,fignum=fignum) if force or not config.has_key('ground_anchors'): print >> sys.stderr, 'click ground anchor points, and press enter when finished' config['ground_anchors'] = ginput_int(0) if force or not config.has_key('predug'): print >> sys.stderr, 'click 4 predug burrow corners (top-ground, top-end, bottom-end, bottom-ground), and press enter when finished, or press enter without clicking any points' pts = ginput_int(0) if len(pts): config['predug'] = pts fr = vidtools.extract_keyframe(vid,vidtools.vid_duration(vid)-1) pylab.matshow(fr,fignum=fignum) if force or not config.has_key('end_ground_anchors'): print >> sys.stderr, 'click trial end ground anchor points, and press enter when finished' config['end_ground_anchors'] = ginput_int(0) open(cfg,'w').write(config.__repr__()) pylab.close(fignum)
def get_crop_config_show(vid,fignum=1): '''given a video, display crop keyframe and return empty cropdict''' fr = vidtools.extract_keyframe(vid) pylab.close(fignum) pylab.matshow(fr,fignum=fignum) these_inds = re.split('[-_](\d)[-_]',os.path.basename(os.path.dirname(vid))) print >> sys.stderr, '\nZoom on antfarms and store crops, e.g.' for af,ind in zip(these_inds[1::2],these_inds[2::2]): print >> sys.stderr, "antfarm %s: cropsdict['%s'] = viz_vidtools.current_view_crop(%s,fr.shape)" % (af,ind,fignum) return {},fr
def get_epm_config(vid,fignum=1,cfg_fn=epm_cfg_fn,close_fig=False): pylab.figure(fignum) pylab.clf() fr = vidtools.extract_keyframe(vid,sec=120) pylab.matshow(fr,fignum=fignum) print >> sys.stderr, 'click 8 arm corners, proceeding clockwise from the top left corner of the top arm' pts = pylab.ginput(8,timeout=0) zones = calc_epm_zones(pts) show_epm_config(pts,zones,fignum) pylab.ylim(fr.shape[0],0) pylab.xlim(0,fr.shape[1]) print >> sys.stderr, 'click to revise points or press enter to accept and write configuration' change_pt = pylab.ginput(1,timeout=0) #change_pt = raw_input('enter the number of an anchor point to change or press enter to save configuration: ') while change_pt: # print >> sys.stderr, 'click the revised position for point %s' % change_pt # pts[int(change_pt)] = pylab.ginput(1,timeout=0)[0] change_pt = change_pt[0] change_idx = min([(vidtools.hypotenuse(change_pt,pt),i) for i,pt in enumerate(pts)])[1] pts[change_idx] = change_pt zones = calc_epm_zones(pts) pylab.clf() pylab.matshow(fr,fignum=fignum) show_epm_config(pts,zones,fignum) pylab.ylim(fr.shape[0],0) pylab.xlim(0,fr.shape[1]) print >> sys.stderr, 'click to revise points or press enter to accept and write configuration' change_pt = pylab.ginput(1,timeout=0) # change_pt = raw_input('enter the number of an anchor point to change or press enter to save configuration: ') cfg = cfg_fn(vid) try: os.makedirs(os.path.dirname(cfg)) except: pass open(cfg,'w').write(zones.__repr__()) if close_fig: pylab.close(fignum)