本文整理汇总了Python中emokit.emotiv.Emotiv类的典型用法代码示例。如果您正苦于以下问题:Python Emotiv类的具体用法?Python Emotiv怎么用?Python Emotiv使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Emotiv类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: console_gather
def console_gather() :
os.system('clear')
headset = Emotiv()
gevent.spawn(headset.setup)
gevent.sleep(0)
packets = 0
now = datetime.now()
filename = str(now.time()) + "_" + str(now.date())
while True :
dir = str(input("Choose input: \n 1. up\n 2. down\n 3. left\n 4. right\n 0. neutral\n"))
if dir in ['1','2','3','4','0'] : break
filename += "_" + dir
if TEST : filename = "TEST_" + filename
buffers = []
names = 'AF3 F7 F3 FC5 T7 P7 O1 O2 P8 T8 FC6 F4 F8 AF4'.split(' ')
for name in names :
buffers.append(sensor_buffer(name))
print "Training will start in..."; sleep(1); print "3..."; sleep(1); print "2..."; sleep(1); print "1..."; sleep(1); print "Focus!"
qualities = []
timeout = time() + 12
while True:
if time() > timeout :
break
packet = headset.dequeue()
for buffer in buffers :
buffer.update( packet )
packets += 1
gevent.sleep(0)
headset.close()
quality = 0.
f = open("./data/" + filename,'w')
columns = []
for name in names :
columns.append(str(name))
columns.append('Q' + str(name))
f.write(','.join(columns))
f.write('\n')
while packets > 0 :
for buffer in buffers :
f.write( buffer.pop() )
f.write('\n')
packets -= 1
f.close()
print "Finished reading, saved to file %s" % filename
for buffer in buffers :
print "Sensor %s mean quality: %.2f" % (buffer.name, buffer.mean_quality())
示例2: session
def session() :
headset = Emotiv()
gevent.spawn(headset.setup)
gevent.sleep(0)
labels = ['0', '1', '2', '3', '4']
for label in labels :
os.system('clear')
print "Training for class: ", label
raw_input("Press Enter to start training..." )
class_gather(label, headset)
headset.close()
示例3: epoc_publish_frames
def epoc_publish_frames():
# Setup ROS publisher.
publisher = rospy.Publisher('epoc/frames', EEGFrame)
# Open a connection to the Emotiv EPOC.
headset = Emotiv()
gevent.spawn(headset.setup)
gevent.sleep(1)
# Initialize ROS node+publisher.
rospy.init_node('epoc_publish')
# Start the publishing loop.
rospy.loginfo('Starting publishing loop...')
published_count = 0
try:
while not rospy.is_shutdown():
# Get the next packet from the EPOC.
packet = headset.dequeue()
frame_header = Header(published_count, rospy.Time.now(), '/epoc')
frame_accel_x = packet.sensors['X']['value']
frame_accel_y = packet.sensors['Y']['value']
frame_signals = [
packet.sensors[channel]['value']
for channel in channels]
frame_qualities = [
packet.sensors[channel]['quality']
for channel in channels]
frame = EEGFrame(
frame_header,
frame_accel_x,
frame_accel_y,
14,
channels,
frame_signals,
frame_qualities)
# Publish the the EEG channels and accelerometer values.
publisher.publish(frame)
# Update and print information count.
published_count += 1
print('\rPublished: %d' % published_count, end='')
gevent.sleep(0)
except rospy.ROSInterruptException:
headset.close()
示例4: epoc_publish_channels
def epoc_publish_channels():
# Setup ROS publishers.
signal_publishers = {
channel: rospy.Publisher('epoc/signal/%s' % channel, UInt32)
for channel
in channels}
quality_publishers = {
channel: rospy.Publisher('epoc/quality/%s' % channel, UInt32)
for channel
in channels}
# Open a connection to the Emotiv EPOC.
headset = Emotiv()
gevent.spawn(headset.setup)
gevent.sleep(1)
# Initialize ROS node+publisher.
rospy.init_node('epoc_publish')
# Start the publishing loop.
rospy.loginfo('Starting publishing loop...')
published_count = 0
try:
while not rospy.is_shutdown():
# Get the next packet from the EPOC.
packet = headset.dequeue()
# Publish the the EEG channels and accelerometer values.
for channel in channels:
signal = UInt32(packet.sensors[channel]['value'])
quality = UInt32(packet.sensors[channel]['quality'])
signal_publishers[channel].publish(signal)
quality_publishers[channel].publish(quality)
# Update and print information count.
published_count += 1
print('\rPublished: %d' % published_count, end='')
gevent.sleep(0)
except rospy.ROSInterruptException:
headset.close()
示例5: evt_main
def evt_main():
global is_running
ring_buf = np.zeros(x.size)
ring_buf2 = np.zeros(x.size)
headset = Emotiv()
gevent.spawn(headset.setup)
gevent.sleep(0)
pos = 0
try:
while is_running:
packet = headset.dequeue()
print packet.gyro_x, packet.gyro_y
ring_buf[pos] = packet.sensors["O1"]["value"]
ring_buf2[pos] = packet.sensors["O2"]["value"]
pos = (pos + 1) % ring_buf.size
if pos % 4 == 0:
yield np.concatenate((ring_buf[pos:ring_buf.size:1], ring_buf[0:pos:1])), np.concatenate((ring_buf2[pos:ring_buf.size:1], ring_buf2[0:pos:1]))
gevent.sleep(0)
except KeyboardInterrupt:
headset.close()
finally:
is_running = False
headset.close()
示例6: __init__
def __init__(self, channels, gheight):
"""
Creates pygame window and graph drawing workers for each sensor.
"""
pygame.init()
self.screen = pygame.display.set_mode(resolution)
self.graphers = []
self.record_packets = []
self.fullscreen = False
self.recording = False
self.updated = False
self.middle_x, self.middle_y = resolution[0]/2, resolution[1]/2
for i, name in enumerate(channels):
self.graphers.append(Grapher(self.screen, gheight, name, i))
self.emotiv = Emotiv(display_output=False)
gevent.spawn(self.emotiv.setup)
gevent.sleep(0)
示例7: evt_main
def evt_main():
global is_running
ring_buf = np.zeros(x.size)
headset = Emotiv()
gevent.spawn(headset.setup)
gevent.sleep(0)
pos = 0
try:
while is_running:
packet = headset.dequeue()
yield packet
gevent.sleep(0)
except KeyboardInterrupt:
headset.close()
finally:
is_running = False
headset.close()
示例8: main_process
def main_process(self):
"""
Get realtime EEG data from Emotiv EPOC, process all data (FFT, feature extraction, and classification), and predict the emotion.
Input: -
Output: Class of emotion between 1 to 5 according to Russel's Circumplex Model.
"""
headset = Emotiv()
gevent.spawn(headset.setup)
gevent.sleep(0)
threads = []
eeg_realtime = np.zeros((number_of_channel,number_of_realtime_eeg),dtype=np.double)
counter=0
init=True
try:
#Looping to get realtime EEG data from Emotiv EPOC
while True:
packet = headset.dequeue()
#Get initial EEG data for all channels
if init:
for i in range(number_of_channel):eeg_realtime[i,counter]=packet.sensors[channel_names[i]]['value']
else:
new_data=[packet.sensors[channel_names[i]]['value'] for i in range(number_of_channel)]
eeg_realtime=np.insert(eeg_realtime,number_of_realtime_eeg,new_data,axis=1)
eeg_realtime=np.delete(eeg_realtime,0,axis=1)
#If EEG data have been recorded in ... seconds, then process data to predict emotion
if counter == (sampling_rate-1) or counter == (number_of_realtime_eeg-1):
t = threading.Thread(target=rte.process_all_data, args=(eeg_realtime,))
threads.append(t)
t.start()
init=False
counter=0
gevent.sleep(0)
counter += 1
except KeyboardInterrupt:
headset.close()
finally:
headset.close()
示例9: packets
def packets():
global is_running
ring_buf = np.zeros(x.size)
headset = Emotiv()
gevent.spawn(headset.setup)
gevent.sleep(0)
pos = 0
try:
while is_running:
packet = headset.dequeue()
data = {key: (value["value"], value["quality"])
for (key, value) in packet.sensors.items()}
yield data
gevent.sleep(0)
except KeyboardInterrupt:
headset.close()
finally:
is_running = False
headset.close()
示例10: evt_main
def evt_main(ring_buf):
headset = Emotiv()
gevent.spawn(headset.setup)
gevent.sleep(0)
pos = 0
try:
while True:
packet = headset.dequeue()
print packet.gyro_x, packet.gyro_y
ring_buf[pos] = packet.gyro_x
if pos % 4 == 0:
yield ring_buf
pos = (pos + 1) % 1024
gevent.sleep(0)
except KeyboardInterrupt:
headset.close()
finally:
is_running = False
headset.close()
示例11: evt_main
def evt_main(ring_buf):
global is_running
headset = Emotiv()
gevent.spawn(headset.setup)
gevent.sleep(0)
pos = 0
try:
while is_running:
packet = headset.dequeue()
print packet.gyro_x, packet.gyro_y
ring_buf[pos] = packet.sensors["FC5"]["value"]
if pos % 4 == 0:
yield ring_buf
pos = (pos + 1) % ring_buf.size
gevent.sleep(0)
except KeyboardInterrupt:
headset.close()
finally:
is_running = False
headset.close()
示例12: main
def main():
"""
Creates pygame window and graph drawing workers for each sensor.
"""
global gheight
pygame.init()
screen = pygame.display.set_mode((1280, 800))
graphers = []
recordings = []
recording = False
record_packets = []
updated = False
cursor_x, cursor_y = 400, 300
#for name in 'AF3 F7 F3 FC5 T7 P7 O1 O2 P8 T8 FC6 F4 F8 AF4'.split(' '):
for name in 'AF4 P8 F4 T8 O2'.split(' '):
graphers.append(Grapher(screen, name, len(graphers)))
fullscreen = False
emotiv = Emotiv(display_output=True)
gevent.spawn(emotiv.setup)
gevent.sleep(0)
while emotiv.running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
emotiv.close()
return
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
emotiv.close()
return
elif event.key == pygame.K_f:
if fullscreen:
screen = pygame.display.set_mode((1280, 800))
fullscreen = False
else:
screen = pygame.display.set_mode((1280, 800), FULLSCREEN, 16)
fullscreen = True
elif event.key == pygame.K_r:
if not recording:
record_packets = []
recording = True
else:
recording = False
recordings.append(list(record_packets))
record_packets = None
packets_in_queue = 0
try:
while packets_in_queue < 8:
packet = emotiv.dequeue()
if abs(packet.gyro_x) > 1:
cursor_x = max(0, min(cursor_x, 1280))
cursor_x -= packet.gyro_x
if abs(packet.gyro_y) > 1:
cursor_y += packet.gyro_y
cursor_y = max(0, min(cursor_y, 800))
map(lambda x: x.update(packet), graphers)
if recording:
record_packets.append(packet)
updated = True
packets_in_queue += 1
except Exception, ex:
print ex
if updated:
screen.fill((75, 75, 75))
map(lambda x: x.draw(), graphers)
pygame.draw.rect(screen, (255, 255, 255), (cursor_x - 5, cursor_y - 5, 10, 10), 0)
pygame.display.flip()
updated = False
gevent.sleep(0)
示例13: abs
height = screen.height
cursor_x, cursor_y = width / 2, height / 2
while True:
updated = False
packet = headset.dequeue()
if abs(packet.gyro_x) > 1:
cursor_x -= packet.gyro_x
updated = True
if abs(packet.gyro_y) > 1:
cursor_y += packet.gyro_y
updated = True
cursor_x = max(0, min(cursor_x, width))
cursor_y = max(0, min(cursor_y, height))
if updated:
screen.move_mouse(cursor_x, cursor_y)
gevent.sleep(0)
headset = None
if __name__ == "__main__":
try:
headset = Emotiv()
gevent.spawn(headset.setup)
gevent.sleep(0)
main()
finally:
if headset:
headset.close()
示例14: Emotiv
if(args.nogui):
guifeature = False
sensornames = 'AF3 F7 F3 FC5 T7 P7 O1 O2 P8 T8 FC6 F4 F8 AF4'.split(' ')
if guifeature:
# building the node connection display
pygame.init()
surface = pygame.display.set_mode((640, 480), 0, 32)
pygame.display.set_caption('Emotiv Epoc Callibration Test')
background = pygame.image.load(os.path.join('images','sensormap.png'))
surface.blit(background, (0,0))
pygame.display.flip()
print "Initializing controller..."
emotiv = Emotiv(displayOutput=False)
gevent.spawn(emotiv.setup)
gevent.sleep(1)
print "Controller initialized."
initOSCClient(args.ip, args.port)
print "Starting client."
# run forever
try:
running = True
while running:
if guifeature:
for event in pygame.event.get():
if event.type == QUIT:
示例15: Emotiv
# This is an example of popping a packet from the Emotiv class's packet queue
# and printing the gyro x and y values to the console.
from emokit.emotiv import Emotiv
import gevent
if __name__ == "__main__":
headset = Emotiv()
gevent.spawn(headset.setup)
gevent.sleep(0)
try:
while True:
packet = headset.dequeue()
print packet.gyro_x, packet.gyro_y
gevent.sleep(0)
except KeyboardInterrupt:
headset.close()
finally:
headset.close()