-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrealtime_samples.py
66 lines (57 loc) · 1.99 KB
/
realtime_samples.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import numpy as np
import ctypes
import config
import matplotlib.pyplot as plt
import phase_shift_algorithm_real_data
import cv2
import time
def get_antenna_data():
lib = ctypes.cdll.LoadLibrary("../lib/libsampler.so")
init = lib.load
init.restype = int
get_data = lib.myread
get_data.restype = None
get_data.argtypes = [
ctypes.POINTER(ctypes.c_float)
]
init()
return get_data
def get_samples():
f = get_antenna_data()
out = np.empty(config.BUFFER_LENGTH, dtype=np.float32)
out_pointer = out.ctypes.data_as(
ctypes.POINTER(ctypes.c_float))
#max_vals = np.array([])
times = np.array([])
i = 0
while(True):
start = time.time()
f(out_pointer)
signals = out.reshape((config.N_SAMPLES, config.N_MICROPHONES))
signals = signals[:,0:config.ROWS*config.COLUMNS] # Use when only having one array, comment out otherwise
#print(np.shape(signals))
heatmap_data = phase_shift_algorithm_real_data.main(signals)
#print(heatmap_data, heatmap_data.dtype, heatmap_data.shape)
#indxs = np.unravel_index(np.argmax(heatmap_data), np.shape(heatmap_data))
#max_val = heatmap_data[indxs[0],indxs[1]]
#heatmap_data /= max_val # normalizing with maximum value
heatmap_data /= 34000
heatmap_data *= 255
try:
img = cv2.resize(heatmap_data, (960,540))
img2 = img.astype('uint8')
img2 = cv2.flip(img2, 1)
img2 = cv2.applyColorMap(img2, cv2.COLORMAP_OCEAN)
cv2.imshow('heatmap', img2)
cv2.waitKey(int(30/30))
except AttributeError:
pass
end = time.time()
if i > 3:
sim_time = round((end - start), 4) # single loop simulation time
#print('Individual loop time:', sim_time, 's')
times = np.append(times, sim_time)
print('Avg simulation time:', round(np.sum(times)/(i-3), 4), 's')
i += 1
get_samples()
exit()