import numpy as np
import smpy.utils as smpy_utils
import ditu.topbind as tb
from scipy.spatial.transform import Rotation as R
import o3d_hdmap.open3d as o3d
geojson_path = '/data/mpcv_lspo_download_data/prod/PLEF35196-2021-11-10-17-48-39/mapping_results/ground_pole_geojson_LC.json'
geojson_data = smpy_utils.read_json(geojson_path)
anchor_lla_ = tb.utils.ecef2lla( np.array(geojson_data['extrinsics'][0]['center']))
lla = [111.64994725780178,30.73907846113732,131.25631082151085]
enu = tb.utils.lla2enu_cheap([lla], anchor_lla=anchor_lla_)
print(enu)
[[ 966.10732692 -5813.22954404 -59.09057418]]
上述方法操作简单,但是lla2enu_cheap函数存在损失,导致结果不够准确。需要无损的lla2enu转换,则使用如下方法进行
坐标转换:通过旋转矩阵乘以(lla2ecef - 锚点(ecef))的方式,将lla转换成enu坐标
import numpy as np
import smpy.utils as smpy_utils
import ditu.topbind as tb
from scipy.spatial.transform import Rotation as R
import o3d_hdmap.open3d as o3d
geojson_path = '/data/mpcv_lspo_download_data/prod/PLEF35196-2021-11-10-17-48-39/mapping_results/ground_pole_geojson_LC.json'
geojson_data = smpy_utils.read_json(geojson_path)
Q_w = geojson_data['extrinsics'][0]['Rwc_quat_wxyz']
w,x,y,z = Q_w[0],Q_w[1],Q_w[2],Q_w[3]
Q_w = [x,y,z,w]
r = R.from_quat(Q_w)
Q_w = r.as_matrix()
Q_w_inv = np.linalg.inv(Q_w)
t_w = np.array(geojson_data['extrinsics'][0]['center'])
output_dir = 'output_grid_size_2m_deltas_1m'
geojson_points_enu = []
for feature in geojson_data['features']:
if feature['properties']['type'] == 'road_surface':
for coord in feature['geometry']['coordinates']:
t_l = np.array(tb.utils.lla2ecef(coord))
w_t_l = Q_w_inv @ (t_l-t_w)
geojson_points_enu.append(w_t_l)
geojson_points_enu = np.array(geojson_points_enu)
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(geojson_points_enu)
colors = np.zeros(geojson_points_enu.shape)
colors[:, 1] = 1
pcd.colors = o3d.utility.Vector3dVector(colors)
path = f'{output_dir}/origin_geojson_all_points.pcd'
o3d.io.write_point_cloud(path, pcd)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)