-
Notifications
You must be signed in to change notification settings - Fork 1
/
instream_collector.py
46 lines (36 loc) · 1.04 KB
/
instream_collector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
import threading
import socket
import argparse
import math
import time
import cv2
import numpy as np
from pylsl import StreamInlet, resolve_stream
WC_WIDTH = 640
WC_HEIGHT = 480
WC_CHNS = 3
# find stream
print("Resolving streams...")
stream_names = ['Muse', 'Webcam', 'HRV']
stream_inlets = []
# create stream inlets
print("Creating stream inlets")
for name in stream_names:
stream = resolve_stream('name', name))
stream_inlets.append(StreamInlet(stream[0]))
cv2.namedWindow("preview")
while True:
# retreive new sample
sample_muse, timestamp_muse = inlet_muse.pull_sample()
# sample_hrv, timestamp_hrv = inlet_hrv.pull_sample()
sample_webcam, timestamp_webcam = inlet_webcam.pull_sample()
print("Sample muse", timestamp_muse, sample_muse)
# print("Sample hrv", timestamp_hrv, sample_hrv)
frame = np.reshape(sample_webcam, (WC_HEIGHT, WC_WIDTH, WC_CHNS)).astype(np.uint8)
print(frame)
cv2.imshow("preview", frame)
key = cv2.waitKey(20)
if key == 27:
break
cv2.destroyWindow("preview")