Last active
October 26, 2023 03:26
-
-
Save wi24rd/c58e4522133f402426fde5f0169e0b4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding=GBK | |
| # The code is provided for testing purpose ONLY as a reference solution by @wi24rd NOT a project/product of his employer. | |
| # This code can tell you how to parse Heatmap data from Assure. | |
| # For JAVA SDK, check https://github.com/AeroSenseSw/AeroSenseAssure/blob/main/src/main/java/com/aerosense/radar/tcp/service/fromRadar/ReportHeatMapHandler.java | |
| import numpy as np | |
| import winsound | |
| import os | |
| from matplotlib import pyplot as plt | |
| from matplotlib import cm | |
| from matplotlib import axes | |
| def get_sign8(vx): | |
| if not vx or vx < 0x80: | |
| return vx | |
| return vx - 0x100 | |
| def showHeatMap(map): | |
| mapList = [] | |
| for i in map: | |
| for j in i: | |
| mapList.append(j) | |
| mapLen = len(mapList) | |
| if mapLen % 3 != 0: | |
| print("http数据传输丢包,只显示其中一部分热力图") | |
| xLabel = [] | |
| yLabel = [] | |
| #定义热图的横纵坐标 | |
| for i in range(0, 255): | |
| xLabel.append(i) | |
| yLabel.append(i) | |
| # 初始化 | |
| data = np.zeros((256, 256), dtype=np.cfloat) | |
| total = 0 | |
| for i in range(0, int(mapLen/3)): | |
| idx = i * 3 | |
| x = get_sign8(mapList[idx]) | |
| y = mapList[idx + 1] | |
| n = mapList[idx + 2] | |
| if n != 0: | |
| hotVal = data[x + 128][y] + n * 10 | |
| # 雷达X方向法线为热力图X=128 | |
| data[x + 128][y] = hotVal | |
| total = total + 1 | |
| else: | |
| total = total + y | |
| #print("x:" + str(x) + ",y:" + str(y) + ",n:" + str(n)) | |
| #作图阶段 | |
| fig = plt.figure() | |
| #定义画布为1*1个划分,并在第1个位置上进行作图 | |
| ax = fig.add_subplot(111) | |
| #作图并选择热图的颜色填充风格,这里选择hot | |
| im = ax.imshow(data, interpolation='nearest', cmap=plt.cm.hot_r, vmin=0, vmax=1000) | |
| #增加右侧的颜色刻度条 | |
| plt.xlim(0, 256) | |
| plt.xlabel("x") | |
| plt.ylabel("y") | |
| plt.gca().invert_yaxis() | |
| plt.colorbar(im) | |
| #增加标题 | |
| plt.title("HeatMap") | |
| plt.show() | |
| gHeatMapData = [] | |
| def readFromFile(dirName): | |
| global gHeatMapData | |
| fileDirList = os.listdir(dirName) | |
| for i in fileDirList: | |
| f_hangle = open(dirName+'/'+i,"rb") | |
| data = f_hangle.read() | |
| print(data) | |
| if len(data) < 23: | |
| gHeatMapData = [] | |
| return "OK" | |
| strData = bytes.decode(data[0:23]) | |
| func = strData[0:7] | |
| #如果是HeatMap | |
| if func == "HeatMap": | |
| finished = strData[21] | |
| if finished == "1": | |
| gHeatMapData.append(data[23:]) | |
| elif finished == "0": | |
| gHeatMapData.append(data[23:]) | |
| # 结束一张图 | |
| showHeatMap(gHeatMapData) | |
| gHeatMapData = [] | |
| if __name__ == "__main__": | |
| readFromFile("./heatMap/") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment