Exemple #1
0
def train():
    images, shapes, labels = images_shapes_not_all_labels_unmarked()
    flip = State.getKey('/flip', None)
    Face.double_data(images, shapes, flip_order=flip)
    predictor = Face.train_shape_predictor(images, shapes)
    State.setKey('/predictor', predictor)
    State.push('train predictor')
Exemple #2
0
def set_frame_cb(fi):
    view = QApp.view()  # TODO should be part of the callback?
    if fi != frame_number():
        State.setKey('/frame_number', fi)
        State.push('change frame')
    img = get_frame_image(fi)
    update_gui_image(view, img)
    update_markup_mesh(view)
    QApp.app.updateMenus()  # trigger a full refesh here (TODO not needed?)
Exemple #3
0
def train_aam():
    images, shapes, labels = images_shapes_not_all_labels_unmarked()
    flip = State.getKey('/flip', None)
    aam_model = Face.train_aam_model(images,
                                     shapes,
                                     flip_order=flip,
                                     texture_rank=20)
    State.setKey('/aam', aam_model)
    State.push('train aam')
Exemple #4
0
def update_flip_order_last2():
    '''A hacky method that makes the last two added points be each others flip.'''
    flip = State.getKey('/flip', [16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,\
     26,25,24,23,22,21,20,19,18,17,27,28,29,30,35,34,33,32,31,45,44,43,42,47,46,\
     39,38,37,36,41,40,54,53,52,51,50,49,48,59,58,57,56,55,64,63,62,61,60,67,66,65])
    flip = list(flip)
    flip.extend([len(flip) + 1, len(flip)])
    print flip
    flip = np.int32(flip)
    State.setKey('/flip', flip)
    State.push('update flip last 2')
Exemple #5
0
    def setAttrs(self, attrs, location=None):
        if location is None: location = self.name

        # if State.hasKey(location):
        # 	locationAttrs = State.getKey(location)
        # 	for k, v in attrs.iteritems():
        # 		locationAttrs[k] = v
        # else:
        # 	locationAttrs = attrs

        State.setKey(location, {'type': location, 'attrs': attrs})
Exemple #6
0
def retriangulate():
    shp = get_predictor()['ref_shape']
    edges = []
    tris = Face.triangulate_2D(shp)
    for p0, p1, p2 in tris:
        edges.append((p0, p1))
        edges.append((p1, p2))
        edges.append((p2, p0))
    edges = np.int32(edges)
    tris = np.int32(tris)
    State.setKey('/edges', edges)
    State.setKey('/tris', tris)
    State.push('triangulate')
Exemple #7
0
	def setFieldValueCommand(self, field, value):
		'''Be careful, this is usually called from a qt callback, so we mustn't rebuild qt objects here.'''
		if self.value_is_adjusting: return
		#print 'setFieldValueCommand', repr(field), repr(value)
		#print '/%s/attrs/%s' % (State.getSel(),field)
		State.setKey('/%s/attrs/%s' % (State.getSel(),field),value)
		self.edit_signal.emit(State.getSel(),field,value) # DH
		self.clean_state() # if changing the field has side effects, these should happen before the push (I think)
		State.push('Set %s' % str(field))
		undoCmd = State.getUndoCmd()
		self.undoItem.setText('&Undo' if undoCmd is None else '&Undo [%s]' % undoCmd)
		redoCmd = State.getRedoCmd()
		self.redoItem.setText('Re&do' if redoCmd is None else 'Re&do [%s]' % redoCmd)
Exemple #8
0
	def createChild(self, name, type, atLocation=None, attrs=None):
		if atLocation is None: atLocation = self.path
		if atLocation not in self.scenegraph:
			self.scenegraph[atLocation] = {
				'type': 'group'
			}

		if not name:
			location = atLocation
		else:
			location = '/'.join([atLocation, name])

		if location not in self._cookedLocations: self._cookedLocations.append(location)
		self.registerCook(atLocation)

		if attrs is None: self.scenegraph[location] = {}
		else: self.scenegraph[location] = attrs
		self.scenegraph[location]['type'] = type
		State.setKey('/interface' + location, {'dirty': True})
		return self.scenegraph[location]
Exemple #9
0
def delete_image():
    fi = frame_number
    images = State.getKey('/images', [])
    shapes = State.getKey('/shapes', [])
    labels = State.getKey('/labels', [])
    images.pop(fi)
    shapes.pop(fi)
    labels.pop(fi)
    State.setKey('/images', images)
    State.setKey('/shapes', shapes)
    State.setKey('/labels', labels)
    State.push('delete image')
Exemple #10
0
def keypress_cb(view, key):
	if key == ord('R'):
		State.setKey('/root/ui/attrs/booting',True)
		State.push('boot face')
	if key == ord('N'):
		State.setKey('/root/ui/attrs/setting_neutral',True)
		State.push('set neutral')
	if key == ord('S'):
		toggle_unreal()
	if key == ord('Z'):
		State.setKey('/root/ui/attrs/debugging',not State.getKey('/root/ui/attrs/debugging'))
		State.push('debugging')
Exemple #11
0
def add_image(img, shp=None):
    if shp is None: shp = get_predictor()['ref_shape']
    if not State.hasKey('/images') or not State.hasKey(
            '/shapes') or not State.hasKey('/labels'):
        State.setKey('/images', [])
        State.setKey('/shapes', [])
        State.setKey('/labels', [])
    fi = len(State.getKey('/images'))
    lbl = np.zeros(len(shp), dtype=np.int32)  # unlabelled
    set_frame_image(fi, img)
    set_frame_markup(fi, shp)
    set_frame_labels(fi, lbl)
    State.push('add image')
Exemple #12
0
def reorder_images():
    images = State.getKey('/images')
    shapes = State.getKey('/shapes')
    labels = State.getKey('/labels')
    old_order = State.getKey('/order', np.arange(len(images), dtype=np.int32))
    norm_shapes, ref_shape, ref_pinv = Face.normalized_shapes(shapes)
    norm_shapes -= ref_shape
    shapes_u, shapes_s, shapes_vt = np.linalg.svd(norm_shapes.reshape(
        norm_shapes.shape[0], -1),
                                                  full_matrices=0)
    wts = np.sum(shapes_u**2, axis=1)
    order = np.argsort(wts)[::-1]
    images = [images[o] for o in order]
    shapes = [shapes[o] for o in order]
    labels = [labels[o] for o in order]
    State.setKey('/images', images)
    State.setKey('/shapes', shapes)
    State.setKey('/labels', labels)
    State.setKey('/order', old_order[order])
    State.push('reorder images')
Exemple #13
0
def delete_selected_vertex():
    vi = get_selected_vertex()
    shapes = State.getKey('/shapes')
    labels = State.getKey('/labels')
    vnames = State.getKey('/vnames')
    num_images, num_vertices = labels.shape
    which = range(0, vi) + range(vi + 1, num_vertices())
    shapes = list(np.float32(shapes)[:, which])
    labels = list(np.int32(labels)[:, which])
    vnames = [vnames[x] for x in which]
    State.setKey('/shapes', shapes)
    State.setKey('/labels', labels)
    State.setKey('/vnames', vnames)
    State.push('delete vertex')
Exemple #14
0
def add_vertex(vname=None):
    # TODO later, we want to initialise every vertex that has a zero label
    shapes = State.getKey('/shapes')
    labels = State.getKey('/labels')
    vnames = State.getKey('/vnames')
    if vname is None: vname = 'pt_%d' % len(vnames)
    shapes = np.float32(shapes)
    labels = np.int32(labels)
    num_images, num_vertices = labels.shape
    shapes = list(
        np.hstack((shapes, np.zeros((num_images, 1, 2), dtype=np.float32))))
    labels = list(
        np.hstack((labels, np.zeros((num_images, 1), dtype=np.int32))))
    vnames.append(vname)
    State.setKey('/shapes', shapes)
    State.setKey('/labels', labels)
    State.setKey('/vnames', vnames)
    State.push('add vertex')
Exemple #15
0
			if parent is None: return parent
		return parent

	def sync(self):
		'''synchronize the selection with the State selection'''
		index = self.selectionModel().currentIndex()
		key = State.getSel()
		if key is None: return
		if index.isValid():
			item = self.index_to_item(index)
			if item.data() == key: return
		item = self.generate_path_to(key)
		self.selectionModel().setCurrentIndex(self.item_to_index(item), QtGui.QItemSelectionModel.ClearAndSelect)

class QSTVWidget(QtGui.QWidget):
	def __init__(self, parent=None, root=''):
		QtGui.QWidget.__init__(self, parent)
		self.layout = QtGui.QVBoxLayout()
		self.treeView = QStateTreeView(self, root)
		self.layout.addWidget(self.treeView)
		self.setLayout(self.layout)

if __name__ == "__main__":
	import sys
	data = {'Alice':{'Keys':[0,1,2],'Purse':{'Cellphone':'nope'}},'Bob':{'Wallet':{'Credit card':53,'Money':[[0,1],[1,2]]}}}
	State.setKey('/doc',data)
	app = QtGui.QApplication([])
	window = QSTVWidget(root='/doc')
	window.show()
	sys.exit(app.exec_())
Exemple #16
0
    #State.setKey('/doc',payload)

    #fbx = decode(payload)
    #State.setKey('/fbx',fbx)
    #for k,v in fbx.iteritems(): State.setKey(k,v)

    from UI import QApp, QGLViewer, GLMeshes, GLPoints3D
    app, win = QGLViewer.makeApp(appName='Imaginarium FBX')
    #outliner = QApp.app.qobjects
    #for gi,(key,value) in enumerate(fbx.items()):
    #	outliner.addItem(str(key)+'='+repr(value)[:200], data=str(key), index=gi)

    display_nodes = skel_to_nodes(skel_dict)
    #print zip(*display_nodes)[1]
    #for gi,(disp,key) in enumerate(display_nodes): outliner.addItem(disp, data='_OBJ_'+key, index=gi)
    #global g_fields
    QApp.fields = dict([(k, sorted(v.items()))
                        for k, v in g_fields.iteritems()])

    for gi, (k, v) in enumerate(fbx['objs'].items()):
        State.setKey('/fbx/' + str(k), v)
    QApp.app.qoutliner.set_root('/fbx')
    #for gi,key in enumerate(sorted(State.allKeys())): outliner.addItem(key+'='+repr(State.getKey(key))[:80], data=key, index=gi)

    QGLViewer.makeViewer(
        timeRange=(0, 8000),
        callback=set_frame_CB,
        layers={'skel': skel_mesh},
        pickCallback=pickedCB
    )  #, dragCallback=dragCB, keyCallback=keyCB, drawCallback=drawGL_cb, layers=layers)
Exemple #17
0
def track_view_cb(fi, attrs):
	# g_mode = 0
	global g_webcam, g_md, g_rbfn, g_predictor
	# runtime options and state
	global g_prev_smooth_shape, g_prev_vs, g_hmc_boot, g_settle, g_head_pan_tilt_roll

	if attrs['using_webcam']:
		if g_webcam is None:
			g_webcam = WebCam()
			g_webcam.Open(State.getKey('/root/ui/attrs/cam_offset') + State.getKey('/root/ui/attrs/webcam_index'))
			g_webcam.SetProperty('FPS', State.getKey('/root/ui/attrs/cam_fps'))
			g_webcam.SetProperty('FRAME_WIDTH', State.getKey('/root/ui/attrs/cam_width'))
			g_webcam.SetProperty('FRAME_HEIGHT', State.getKey('/root/ui/attrs/cam_height'))
		if g_webcam is None:
			img = np.zeros((16,16,3),dtype=np.uint8)
		else:
			img = g_webcam.GetFrame()
			if img is None:
				img = np.zeros((16,16,3),dtype=np.uint8)
	elif g_md is not None:
		MovieReader.readFrame(g_md, seekFrame=fi) # only update the visible camera
		img = np.frombuffer(g_md['vbuffer'], dtype=np.uint8).reshape(g_md['vheight'],g_md['vwidth'],3)
		#QApp.app.qtimeline.setRange(0, g_md['vmaxframe'])
	else:
		img = np.zeros((16,16,3),dtype=np.uint8)
	
	mirror_scale = -1 if attrs['mirroring'] else 1
	rotate = attrs['rotate']

	if g_settle >= 0:
		if g_settle == 0 and g_prev_vs is not None:
			g_hmc_boot = g_prev_vs.copy()
		g_settle = g_settle - 1
	else:
		if attrs['HMC_mode'] and g_hmc_boot is not None: g_prev_vs = g_hmc_boot.copy()
		if attrs['booting'] or Face.test_reboot(img, g_prev_vs):
			g_prev_vs = Face.detect_face(img, g_predictor, 2, rotate)
			g_hmc_boot = None # in case we didn't detect a face
			g_settle = 10 # go into settle mode (10 frames)
			if g_prev_vs is not None:
				State.setKey('/root/ui/attrs/booting',False)
				if attrs['HMC_mode']: g_hmc_boot = g_prev_vs.copy()
	g_prev_vs = Face.track_face(img, g_predictor, g_prev_vs, rotate=rotate)

	# compensate for roll, translation and scale
	norm_shape, head_pan, head_tilt, A = stabilize_shape(g_prev_vs, setting_neutral=attrs['setting_neutral'])
	# dejitter
	if attrs['filtering']:
		g_prev_smooth_shape = filter_data(norm_shape, g_prev_smooth_shape)
	else:
		g_prev_smooth_shape = norm_shape.copy()
	# extract angles from the measured values
	head_pan_tilt_roll = np.degrees(np.arctan2([head_pan*mirror_scale, head_tilt, -mirror_scale*A[1][0]],[2,2,A[1][1]]))
	g_head_pan_tilt_roll = filter_data(head_pan_tilt_roll, g_head_pan_tilt_roll, 3.0)

	camera = QApp.view().camera
	camera.lockedUpright = False
	camera.cameraRoll = (-90*rotate if rotate != -1 else g_head_pan_tilt_roll[2])

	ret = g_prev_smooth_shape.copy()
	if attrs['mirroring']:
		flip_order = [16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0, 26,25,24,23,22,21,20,19,18,17, 27,28,29,30, 35,34,33,32,31, \
			  45,44,43,42, 47,46, 39,38,37,36, 41,40, 54,53,52,51,50,49,48, 59,58,57,56,55, 64,63,62,61,60, 67,66,65, 69,68]
		ret = ret[flip_order]
	slider_names, slider_values = applyRetarget(g_rbfn, ret)
	#State._setKey('/root/sliders/attrs', dict(zip(slider_names, slider_values))) # NO UNDO
	slider_names.extend(['NeckPan','NeckTilt','NeckRoll'])
	slider_values = np.float32(list(slider_values)+list(g_head_pan_tilt_roll))

	return g_head_pan_tilt_roll.copy(),g_prev_vs.copy(),norm_shape,img,slider_names,slider_values,A
Exemple #18
0
 def saveOps(self, filename):
     opNames = [(op.getName(), self.findRegisteredOpName(op))
                for op in self.ops]
     State.setKey('recipe', opNames)
Exemple #19
0
            'alMouthOuterCorner',
            'alMouthOuterLower1',
            'alMouthOuterLower2',
            'acMouthOuterLower',
            'arMouthOuterLower2',
            'arMouthOuterLower1',
            'arMouthInnerCorner',
            'arMouthInnerUpper',
            'acMouthInnerUpper',
            'alMouthInnerUpper',
            'alMouthInnerCorner',
            'alMouthInnerLower',
            'acMouthInnerLower',
            'arMouthInnerLower',  # 48:68
        ]
        State.setKey('/vnames', vnames)

    if 0:
        subset = [0, 7, 8, 9, 16, 27, 30, 31, 33, 35, 36, 39, 42, 45, 48, 54]
        flip = [
            subset.index(x) for x in
            [16, 9, 8, 7, 0, 27, 30, 35, 33, 31, 45, 42, 39, 36, 54, 48]
        ]
        vnames = [vnames[x] for x in subset]
        State.setKey('/flip', flip)
        State.setKey('/vnames', vnames)
        shapes = State.getKey('/shapes')
        labels = State.getKey('/labels')
        shapes = list(np.float32(shapes)[:, subset])
        labels = list(np.int32(labels)[:, subset])
        State.setKey('/shapes', shapes)
Exemple #20
0
def main():
	from UI import QGLViewer
	from UI import GLMeshes, GLPoints3D

	global g_setting_frame
	g_setting_frame = False
	# static data
	global g_webcam, g_md, g_rbfn, g_predictor, g_head_pan_shape, g_head_tilt_shape
	# runtime options and state
	global g_prev_smooth_shape, g_prev_vs, g_hmc_boot, g_neutral_corrective_shape, g_settle, g_head_pan_tilt_roll, g_smooth_pose
	global g_directory, g_TIS_server, g_mode, g_frame

	g_TIS_server = SocketServer.SocketServer()
	g_mode, g_frame = 0,{}

	grip_dir = os.environ['GRIP_DATA']
	g_directory = grip_dir

	g_webcam,g_md = None,None

	g_prev_vs, g_prev_smooth_shape = None,None
	g_hmc_boot = None
	#clear_neutral()
	g_neutral_corrective_shape = IO.load(os.path.join(g_directory,'neutral.out'))[1]
	g_settle = -1
	g_head_pan_tilt_roll = None
	g_smooth_pose = {}

	aam = IO.load(os.path.join(g_directory,'aam.out'))[1]
	if 0:
		svt = np.float32(aam['shapes']).reshape(-1,140)
		svt = np.dot(aam['shapes_u'],aam['shapes_s'].reshape(-1,1)*aam['shapes_vt'])
		svt = aam['shapes_s'].reshape(-1,1)*aam['shapes_vt']
		tmp = svt.reshape(svt.shape[0],-1,2)
		Sx,Sy = tmp[:,:,0],tmp[:,:,1]
		tmp = np.dot(np.dot(Sy.T,np.dot(Sx,Sx.T)),Sy)
		u,s,vt = np.linalg.svd(tmp, full_matrices=False)
		print s
		g_head_pan_shape = np.zeros((svt.shape[1]/2,2),dtype=np.float32)
		g_head_tilt_shape = np.zeros((svt.shape[1]/2,2),dtype=np.float32)
		g_head_pan_shape[:,0] = g_head_tilt_shape[:,1] = vt[0]
		print np.sum(g_head_pan_shape * aam['shapes_vt'][0].reshape(-1,2))
		print np.sum(g_head_tilt_shape * aam['shapes_vt'][1].reshape(-1,2))
	g_head_pan_shape = aam['shapes_vt'][0].reshape(-1,2)
	g_head_tilt_shape = aam['shapes_vt'][1].reshape(-1,2)
	g_head_tilt_shape = g_head_pan_shape[:,::-1]*np.float32([1,-1])
	print np.sum(g_head_pan_shape*g_head_tilt_shape)
	g_head_pan_shape *= np.linalg.norm(g_head_pan_shape)**-0.5
	g_head_tilt_shape *= np.linalg.norm(g_head_tilt_shape)**-0.5
	if np.sum(g_head_pan_shape[:,0] < 1): g_head_pan_shape = -g_head_pan_shape
	if np.sum(g_head_tilt_shape[:,1] > 1): g_head_tilt_shape = -g_head_tilt_shape
	#print np.sum(g_head_pan_shape * g_head_tilt_shape)
	#print np.dot(g_head_pan_shape[:,0],g_head_tilt_shape[:,1])

	g_predictor = Face.load_predictor(os.path.join(g_directory,'train.out'))
	rbfn_filename = os.path.join(g_directory,'rbfn.out')
	g_rbfn = IO.load(rbfn_filename)[1]
	#g_rbfn = convert_rbfn(rbfn_in_filename)
	#IO.save(rbfn_filename, g_rbfn)

	
	ref_shape = g_predictor['ref_shape']
	cx,cy = np.mean(ref_shape,axis=0)
	vx,vy = (np.var(ref_shape,axis=0)**0.5) * 2.5
	geo_bs = []
	ref_fs = Face.triangulate_2D(ref_shape)
	for p0,p1,p2 in ref_fs:
		geo_bs.append((p0,p1))
		geo_bs.append((p1,p2))
		geo_bs.append((p2,p0))
	geo_vs = np.zeros((len(ref_shape),3), dtype=np.float32)
	geo_fs = []
	geo_ts = np.float32([[1,0,0,0],[0,1,0,1000],[0,0,1,0]])
	geo_vts = np.zeros_like(ref_shape)
	
	img_vs = np.float32([[-1000,-1000,0],[1000,-1000,0],[1000,1000,0],[-1000,1000,0]])
	img_fs = np.int32([[0,1,2,3]])
	img_ts = np.float32([[1,0,0,0],[0,1,0,1000],[0,0,1,0]])
	img_vts = np.float32([[0,1],[1,1],[1,0],[0,0]])
	markup_mesh = GLPoints3D(vertices=geo_vs, edges=np.int32(geo_bs), names=[], colour=[0,1,0,1],edgeColour=[1,1,1,1])
	geo_mesh = GLMeshes(names=['geo_mesh'],verts=[geo_vs],faces=[geo_fs],transforms=[geo_ts],bones=[geo_bs], vts=[geo_vts], colour=[1,0,0,1])
	image_mesh = GLMeshes(names=['image_mesh'],verts=[img_vs],faces=[img_fs],transforms=[img_ts],vts=[img_vts])

	global g_bs_vs, g_bs_shape_mat, g_bs_fs, g_bs_vts, g_bs_shape_mat_T
	bs_dict = IO.load(os.path.join(g_directory,'harpy_ma.out'))[1]['blendShapes']['Harpy_cFace_GEOShape']
	obj_scale = 10.0
	g_bs_vs = np.float32(bs_dict['vs']*obj_scale)
	bs_dict['pts'] = [b*obj_scale for b in bs_dict['pts']]
	g_bs_fs = bs_dict['fs'] # warning: mix of quads and triangles :-(
	assert bs_dict['vts'].keys() == range(len(bs_dict['vts'].keys()))
	g_bs_vts = bs_dict['vts'].values()
	g_bs_ts = np.float32([[1,0,0,800],[0,1,0,-600],[0,0,1,300]])
	bs_mesh = GLMeshes(names=['bs_mesh'],verts=[g_bs_vs],faces=[g_bs_fs],transforms=[g_bs_ts],vts=[g_bs_vts],visible=False)

	rbfn_groups, rbfn_slider_splits, rbfn_slider_names, rbfn_marker_names = extract_groups(g_rbfn)
	slider_names = [(x[8:-2]+'.translateY' if x.startswith('get_ty') else x) for x in bs_dict['wt_names']]
	try:
		slider_order = [slider_names.index(x) for x in rbfn_slider_names]
	except Exception as e:
		print 'error',e
		slider_order = []
	g_bs_shape_mat = bs_dict['matrix'] = np.zeros((len(bs_dict['pts']), len(bs_dict['vs']), 3),dtype=np.float32)
	for m,ct,pt in zip(g_bs_shape_mat,bs_dict['cts'],bs_dict['pts']): m[ct] = pt
	g_bs_shape_mat = g_bs_shape_mat[slider_order]
	g_bs_shape_mat_T = g_bs_shape_mat.transpose(1,2,0).copy()

	layers = {'image_mesh':image_mesh,'geo_mesh':geo_mesh,'bs_mesh':bs_mesh,'markup_mesh':markup_mesh}
	app,win = QGLViewer.makeApp()
	outliner = win.qoutliner
	#for gi,geo in enumerate(layers.keys()): outliner.addItem(geo, data='_OBJ_'+geo, index=gi)

	State.setKey('ui',{'type':'ui','attrs':{\
		'harpy_xoffset':300.0,'show_harpy':True,'rotate':0,'mirroring':False,'unreal':True,'streaming_TIS':False,\
		'using_webcam':False,'HMC_mode':True,'booting':True,'filtering':True,'setting_neutral':True,'debugging':False, \
		'webcam_index':0,'cam_offset':700,'cam_fps':50,'cam_width':1280,'cam_height':720, 'movie_filename':''}})
	if True: # running on deployed face machine at 720p50
		State.setKey('/root/ui',{'type':'ui','attrs':{\
			'harpy_xoffset':300.0,'show_harpy':False,'rotate':1,'mirroring':False,'unreal':True,'streaming_TIS':False,\
			'using_webcam':True,'HMC_mode':True,'booting':True,'filtering':True,'setting_neutral':True,'debugging':False, \
			'webcam_index':0,'cam_offset':700,'cam_fps':50,'cam_width':1280,'cam_height':720, 'movie_filename':''}})
	win.setFields('ui',     [
		('show_harpy',      'show_harpy','Whether to display the Harpy','bool', False),
		('harpy_xoffset',   'xoffset', 'Pixels to offset Harpy to right', 'float', 300.0),
		('rotate',          'rotation','Rotate image 0=up,1=left,2=down,3=right,-1=any angle','int', 0),
		('mirroring',       'mirror',  'Show reversed',                 'bool', False),
		('unreal',          'unreal',  'Whether to connect to unreal',  'bool', True),
		#('streaming_TIS',   'streaming_TIS',  'Whether currently streaming',   'bool', False),
		('using_webcam',    'webcam',  'Whether using the webcam',      'bool', False),
		('HMC_mode',        'HMC_mode','Boot every frame',              'bool', True),
		('booting',         'boot',    'Boot at next chance',           'bool', True),
		('filtering',       'filter',  'Whether to filter noise',       'bool', True),
		('setting_neutral', 'neutral', 'Set neutral at next chance',    'bool', False),
		('debugging',       'debug',   'Show rbfn input for debugging', 'bool', False),
		('webcam_index',    'camindex', 'The index of the webcam',      'int',  0),
		('cam_offset',      'camoffset','The offset of the webcam',     'int',  700),
		('cam_fps',         'fps',      'The frame rate of the webcam', 'int',  50),
		('cam_width',       'width',    'The width of the webcam image', 'int',  1280),
		('cam_height',      'height',   'The height of the webcam image', 'int',  720),
		('movie_filename',  'movie',   'The filename of the movie', 'string',  ''),
		])
	slider_names = sorted(g_rbfn['slider_names'])
	win.setFields('sliders', [(sn,sn,'Slider %d'%si,'float',0.0) for si,sn in enumerate(slider_names)])
	State.setKey('/root/sliders', {'type':'sliders','attrs':{sn:0.0 for sn in slider_names}})
	outliner.set_root('/root')
	#outliner.addItem('sliders', data='sliders', index=1)
	win.outliner.raise_()
	#win.select('ui')
	QApp.app.dirtyCB = dirty_cb
	QApp.app.addMenuItem({'menu':'&File','item':'Import &movie','tip':'Import a movie file','cmd':import_movie})
	QApp.app.addMenuItem({'menu':'&Edit','item':'Retrain rbfn','tip':'Train the rbfn','cmd':retrain_RBFN})
	QApp.app.addMenuItem({'menu':'&Edit','item':'Retrain rbfn (no linear)','tip':'Train the rbfn with no linear part','cmd':retrain_RBFN_no_linear})
	QApp.app.addMenuItem({'menu':'&Edit','item':'Retrack refresh rbfn','tip':'Refresh the rbfn','cmd':retrack_refresh_rbfn})
	QApp.app.addMenuItem({'menu':'&Edit','item':'Retrack remap rbfn','tip':'Rebuild the rbfn','cmd':retrack_remap_rbfn})
	QApp.app.addMenuItem({'menu':'&File','item':'Export rbfn','tip':'Export the rbfn','cmd':export_rbfn})
	State.clearUndoStack()
	QGLViewer.makeViewer(appName='StreamVideoTrack',timeRange=(0,100), callback=setFrame_cb, keyCallback=keypress_cb, layers=layers, mats=[Calibrate.makeMat(Calibrate.composeRT(np.eye(3)*[10,10,1],[0,1000,6000],1000),[0,0],[1920,1080])], camera_ids=['RBFN'])

	# Ensure the server has stopped when program terminates
	g_TIS_server.Stop()
Exemple #21
0
def import_predictor(fn=None):
    if fn is None:
        fn, _ = QApp.app.loadFilename('Choose predictor to open', cwd(),
                                      'Predictor Files (*.io)')
    State.setKey('/predictor', Face.load_predictor(fn))
    set_cwd(fn)
Exemple #22
0
def set_cwd(fn):
    State.setKey('/cwd', os.path.dirname(fn))
Exemple #23
0
def set_frame_labels(fi, lbl):
    State.setKey('/labels/%d' % fi, np.int32(lbl))
Exemple #24
0
def load_object(desc, filetype, key):
    print 'imorting', desc
    fn, _ = QApp.app.loadFilename('Choose ' + desc + ' to open', cwd(),
                                  filetype)
    State.setKey(key, IO.load(fn)[1])
    set_cwd(fn)
Exemple #25
0
def set_frame_image(fi, img):
    State.setKey('/images/%d' % fi, JPEG.compress(img))
Exemple #26
0
def set_frame_markup(fi, shp):
    State.setKey('/shapes/%d' % fi, np.float32(shp))
Exemple #27
0
def clear_neutral():
	global g_neutral_corrective_shape
	State.setKey('/root/ui/attrs/setting_neutral',False)
	g_neutral_corrective_shape = 0
Exemple #28
0
def set_selected_vertex(vi):
    State.setKey('/markup_mesh_sel', vi)
    markup_mesh = QApp.view().getLayer('markup_mesh')
    markup_mesh.selectedIndex = vi
Exemple #29
0
def import_movie():
	global g_directory
	vid_filename,_ = QApp.app.loadFilename('Choose a movie to open',directory=g_directory,filtr='Movie Files (*.mp4 *.mov *.avi *.flv)')
	if vid_filename: State.setKey('/root/ui/attrs/movie_filename',vid_filename)