加特兰Demo点迹数据读取和显示

发布时间:2023年12月18日

? ? ? ? 加特兰当前主推的芯片,拿到了样件做了几个基本Demo测试,录取的点迹数据为txt文档,数据格式如下:

FT =  0.10 CMN1 = 263 CMN2 = 150 BNK 0
--- F 0 O 140/2/140!0/0/0/0/0/0.00! ---
BK
	00: P  25.67, R   4.11, V   0.00, A -39.04, E  -7.04, RCS  25.67, RI 011, VI 000, F 3, C 1.00
	01: P  37.64, R   5.27, V   0.00, A -32.14, E  -7.08, RCS  37.64, RI 013, VI 000, F 3, C 1.00
	02: P  46.10, R   6.13, V -10.33, A  50.44, E   2.99, RCS  46.10, RI 015, VI 438, F 1, C 1.00
	03: P  27.36, R   6.51, V  -6.05, A  45.52, E  -4.39, RCS  27.36, RI 016, VI 469, F 1, C 0.92
	04: P  43.76, R   6.43, V  -9.98, A  51.48, E   2.89, RCS  43.76, RI 016, VI 440, F 1, C 1.00
	05: P  39.81, R   6.46, V  -9.67, A  52.81, E   2.54, RCS  39.81, RI 016, VI 443, F 1, C 0.99

? ? ? ? 这些数据可以通过python或c++读取解析。

1 数据读取和解析

? ? ? ? python可以通过基本的open函数、read函数读取txt文件,设置好文本路径,通过下面函数即可读取所有点迹行的数据和帧数。

# 读取所有点迹数据
def DetectInputData(filename):
    data = []
    frame_count = 0
    file = open(filename,'r')       # 打开文件
    file_data = file.readlines()    # 读取所有行
    for row in file_data:
        if len(row) > 90:
            data.append(row)
        if row == 'BK\n':
            frame_count += 1
    return data, frame_count

????????c++可以通过文件输入流进行读取,主要通过getline()函数,依次读取txt文档的每一行数据,同样可以根据标识信息获取帧数。

// read detect files
void ReadTxtFile(std::ifstream& file_name, std::vector<std::vector<std::string>>& file_array, uint32_t& detect_frame_num)
{
	std::string file_str;
	uint64_t file_row = 0;
	while(getline(file_name, file_str)) {					// get information
		std::string tmp_str;
		std::stringstream file_data(file_str);				// all of the data read into file_data
		std::vector<std::string> file_line;
		if (file_str.size() > 90) {
			while(getline(file_data, tmp_str, ':')) {			
				file_line.push_back(tmp_str);
			}
			file_array.push_back(file_line);			// use "," to separate id and detect information 
			uint32_t test = 0;
		}
		if (file_str == "BK"){
			detect_frame_num++;
		}
		// std::cout << file_str  << " size:" << file_str.size() << std::endl;					// get header
		file_row++;
	}
}

????????再对读取后的数据提取信息,可以根据关键字和","分割符提取。文本中功率为P,距离为R,径向速度为V,方位角度为A,俯仰角度为E,雷达散射截面积为RCS(这里不准确),距离单元索引为RI,速度单元索引为VI,模糊系数为F,点迹概率为C。

00: P  25.67, R   4.11, V   0.00, A -39.04, E  -7.04, RCS  25.67, RI 011, VI 000, F 3, C 1.00

? ? ? ? 这里主要提取前面几个点迹信息,如距离、速度等,由于雷达固定不动,可以通过径向速度门限区分运动点迹和静止点迹,python和c++版本分别如下,两个函数名一样,代表用途一致。

# 提取点迹信息
def GetDetectInfo(data, detects, speed_thres):
    for detect_info in data:
        power = 0
        distance = 0
        vr = 0
        azi = 0
        ele = 0
        for i in range(0, len(detect_info)-1):
            if detect_info[i] == 'P':
                power = GetValueResult(detect_info, i+1)
            if detect_info[i] == 'R' and detect_info[i+1] == ' ':
                distance = GetValueResult(detect_info, i+1)
            if detect_info[i] == 'V' and detect_info[i+1] == ' ':
                vr = GetValueResult(detect_info, i+1)  
            if detect_info[i] == 'A':
                azi = GetValueResult(detect_info, i+1)*DEG2RAD
            if detect_info[i] == 'E':
                ele = GetValueResult(detect_info, i+1)*DEG2RAD
        rcs = 10.0
        snr = power - 10.0
        x = distance*np.cos(ele)*np.cos(azi)
        y = distance*np.cos(ele)*np.sin(azi)
        detects.x.append(x)
        detects.y.append(y)
        detects.speed.append(vr)
        detects.snr.append(snr)
        detects.rcs.append(rcs)
        detects.power.append(power)
        # 用径向速度筛选动静点迹
        if abs(vr) > speed_thres:
            detects.move_x.append(x)
            detects.move_y.append(y)
        else:
            detects.static_x.append(x)
            detects.static_y.append(y)

????????c++版本由于接入目标跟踪框架,无需做动静分离处理。

// get detect info 
void GetDetectInfo(std::vector<std::string>& detect_line , RadarTarget& radar_target)
{
	radar_target.timestamp = 0.0f;
	radar_target.amb_speed = 100.0f;
	RadarPoint tmp_radar = { 0 };
	tmp_radar.id = std::atoi(detect_line[0].c_str());
	std::string detect_info = detect_line[1];
	for (int i = 0; i < detect_info.size() - 1; i++) {
		if (detect_info[i] == 'P') {
			
			tmp_radar.power = GetValueResult(detect_info, i+1);
		}
		if (detect_info[i] == 'R' && detect_info[i+1] == ' ') {
			
			tmp_radar.distance = GetValueResult(detect_info, i+1);
		}
		if (detect_info[i] == 'V' && detect_info[i+1] == ' ') {
			
			tmp_radar.vr = GetValueResult(detect_info, i+1);
		}
		if (detect_info[i] == 'A') {
			
			tmp_radar.azimuth = GetValueResult(detect_info, i+1)*DEG2RAD;
		}
		if (detect_info[i] == 'E') {
			
			tmp_radar.elevation = GetValueResult(detect_info, i+1)*DEG2RAD;
		}
	}

	tmp_radar.rcs = 10.0f;
	tmp_radar.snr = tmp_radar.power - 10.0f;
	tmp_radar.x = tmp_radar.distance * cosf(tmp_radar.elevation) * cosf(tmp_radar.azimuth);
	tmp_radar.y = tmp_radar.distance * cosf(tmp_radar.elevation) * sinf(tmp_radar.azimuth);
	tmp_radar.z = tmp_radar.distance * sinf(tmp_radar.elevation) + OFFSET_Z;
	radar_target.points.push_back(tmp_radar);
}

? ? ? ? 这里都用到了GetValueResult()函数,用来从txt文本中提取数值,两个版本基本一样。

# 获取txt中的数值
def GetValueResult(detect_info, start_pos):
    value = ''
    for i in range(start_pos, start_pos+10):
        if (detect_info[i] == ','):
            break
        if (detect_info[i] != ' '):
            value += detect_info[i]
    result = float(value)
    return result
// 获取txt中的数值
float GetValueResult(std::string& detect_info, int start_pos)
{
	std::string value;
	float result = 0.0f;

	for (int i = start_pos; i < start_pos + 10; i++){
		if (detect_info[i] == ',')
		{
			break;
		}
		if (detect_info[i] != ' ') {
			value += detect_info[i];
		}
	}
	result = (float)std::atof(value.c_str());
	return result;
}

2 数据显示

? ? ? ? 数据读取后,即可调用画图显示,这里仅使用python。可以看到,用蓝色和红色区分运动和静止点迹,运动目标点迹整体波动不大,精度较高,更精细的评估需要真值设备,这里不再讨论。

# 显示点迹
    plt.figure()
    plt.scatter(detects.move_y,detects.move_x,s=10,color="b",label="move detect")
    plt.scatter(detects.static_y,detects.static_x,s=10,color="r",label="static detect")
    plt.legend()
    plt.grid(True)
    plt.title("Calterah Detect Test")
    plt.show()

文章来源:https://blog.csdn.net/weixin_41691854/article/details/135061173
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。