RS2002 commited on
Commit
ee32bf3
·
verified ·
1 Parent(s): 39ff146

Upload 8 files

Browse files
data/csi_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:91454a2af39d397357330afabffd1b1ba5d59fabfa23c10bde8daa40448eccbd
3
+ size 16281304
data/processed_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:20b8c44e02a8231803cf4f2088d1fddda85d4848defa96607da7786bb3e4dcf6
3
+ size 59596932
data_process_example/README.md ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # How to Run
2
+
3
+ You can run the code `process_csi1.py`, `process_csi2.py`, `process_csi2_magnitude_linear_inter.py`, `process_cv.py`, `combine_csi_cv.py` in order.
data_process_example/combine_csi_cv.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle
2
+ import numpy as np
3
+
4
+ with open("./data_sequence.pkl", 'rb') as f:
5
+ # with open("./data_sequence_linear.pkl", 'rb') as f:
6
+ data_csi = pickle.load(f)
7
+ with open("./gt_data.pkl", 'rb') as f:
8
+ data_cv = pickle.load(f)
9
+
10
+ data = []
11
+ pad = -1000
12
+ for k in range(len(data_csi)):
13
+ csi = data_csi[k]
14
+ cv = data_cv[k]
15
+
16
+ x = cv['x']
17
+ y = cv['y']
18
+ img_path = np.array(cv['img_path'])
19
+ time_cv = cv['timestamp']
20
+ print(cv['people_name'])
21
+
22
+ indices = np.argsort(time_cv)
23
+ x = x[indices]
24
+ y = y[indices]
25
+ img_path = img_path[indices]
26
+ time_cv = time_cv[indices]
27
+
28
+ print(x)
29
+ print(y)
30
+
31
+
32
+ csi_time = csi['global_time']
33
+ local_time = csi['time']
34
+ magnitude = csi['magnitude']
35
+ phase = csi['phase']
36
+ people = csi['people']
37
+
38
+ indices = np.argsort(csi_time)
39
+ local_time = local_time[indices]
40
+ magnitude = magnitude[indices]
41
+ csi_time = csi_time[indices]
42
+ phase = phase[indices]
43
+
44
+
45
+
46
+ x_list = []
47
+ y_list = []
48
+ path_list = []
49
+
50
+ i = 0
51
+ j = 0
52
+
53
+ print(csi_time)
54
+ print(time_cv)
55
+
56
+
57
+ while csi_time[i] < time_cv[j]:
58
+ i += 1
59
+ x_list.append(pad)
60
+ y_list.append(pad)
61
+ path_list.append(pad)
62
+
63
+
64
+ # print(len(csi_time))
65
+ # print(len(time_cv))
66
+ while i < len(csi_time):
67
+ while csi_time[i] > time_cv[j]:
68
+ j += 1
69
+ if j >= len(time_cv):
70
+ break
71
+ if j >= len(time_cv):
72
+ break
73
+ x_list.append(x[j])
74
+ y_list.append(y[j])
75
+ path_list.append(img_path[j])
76
+ i += 1
77
+
78
+ print(len(x_list))
79
+
80
+
81
+ if len(x_list) < len(csi_time):
82
+ num = len(csi_time) - len(x_list)
83
+ x_list = x_list + [pad] * num
84
+ y_list = y_list + [pad] * num
85
+ path_list = path_list + [pad] * num
86
+
87
+ data.append({
88
+ 'magnitude': magnitude,
89
+ 'phase': phase,
90
+ 'x': x_list,
91
+ 'y': y_list,
92
+ 'img_path': path_list,
93
+ 'time': local_time,
94
+ 'people': people
95
+ })
96
+ print(people)
97
+ print(len(magnitude),len(phase),len(x_list),len(y_list),len(path_list),len(local_time))
98
+
99
+ output_file = './wiloc.pkl'
100
+ # output_file = './wiloc_linear.pkl'
101
+ with open(output_file, 'wb') as f:
102
+ pickle.dump(data, f)
data_process_example/process_csi1.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pickle
3
+ import os
4
+ import pandas as pd
5
+
6
+ # root="./csi"
7
+ root="/home/chentingwei/LoFi/csi_csv"
8
+
9
+
10
+ data=[]
11
+ csi_vaid_subcarrier_index = range(0, 52)
12
+
13
+ def handle_complex_data(x, valid_indices):
14
+ real_parts = []
15
+ imag_parts = []
16
+ for i in valid_indices:
17
+ real_parts.append(x[i * 2])
18
+ imag_parts.append(x[i * 2 - 1])
19
+ return np.array(real_parts) + 1j * np.array(imag_parts)
20
+
21
+ people_id=0
22
+ for people in os.listdir(root):
23
+ print(people)
24
+ path=os.path.join(root,people)
25
+
26
+ for file in os.listdir(path):
27
+ if file[-3:] != "csv":
28
+ continue
29
+ # print(file)
30
+ df = pd.read_csv(os.path.join(path,file))
31
+ df.dropna(inplace=True)
32
+ df['data'] = df['data'].apply(lambda x: eval(x))
33
+ complex_data = df['data'].apply(lambda x: handle_complex_data(x, csi_vaid_subcarrier_index))
34
+ magnitude = complex_data.apply(lambda x: np.abs(x))
35
+ phase = complex_data.apply(lambda x: np.angle(x, deg=True))
36
+ time = np.array(df['timestamp'])
37
+ local_time = np.array(df['local_timestamp'])
38
+
39
+ data.append({
40
+ 'csi_time':time,
41
+ 'csi_local_time':local_time,
42
+ 'people_name': people,
43
+ 'people': people_id,
44
+ 'magnitude': np.array([np.array(a) for a in magnitude]),
45
+ 'phase': np.array([np.array(a) for a in phase]),
46
+ 'CSI': np.array([np.array(a) for a in complex_data])
47
+ })
48
+ people_id+=1
49
+
50
+
51
+ output_file = './csi_data.pkl'
52
+ with open(output_file, 'wb') as f:
53
+ pickle.dump(data, f)
data_process_example/process_csi2.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pickle
3
+
4
+
5
+ result=[]
6
+ pad=[-1000]*52
7
+ loacl_gap=10000
8
+
9
+ def process_time(timestamp):
10
+ t = timestamp.split()
11
+ # print(t)
12
+ t = t[-1].split(":")
13
+ h = float(t[0])
14
+ m = float(t[1])
15
+ t = t[-1].split(".")
16
+ s = float(t[0])
17
+ ms = float(t[1])
18
+ # print(h,m,s,ms)
19
+ return h * 60 * 60 * 100 + m * 60 * 100 + s * 100 + ms
20
+
21
+
22
+ with open("./csi_data.pkl", 'rb') as f:
23
+ csi = pickle.load(f)
24
+
25
+ for data in csi:
26
+ csi_time=data['csi_time']
27
+ local_time=data['csi_local_time']
28
+ magnitude=data['magnitude']
29
+ phase=data['phase']
30
+ people=data['people']
31
+
32
+ last_local=None
33
+ last_glob=None
34
+ current_magnitude=[]
35
+ current_phase=[]
36
+ current_timestamp=[]
37
+ global_timestamp=[]
38
+ for i in range(len(csi_time)):
39
+ if last_local is None:
40
+ last_local=local_time[i]
41
+ last_glob=process_time(csi_time[i])
42
+ current_magnitude.append(magnitude[i])
43
+ current_phase.append(phase[i])
44
+ current_timestamp.append(local_time[i])
45
+ else:
46
+ local = local_time[i]
47
+ glob = process_time(csi_time[i])
48
+ num=round((local-last_local-loacl_gap)/loacl_gap)
49
+ if num>0:
50
+ delta=(local-last_local)/(num+1)
51
+ delta_glob=(glob-last_glob)/(num+1)
52
+ for j in range(num):
53
+ current_magnitude.append(pad)
54
+ current_phase.append(pad)
55
+ current_timestamp.append(current_timestamp[-1] + delta)
56
+ global_timestamp.append(global_timestamp[-1]+delta_glob)
57
+ current_magnitude.append(magnitude[i])
58
+ current_phase.append(phase[i])
59
+ current_timestamp.append(local)
60
+ global_timestamp.append(glob)
61
+ last_local = local
62
+ last_glob = glob
63
+
64
+ print(len(current_magnitude))
65
+ # print(np.max(global_timestamp))
66
+ result.append({
67
+ 'time': np.array(current_timestamp),
68
+ 'global_time': np.array(global_timestamp),
69
+ 'people': people,
70
+ 'magnitude': np.array(current_magnitude),
71
+ 'phase': np.array(current_phase)
72
+ })
73
+
74
+ output_file = './data_sequence.pkl'
75
+ with open(output_file, 'wb') as f:
76
+ pickle.dump(result, f)
data_process_example/process_csi2_magnitude_linear_inter.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pickle
3
+ import pandas as pd
4
+
5
+
6
+ result=[]
7
+ pad=[-1000]*52
8
+ loacl_gap=10000
9
+
10
+ def process_time(timestamp):
11
+ t = timestamp.split()
12
+ t = t[-1].split(":")
13
+ h = float(t[0])
14
+ m = float(t[1])
15
+ t = t[-1].split(".")
16
+ s = float(t[0])
17
+ ms = float(t[1])
18
+ return h * 60 * 60 * 100 + m * 60 * 100 + s * 100 + ms
19
+
20
+ def interpolate_data(original_data):
21
+ data_interpolate = np.copy(original_data)
22
+
23
+ # 对数据进行插值处理
24
+ for j in range(original_data.shape[1]):
25
+ series = pd.Series(original_data[:, j])
26
+ series.interpolate(method='linear', inplace=True)
27
+ data_interpolate[:, j] = series.values
28
+
29
+ return data_interpolate
30
+
31
+
32
+ with open("./csi_data.pkl", 'rb') as f:
33
+ csi = pickle.load(f)
34
+
35
+ for data in csi:
36
+ csi_time=data['csi_time']
37
+ local_time=data['csi_local_time']
38
+ magnitude=data['magnitude']
39
+ phase=data['phase']
40
+ people=data['people']
41
+
42
+ last_local=None
43
+ last_glob=None
44
+ current_magnitude=[]
45
+ current_phase=[]
46
+ current_timestamp=[]
47
+ global_timestamp=[]
48
+ for i in range(len(csi_time)):
49
+ if last_local is None:
50
+ last_local=local_time[i]
51
+ last_glob=process_time(csi_time[i])
52
+ current_magnitude.append(magnitude[i])
53
+ current_phase.append(phase[i])
54
+ current_timestamp.append(local_time[i])
55
+ else:
56
+ local = local_time[i]
57
+ glob = process_time(csi_time[i])
58
+ num=round((local-last_local-loacl_gap)/loacl_gap)
59
+ if num>0:
60
+ delta=(local-last_local)/(num+1)
61
+ delta_glob=(glob-last_glob)/(num+1)
62
+ for j in range(num):
63
+ current_magnitude.append(pad)
64
+ current_phase.append(pad)
65
+ current_timestamp.append(current_timestamp[-1] + delta)
66
+ global_timestamp.append(global_timestamp[-1]+delta_glob)
67
+ current_magnitude.append(magnitude[i])
68
+ current_phase.append(phase[i])
69
+ current_timestamp.append(local)
70
+ global_timestamp.append(glob)
71
+ last_local = local
72
+ last_glob = glob
73
+
74
+
75
+ current_magnitude = np.array(current_magnitude)
76
+ current_magnitude[current_magnitude == -1000] = np.nan
77
+ current_magnitude = interpolate_data(current_magnitude)
78
+ print(len(current_magnitude))
79
+
80
+
81
+ result.append({
82
+ 'time': np.array(current_timestamp),
83
+ 'global_time': np.array(global_timestamp),
84
+ 'people': people,
85
+ 'magnitude': current_magnitude,
86
+ 'phase': np.array(current_phase)
87
+ })
88
+
89
+ output_file = './data_sequence_linear.pkl'
90
+ with open(output_file, 'wb') as f:
91
+ pickle.dump(result, f)
data_process_example/process_cv.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import tqdm
3
+ import cv2
4
+ import numpy as np
5
+ import pickle
6
+
7
+ # root="./cv"
8
+ root="/home/chentingwei/LoFi/lofi"
9
+
10
+
11
+ # 加载 YOLO 模型
12
+ net = cv2.dnn.readNet("./model/yolov3.weights", "./model/yolov3.cfg")
13
+ # 获取输出层的名称
14
+ layer_names = net.getLayerNames()
15
+ output_layers = [layer_names[i - 1] for i in net.getUnconnectedOutLayers()]
16
+
17
+ src_points = np.array([[0, 0], [180, 0], [0, 480], [180, 480]], dtype="float32") # real world
18
+ dst_points = np.array([[222, 210], [374, 209], [65, 458], [495, 451]], dtype="float32") # image world
19
+
20
+
21
+ M = cv2.getPerspectiveTransform(src_points, dst_points)
22
+
23
+ data=[]
24
+
25
+ def get_gt(img_path,net):
26
+ image = cv2.imread(img_path)
27
+ # 加载图像
28
+ height, width, channels = image.shape
29
+
30
+ # 准备输入图像
31
+ blob = cv2.dnn.blobFromImage(image, 0.00392, (416, 416), (0, 0, 0), True, crop=False)
32
+ net.setInput(blob)
33
+ outs = net.forward(output_layers)
34
+
35
+ # 解析 YOLO 输出,找到人体边界框
36
+ class_ids = []
37
+ confidences = []
38
+ boxes = []
39
+
40
+ for out in outs:
41
+ for detection in out:
42
+ scores = detection[5:]
43
+ class_id = np.argmax(scores)
44
+ confidence = scores[class_id]
45
+ if confidence > 0.5: # 置信度阈值
46
+ center_x = int(detection[0] * width)
47
+ center_y = int(detection[1] * height)
48
+ w = int(detection[2] * width)
49
+ h = int(detection[3] * height)
50
+ x = int(center_x - w / 2)
51
+ y = int(center_y - h / 2)
52
+ boxes.append([x, y, w, h])
53
+ confidences.append(float(confidence))
54
+ class_ids.append(class_id)
55
+
56
+ # 如果检测到了多个框,只保留置信度最高的那个框
57
+ if len(boxes) > 0:
58
+ max_confidence_idx = np.argmax(confidences)
59
+ boxes = [boxes[max_confidence_idx]]
60
+ x, y, w, h = boxes[0]
61
+ foot_position_image = (x + w // 2, y + h)
62
+
63
+ person_img_coords = np.array([[foot_position_image[0], foot_position_image[1]]],
64
+ dtype="float32")
65
+ actual_coords = cv2.perspectiveTransform(np.array([person_img_coords]), np.linalg.inv(M))
66
+ return actual_coords[0,0,0],actual_coords[0,0,1]
67
+
68
+
69
+ people_id=0
70
+ for people in os.listdir(root):
71
+ print(people)
72
+ path=os.path.join(root,people)
73
+
74
+ pbar = tqdm.tqdm(os.listdir(path))
75
+
76
+ x_list = []
77
+ y_list = []
78
+ img_path_list = []
79
+ time_list = []
80
+
81
+ for pic in pbar:
82
+ if "color" not in pic:
83
+ continue
84
+
85
+ # print(pic)
86
+ timestamp = pic.split("_")
87
+ timestamp = timestamp[-1].split(".")
88
+ timestamp = timestamp[0]
89
+ timestamp = timestamp.split("-")
90
+ # print(timestamp)
91
+ timestamp = float(timestamp[0]) * 60 * 60 * 100 + float(timestamp[1]) * 60 * 100 + float(timestamp[2]) * 100 + float(timestamp[3])
92
+
93
+ img_path = os.path.join(path, pic)
94
+ x, y = get_gt(img_path, net)
95
+ x_list.append(x)
96
+ y_list.append(y)
97
+ img_path_list.append(img_path)
98
+ time_list.append(timestamp)
99
+
100
+ data.append({
101
+ 'timestamp': np.array(time_list),
102
+ 'people_name': people,
103
+ 'people': people_id,
104
+ 'x': np.array(x_list),
105
+ 'y': np.array(y_list),
106
+ 'img_path': img_path_list
107
+ })
108
+ people_id += 1
109
+
110
+ output_file = './gt_data.pkl'
111
+ with open(output_file, 'wb') as f:
112
+ pickle.dump(data, f)