示例#1
0
	def restore_settings(self, fname):
		
		"""
		Restores all settings from a file
		"""
		
		if not os.path.exists(fname):
			print "%s not found" % fname
			return False
		
		print "Restoring from %s" % fname
			
		f = open(fname, "r")
		try:
			settings = pickle.load(f)
		except:
			f.close()
			print "Failed to restore from %s" % fname
			return False
		f.close()
		
		camera_dev = settings["camera_dev"]
		resolution = settings["resolution"]
		
		# Initialize if etracker has not yet been initialized, reinit otherwise
		if hasattr(self, "et"):
			self.et.reinit_camera(camera_dev, resolution)
		else:
			self.et = self.et = etracker.etracker(camera_dev, resolution, self)

		self.et.log_samples = settings["log_samples"]
		self.et.smov_threshold = settings["smov_threshold"]
		self.et.emov_threshold = settings["emov_threshold"]
		self.et.v3d = settings["v3d"]
		self.et.monitor_tracking = settings["monitor_tracking"]
		self.et.monitor_webcam = settings["monitor_webcam"]
		etracker.camera.cvar.match_mode = settings["match_mode"]
		etracker.camera.cvar.size_mode = settings["size_mode"]
		etracker.camera.cvar.min_z = settings["min_z"]
		self.et.control_mouse = settings["control_mouse"]
		self.et.host = settings["host"]
		self.et.port = settings["port"]
		self.et.target_t_res = settings["target_tres"]
		self.et.comm_protocol = settings["protocol"]
		
		for option in settings["camera_options"]:
			self.et.set_camera_option(option, settings["camera_options"][option])
			
		for o in settings["objects"]:
			self.et.objects.append(etracker.tracker_object(o, settings["objects"][o][0], settings["objects"][o][1], self.et))
		self.update_object_list()
		
		return True
示例#2
0
- Track your objects!
"""

import sys
from mantra import etracker
import os

# Some options
resolution = 320, 240
device = None # Get first device
mantra = None # No GUI
protocol = 'udp' # udp for OpenSesame, tcp for E-Prime
log_file = 'recording.tsv'

# Initialize the tracker
et = etracker.etracker(device, resolution, mantra)
et.comm_protocol = protocol
et.fname = log_file

# Keep adding new objects until escape is pressed
while True:
	o = et.define_object(0)
	if o == None:
		if len(et.objects) == 0:			
			print "Exiting"
			sys.exit()
		break
	print "Object has the following RGB values:", o.color
	et.objects.append(o)

# Track!
示例#3
0
	def __init__(self, parent = None):
	
		"""
		The constructor
		"""
		
		QtGui.QWidget.__init__(self, parent)
												
		# Setup the UI
		self.ui = mantra_gui.Ui_MainWindow()
		self.ui.setupUi(self)
		self.toggle_advanced_options()
		self.toggle_camera_options()
		
		self.ui.title.setText(str(self.ui.title.text()).replace("[version]", self.version))
		self.setWindowTitle("Mantra %s" % self.version)
		
		# Restore settings and init with default values if this fails
		if not self.restore_settings(os.environ["HOME"] + "/.default.mantraprofile"):		
			self.et = etracker.etracker(None, None, self)
		
		# Continu setting up the UI
		self.set_options()	
		self.timer = QtCore.QTimer()
		
		# Make the connections
		QtCore.QObject.connect(self.ui.actionAdd_object, QtCore.SIGNAL("triggered()"), self.define_object)
		QtCore.QObject.connect(self.ui.actionClear_objects, QtCore.SIGNAL("triggered()"), self.clear_objects)
		QtCore.QObject.connect(self.ui.actionStart, QtCore.SIGNAL("triggered()"), self.start_tracking)
		QtCore.QObject.connect(self.ui.actionStop, QtCore.SIGNAL("triggered()"), self.stop_tracking)
		QtCore.QObject.connect(self.ui.actionPause, QtCore.SIGNAL("triggered()"), self.pause_tracking)
		QtCore.QObject.connect(self.ui.actionAbout, QtCore.SIGNAL("triggered()"), self.about_dialog)
		QtCore.QObject.connect(self.ui.actionQuit, QtCore.SIGNAL("triggered()"), self.close)
		QtCore.QObject.connect(self.ui.actionSave_profile, QtCore.SIGNAL("triggered()"), self.save_profile)
		QtCore.QObject.connect(self.ui.actionOpen_profile, QtCore.SIGNAL("triggered()"), self.open_profile)

		QtCore.QObject.connect(self.ui.actionShow_advanced_options, QtCore.SIGNAL("triggered()"), self.toggle_advanced_options)
		QtCore.QObject.connect(self.ui.actionShow_camera_options, QtCore.SIGNAL("triggered()"), self.toggle_camera_options)
		
		QtCore.QObject.connect(self.ui.button_browse, QtCore.SIGNAL("clicked()"), self.browse)
		QtCore.QObject.connect(self.ui.button_change_resolution, QtCore.SIGNAL("clicked()"), self.change_resolution)
		QtCore.QObject.connect(self.ui.button_change_camera, QtCore.SIGNAL("clicked()"), self.change_camera)
		
		QtCore.QObject.connect(self.ui.spinbox_smov_threshold, QtCore.SIGNAL("valueChanged(int)"), self.option_changed)
		QtCore.QObject.connect(self.ui.spinbox_emov_threshold, QtCore.SIGNAL("valueChanged(int)"), self.option_changed)		
		QtCore.QObject.connect(self.ui.spinbox_min_z, QtCore.SIGNAL("valueChanged(int)"), self.option_changed)
		QtCore.QObject.connect(self.ui.spinbox_framerate, QtCore.SIGNAL("valueChanged(int)"), self.option_changed)
		QtCore.QObject.connect(self.ui.checkbox_log_samples, QtCore.SIGNAL("stateChanged(int)"), self.option_changed)
		QtCore.QObject.connect(self.ui.checkbox_v3d, QtCore.SIGNAL("stateChanged(int)"), self.option_changed)
		QtCore.QObject.connect(self.ui.checkbox_monitor_tracking, QtCore.SIGNAL("stateChanged(int)"), self.option_changed)						
		QtCore.QObject.connect(self.ui.checkbox_monitor_webcam, QtCore.SIGNAL("stateChanged(int)"), self.option_changed)		
		QtCore.QObject.connect(self.ui.checkbox_control_mouse, QtCore.SIGNAL("stateChanged(int)"), self.option_changed)		
		QtCore.QObject.connect(self.ui.combobox_match_mode, QtCore.SIGNAL("currentIndexChanged(int)"), self.option_changed)
		QtCore.QObject.connect(self.ui.combobox_size_mode, QtCore.SIGNAL("currentIndexChanged(int)"), self.option_changed)
		QtCore.QObject.connect(self.ui.combobox_comm_protocol, QtCore.SIGNAL("currentIndexChanged(int)"), self.option_changed)
		QtCore.QObject.connect(self.ui.edit_host, QtCore.SIGNAL("editingFinished()"), self.option_changed)
		QtCore.QObject.connect(self.ui.spinbox_port, QtCore.SIGNAL("valueChanged(int)"), self.option_changed)

		#self.et.objects.append(etracker.tracker_object("MARKER", (255, 91, 120), 50, self.et))

		self.populate_camera_options()