Go2Py_SIM/examples/miscellaneous/calibration_post_processing...

803 lines
109 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Calibration Postprocessing"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Kalibr (D455 to Body IMU)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"from Go2Py.calibration import *\n",
"import numpy as np\n",
"np.set_printoptions(formatter={'float': lambda x: \"{0:0.6f}\".format(x)})"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"ext_params = [KalibrExtractExtrinsics(f'datasets/calibration/calibration/kalibr/dynamic/all/seq{i+1}.yaml') for i in range(5)]\n",
"int_params = KalibrExtractIntrinsics(f'datasets/calibration/calibration/kalibr/dynamic/all/seq{1}.yaml')"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"def computeSE3Mean(poses):\n",
" T0 = poses[0]\n",
" log_delta_Ts = []\n",
" for T in poses:\n",
" log_delta_Ts.append(pin.log6(np.linalg.inv(T0)@T).vector)\n",
" log_delta_Ts = np.vstack(log_delta_Ts)\n",
" return T0@pin.exp6(np.mean(log_delta_Ts, axis=0)).homogeneous\n",
"\n",
"\n",
"ext_result = {}\n",
"int_result = {}\n",
"camera_name_map = {'cam0':'infra1',\n",
" 'cam1':'infra2',\n",
" 'cam2':'color'}\n",
"for cam in ['cam0', 'cam1', 'cam2']:\n",
" poses = [r[f'{cam}_T_imu'] for r in ext_params]\n",
" ext_result[f'{camera_name_map[cam]}_T_imu']=computeSE3Mean(poses)\n",
" int_result[camera_name_map[cam]]=int_params[cam]"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'infra1': {'camera_model': 'pinhole',\n",
" 'intrinsics': {'fu': 398.0379492735872,\n",
" 'fv': 401.10555839769535,\n",
" 'pu': 327.56389668833106,\n",
" 'pv': 244.66328819850395},\n",
" 'distortion_model': 'radtan',\n",
" 'distortion_coeffs': {'k1': 0.022437463738179255,\n",
" 'k2': -0.006800545399861931,\n",
" 'r1': 0.0007861230173005672,\n",
" 'r2': 0.0031405110415967147},\n",
" 'resolution': [640, 480]},\n",
" 'infra2': {'camera_model': 'pinhole',\n",
" 'intrinsics': {'fu': 398.170676888213,\n",
" 'fv': 401.14236478722404,\n",
" 'pu': 324.30936661646456,\n",
" 'pv': 244.30665138733275},\n",
" 'distortion_model': 'radtan',\n",
" 'distortion_coeffs': {'k1': 0.021509683195673927,\n",
" 'k2': -0.005685185848086602,\n",
" 'r1': 0.0005912786969070088,\n",
" 'r2': 0.0015930212849673176},\n",
" 'resolution': [640, 480]},\n",
" 'color': {'camera_model': 'pinhole',\n",
" 'intrinsics': {'fu': 389.87107372397037,\n",
" 'fv': 392.45741669539916,\n",
" 'pu': 323.75335233916996,\n",
" 'pv': 244.24311882848974},\n",
" 'distortion_model': 'radtan',\n",
" 'distortion_coeffs': {'k1': -0.03133853627816805,\n",
" 'k2': 0.04281860405665049,\n",
" 'r1': 0.00042180931009971407,\n",
" 'r2': 0.0024263659102242005},\n",
" 'resolution': [640, 480]}}"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"int_result"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'infra1_T_imu': array([[-0.046, -0.999, 0.017, 0.054],\n",
" [-0.092, -0.013, -0.996, 0.067],\n",
" [0.995, -0.047, -0.092, -0.343],\n",
" [0.000, 0.000, 0.000, 1.000]]),\n",
" 'infra2_T_imu': array([[-0.040, -0.999, 0.017, -0.043],\n",
" [-0.091, -0.013, -0.996, 0.066],\n",
" [0.995, -0.041, -0.091, -0.344],\n",
" [0.000, 0.000, 0.000, 1.000]]),\n",
" 'color_T_imu': array([[-0.039, -0.999, 0.014, -0.007],\n",
" [-0.091, -0.010, -0.996, 0.066],\n",
" [0.995, -0.040, -0.090, -0.344],\n",
" [0.000, 0.000, 0.000, 1.000]])}"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ext_result"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Vicon2Gt"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[-0.887, 0.452, 0.097, 0.051],\n",
" [-0.454, -0.891, -0.002, 0.006],\n",
" [0.086, -0.046, 0.995, 0.017],\n",
" [0.000, 0.000, 0.000, 1.000]])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"imu_T_marker = Vicon2GtExtractParams('datasets/calibration/calibration/vicon2gt/seq1/seq1_vicon2gt_info.txt')\n",
"imu_T_marker"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Kinematics-Vicon"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"import pickle\n",
"with open('datasets/calibration/calibration/kinematic-vicon-dataset/inplace_rotation.pkl', 'rb') as f:\n",
" data = pickle.load(f)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"from Go2Py.sim.mujoco import Go2Sim\n",
"robot = Go2Sim(dt=0.001)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"import time\n",
"import numpy as np\n",
"mjworld_Ts_base = []\n",
"vworld_Ts_marker = []\n",
"Kp = 200\n",
"Kv = 5.0\n",
"robot.standUpReset()\n",
"for i in range(len(data['q'])):\n",
" state = robot.getJointStates()\n",
" tau = Kp*np.eye(12)@(data['q'][i] - state['q']).reshape(12,1)+data['tau'][i].reshape(12,1) + \\\n",
" Kv*np.eye(12)@(data['dq'][i] - state['dq']).reshape(12,1)\n",
" robot.setCommands(np.zeros(12), np.zeros(12), np.zeros(12), np.zeros(12), tau)\n",
"\n",
" t, q = robot.getPose()\n",
" R = pin.Quaternion(np.hstack([q[1:], q[0]])).matrix()\n",
" mjworld_T_base=np.vstack([np.hstack([R, t.reshape(3,1)]), np.array([0,0,0,1])])\n",
" vworld_T_marker = data['world_T_marker'][i]\n",
" mjworld_Ts_base.append(mjworld_T_base.reshape(1,4,4))\n",
" vworld_Ts_marker.append(vworld_T_marker.reshape(1,4,4))\n",
" robot.step()\n"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"mjworld_Ts_base = np.vstack(mjworld_Ts_base[:-3000])\n",
"vworld_Ts_marker = np.vstack(vworld_Ts_marker[:-3000])"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f816c43a4f0>,\n",
" <matplotlib.lines.Line2D at 0x7f816c43a550>,\n",
" <matplotlib.lines.Line2D at 0x7f816c43a670>]"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD4CAYAAADvsV2wAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAABDVklEQVR4nO3deXwU9f348ddnr9x3QggkkHDKfaOCCKgIeIL1aL2vr9XW1trT1l+tra3a1qtWbWu9a60HKqKCCIoiIjdyH0kgXElIQkLuZK/P74/PbhLIhpwkkH0/H488dnZmduYzm9n3fOZzjdJaI4QQovuzdHUChBBCdA4J+EIIESQk4AshRJCQgC+EEEFCAr4QQgQJW1cnoCmJiYk6PT29q5MhhBCnlfXr1xdprZMCLTtlA356ejrr1q3r6mQIIcRpRSm1r6llUqQjhBBBQgK+EEIECQn4QggRJCTgCyFEkJCAL4QQQUICvhBCBAkJ+EIIESRO2Xb4pyqX18WBsgNYLVYcFgd2q50wWxgR9ogmP5Nb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c8NcfXs/Woq1sPbKVsT3GNlqeGmmKUgqqChotq/XUAhBuD2+0LDokGoBSZykAB8oO8E7mOxRWFdbV9gPMencWaVFpOD1Oyp3lFFSb/aRHp3PD0BuwKAvPbHyGx9Y9xvKDy3F5XVS5qthVsguLsrSpuMJfbLW/bH+jZV8c+AIwlc5tdV7aeTz37XNct/A6EkITOFJz5JjlIxJHtKlyt7VSI1MprS096fs5Hbi8LnYe2UmkIxKNxu114/F68GgPr21/jZiQmBYHv1PF+OTxvJf
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"plt.plot(vworld_Ts_marker[:,0:3,-1])"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f8169306220>,\n",
" <matplotlib.lines.Line2D at 0x7f8169306280>,\n",
" <matplotlib.lines.Line2D at 0x7f81693063a0>]"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAD5CAYAAAAqaDI/AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAABTlUlEQVR4nO2dd3icxdW377Or1ap3WbIl2XLvxkW4UEwzvRhCCSQEAgRIAiEJCXlJg8SBfCRAKAkETA8JmA6mGkwxGNzk3nCTiyTL6r1ume+P2ZVX0qqvJcs793Xtpd152jy7j+Y3c86ZM6KUwmAwGAzBi6W/K2AwGAyG/sUIgcFgMAQ5RggMBoMhyDFCYDAYDEGOEQKDwWAIcowQGAwGQ5ATEoiTiMg5wCOAFXhaKXVfq+0/Bm4BXEANcJNSapuIZALbgR2eXVcqpX7c2fWSkpJUZmZmIKpuMBgM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72JXxS5WHFyBUzlxKzdnDD2juQcvIlwz8RpGxY8iRELYVLKJL/O+5I1db/g148bZ45iSPAXQQp4Wlcam4k08ufFJFIoTh5zI4KjB1DTV4HA7cLqdfLz/4+ZjH5/3OMNihvHB3g/IPpRN9qFs/rn+n6wrWgeAVay4lKvd7yLUEtps2uoOpfWl7ZqFAEKtoQA0uZsIt4R3+/y9JaiEICwkDIAl+5dwTuY5ATuvd0TQ2lkcEaKHxf6EoMndhNPtbBaLFvW06nq2JwRv7HqDisYKntr8FKAfXrvVTp2zjv3V+7nnxHu45dNbUEpxwYgL2FC0gesnXc8PJvwAgFUFq3h799sA/HH2H/m27Fte2/kayeHJ3Dr1VtYVraOmqYbZg2c
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.plot(mjworld_Ts_base[:,0:3,-1])"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"from SimpleHandEye.solvers import OpenCVSolver"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"solver = OpenCVSolver()"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"A = mjworld_Ts_base\n",
"B = vworld_Ts_marker\n",
"X , Y = solver.solve(A = A, B = B)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f815c364850>,\n",
" <matplotlib.lines.Line2D at 0x7f815c364880>,\n",
" <matplotlib.lines.Line2D at 0x7f815c3649a0>]"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGli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fvvJ20FgtpLdFR4DdhIAxYSR8zSp9l5SZh2NCkj/B6MNUc7tR5amn8fDUWFJQMF63+VrSxGUw/6jQqdm+lclcJfncrYSKEhIY5wclPr7ydLEcW3x33XS4acxH3em8i0uLB4Yasmkay3mkDVgDQao6gqAKDKkhRzaRPGbP3tbMnjqduoe5HcdfDb6Ki4g/7sRltGJWuJSp32Gi2s56SkjW9FvQNr7+Fs0FFbajmg9cf49zLbu31e9TYVA1AenJ2zPOJjmQ0NIKhwct+MuQEPdLiIa/GxsKnHqFy6jrSXBlowTChsnocI/OYXnw044r7l+zR2hJB5HZe8DBpBiJdvFORYAh/cuyTWrINUdv/D/eh//2S6qWriYRDXPTrPzOxYFqnMhWLvsEGnPvzeyhZs5RjvvO9zhUBBdkjufGHf9373G9VMdU2xiy7c9s6ACZMPhqTwcRF59zEvz9cjCnJyfgxswBQhLLXzGE3Ozh56j6zxvTpJ7Lj8TeoLNses/7G3buxAj+6+R+dzo3KGgcnxLxsL4XDxvLTl94hEg5Rva2Eii0b0TSNcDBI0Oth1rkX6u1KTQaa8LQ040zubBKT7GPh6nexhBQmXXYRp5x5eceTs3u+3qAY+Ont/937vKF8NxWbN9JcU4WnuQmT1YbBaMRgNGI0m5l8yr4f6NPP+yE
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"t1 = np.array([A[i]@X for i in range(A.shape[0])])[:,0:3,-1]\n",
"t2 = np.array([Y@B[i] for i in range(B.shape[0])])[:,0:3,-1]\n",
"plt.plot(t1)\n",
"plt.plot(t2)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[-0.888, 0.453, 0.076, 0.023],\n",
" [-0.454, -0.891, -0.004, -0.000],\n",
" [0.066, -0.038, 0.997, 0.058],\n",
" [0.000, 0.000, 0.000, 1.000]])"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"base_T_marker = X\n",
"base_T_marker\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Load Lidar to Camera extrinsics"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.124, 0.311, -0.942, -0.140],\n",
" [-0.992, 0.014, -0.125, -0.037],\n",
" [-0.026, 0.950, 0.310, -0.041],\n",
" [0.000, 0.000, 0.000, 1.000]])"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import json\n",
"with open('datasets/calibration/calibration/utlidar-camera/calib.json', 'r') as f: \n",
" ext = json.load(f)\n",
"lidar_T_camera = ext['results']['init_T_lidar_camera']\n",
"t = np.array(lidar_T_camera[0:3])\n",
"q = np.array(lidar_T_camera[3:])\n",
"R = pin.Quaternion(q).matrix()\n",
"lidar_T_camera=np.vstack([np.hstack([R, t.reshape(3,1)]), np.array([0,0,0,1])])\n",
"lidar_T_camera"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Combine it All"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'infra1_T_imu': array([[-0.046, -0.999, 0.017, 0.054],\n",
" [-0.092, -0.013, -0.996, 0.067],\n",
" [0.995, -0.047, -0.092, -0.343],\n",
" [0.000, 0.000, 0.000, 1.000]]),\n",
" 'infra2_T_imu': array([[-0.040, -0.999, 0.017, -0.043],\n",
" [-0.091, -0.013, -0.996, 0.066],\n",
" [0.995, -0.041, -0.091, -0.344],\n",
" [0.000, 0.000, 0.000, 1.000]]),\n",
" 'color_T_imu': array([[-0.039, -0.999, 0.014, -0.007],\n",
" [-0.091, -0.010, -0.996, 0.066],\n",
" [0.995, -0.040, -0.090, -0.344],\n",
" [0.000, 0.000, 0.000, 1.000]]),\n",
" 'base_T_marker': array([[-0.888, 0.453, 0.076, 0.023],\n",
" [-0.454, -0.891, -0.004, -0.000],\n",
" [0.066, -0.038, 0.997, 0.058],\n",
" [0.000, 0.000, 0.000, 1.000]]),\n",
" 'imu_T_marker': array([[-0.887, 0.452, 0.097, 0.051],\n",
" [-0.454, -0.891, -0.002, 0.006],\n",
" [0.086, -0.046, 0.995, 0.017],\n",
" [0.000, 0.000, 0.000, 1.000]]),\n",
" 'lidar_T_color': array([[0.124, 0.311, -0.942, -0.140],\n",
" [-0.992, 0.014, -0.125, -0.037],\n",
" [-0.026, 0.950, 0.310, -0.041],\n",
" [0.000, 0.000, 0.000, 1.000]])}"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ext_result['base_T_marker'] = base_T_marker\n",
"ext_result['imu_T_marker'] = imu_T_marker\n",
"ext_result['lidar_T_color'] = lidar_T_camera\n",
"ext_result"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
"from Go2Py.calibration import ExtrinsicCalibrationManager\n",
"manager = ExtrinsicCalibrationManager()"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [],
"source": [
"for key, T in zip(ext_result.keys(), ext_result.values()):\n",
" parent = key.split('_T_')[0]\n",
" child = key.split('_T_')[1]\n",
" manager.add(parent=parent, child=child, R=T[0:3,0:3], t=T[0:3,-1])"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [],
"source": [
"ext_wrt_base = manager.get_all('base')\n",
"ext_wrt_imu = manager.get_all('imu')\n",
"result = {'ext_wrt_base':ext_wrt_base,\n",
" 'ext_wrt_imu':ext_wrt_base}"
]
},
{
"cell_type": "code",
2024-05-28 11:08:56 +08:00
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
"with open('datasets/calibration/final_results.pkl', 'wb') as f:\n",
" pickle.dump(result, f)"
]
},
{
"cell_type": "code",
2024-05-28 11:07:35 +08:00
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"import pickle\n",
"with open('datasets/calibration/final_results.pkl', 'rb') as f:\n",
" result = pickle.load(f)"
]
},
{
"cell_type": "code",
2024-05-28 11:07:35 +08:00
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2024-05-28 11:07:35 +08:00
"{'infra1_wrt_base': array([[-0.04633745, -0.07139989, 0.99637086, 0.32161791],\n",
" [-0.99882303, -0.01099835, -0.04723963, 0.03330488],\n",
" [ 0.01433134, -0.99738713, -0.07080622, 0.08162181],\n",
" [ 0. , 0. , 0. , 1. ]]),\n",
" 'imu_wrt_base': array([[ 9.99781597e-01, -2.84572838e-05, -2.08987443e-02,\n",
" -2.73533177e-02],\n",
" [-7.00270663e-06, 9.99998561e-01, -1.69667706e-03,\n",
" -5.49944525e-03],\n",
" [ 2.08987625e-02, 1.69645285e-03, 9.99780158e-01,\n",
" 3.99126757e-02],\n",
" [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n",
" 1.00000000e+00]]),\n",
" 'infra2_wrt_base': array([[-0.04036617, -0.07029462, 0.9967092 , 0.31796855],\n",
" [-0.99908557, -0.01122962, -0.0412544 , -0.06191919],\n",
" [ 0.01409262, -0.99746306, -0.06977704, 0.08277337],\n",
" [ 0. , 0. , 0. , 1. ]]),\n",
" 'color_wrt_base': array([[-0.03955514, -0.07002279, 0.99676085, 0.31941529],\n",
" [-0.99915546, -0.00833421, -0.04023564, -0.02578968],\n",
" [ 0.01112463, -0.99751058, -0.06963399, 0.08231088],\n",
" [ 0. , 0. , 0. , 1. ]]),\n",
" 'marker_wrt_base': array([[-8.88383872e-01, 4.52720962e-01, 7.62746821e-02,\n",
" 2.29437353e-02],\n",
" [-4.54285606e-01, -8.90848853e-01, -3.59301716e-03,\n",
" -6.99694933e-06],\n",
" [ 6.63225789e-02, -3.78424687e-02, 9.97080369e-01,\n",
" 5.84578170e-02],\n",
" [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n",
" 1.00000000e+00]]),\n",
" 'lidar_wrt_base': array([[-0.96602083, -0.08677698, 0.24346151, 0.19088012],\n",
" [-0.08810804, 0.99609608, 0.00543825, -0.00108608],\n",
" [-0.24298297, -0.01619745, -0.96989531, 0.00789635],\n",
" [ 0. , 0. , 0. , 1. ]])}"
]
},
2024-05-28 11:07:35 +08:00
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result['ext_wrt_base']"
]
},
{
"cell_type": "code",
2024-05-28 11:07:35 +08:00
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2024-05-28 11:07:35 +08:00
"{'infra1_wrt_base': array([[-0.04633745, -0.07139989, 0.99637086, 0.32161791],\n",
" [-0.99882303, -0.01099835, -0.04723963, 0.03330488],\n",
" [ 0.01433134, -0.99738713, -0.07080622, 0.08162181],\n",
" [ 0. , 0. , 0. , 1. ]]),\n",
" 'imu_wrt_base': array([[ 9.99781597e-01, -2.84572838e-05, -2.08987443e-02,\n",
" -2.73533177e-02],\n",
" [-7.00270663e-06, 9.99998561e-01, -1.69667706e-03,\n",
" -5.49944525e-03],\n",
" [ 2.08987625e-02, 1.69645285e-03, 9.99780158e-01,\n",
" 3.99126757e-02],\n",
" [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n",
" 1.00000000e+00]]),\n",
" 'infra2_wrt_base': array([[-0.04036617, -0.07029462, 0.9967092 , 0.31796855],\n",
" [-0.99908557, -0.01122962, -0.0412544 , -0.06191919],\n",
" [ 0.01409262, -0.99746306, -0.06977704, 0.08277337],\n",
" [ 0. , 0. , 0. , 1. ]]),\n",
" 'color_wrt_base': array([[-0.03955514, -0.07002279, 0.99676085, 0.31941529],\n",
" [-0.99915546, -0.00833421, -0.04023564, -0.02578968],\n",
" [ 0.01112463, -0.99751058, -0.06963399, 0.08231088],\n",
" [ 0. , 0. , 0. , 1. ]]),\n",
" 'marker_wrt_base': array([[-8.88383872e-01, 4.52720962e-01, 7.62746821e-02,\n",
" 2.29437353e-02],\n",
" [-4.54285606e-01, -8.90848853e-01, -3.59301716e-03,\n",
" -6.99694933e-06],\n",
" [ 6.63225789e-02, -3.78424687e-02, 9.97080369e-01,\n",
" 5.84578170e-02],\n",
" [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n",
" 1.00000000e+00]]),\n",
" 'lidar_wrt_base': array([[-0.96602083, -0.08677698, 0.24346151, 0.19088012],\n",
" [-0.08810804, 0.99609608, 0.00543825, -0.00108608],\n",
" [-0.24298297, -0.01619745, -0.96989531, 0.00789635],\n",
" [ 0. , 0. , 0. , 1. ]])}"
]
},
2024-05-28 11:07:35 +08:00
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result['ext_wrt_imu']"
]
},
{
"cell_type": "code",
2024-05-28 11:07:35 +08:00
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2024-05-28 11:07:35 +08:00
"(array([ 0.31941529, -0.02578968, 0.08231088]),\n",
" array([-1.64049103, -0.01112486, -1.61036424]))"
]
},
2024-05-28 11:07:35 +08:00
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pinocchio as pin\n",
"T = result['ext_wrt_imu']['color_wrt_base']\n",
"from scipy.spatial.transform import Rotation \n",
"T[0:3,-1], Rotation.from_matrix(T[0:3,0:3]).as_euler(seq='xyz')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3D Visualizations"
]
},
{
"cell_type": "code",
2024-05-28 11:07:35 +08:00
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
2024-05-28 11:07:35 +08:00
"[2024-05-28T02:56:54Z WARN re_sdk_comms::tcp_client] Tried to flush while TCP stream was still Pending. Data was possibly dropped.\n",
"[2024-05-28T02:56:54Z INFO re_sdk_comms::server] Hosting a SDK server over TCP at 0.0.0.0:9876. Connect with the Rerun logging SDK.\n",
"[2024-05-28T02:56:54Z INFO winit::platform_impl::platform::x11::window] Guessed window scale factor: 1\n",
"[2024-05-28T02:56:54Z INFO re_sdk_comms::server] New SDK client connected: 127.0.0.1:37256\n",
"[2024-05-28T02:56:54Z INFO re_sdk_comms::server] New SDK client connected: 127.0.0.1:37250\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
2024-05-28 11:07:35 +08:00
"[2024-05-28T02:56:54Z WARN wgpu_hal::vulkan::instance] Unable to find extension: VK_EXT_swapchain_colorspace\n",
"MESA-INTEL: warning: Performance support disabled, consider sysctl dev.i915.perf_stream_paranoid=0\n",
"\n",
2024-05-28 11:07:35 +08:00
"[2024-05-28T02:56:54Z INFO egui_wgpu] There were 3 available wgpu adapters: {backend: Vulkan, device_type: DiscreteGpu, name: \"NVIDIA GeForce GTX 1050\", driver: \"NVIDIA\", driver_info: \"535.171.04\", vendor: 0x10DE, device: 0x1C8D}, {backend: Vulkan, device_type: IntegratedGpu, name: \"Intel(R) HD Graphics 630 (KBL GT2)\", driver: \"Intel open-source Mesa driver\", driver_info: \"Mesa 21.2.6\", vendor: 0x8086, device: 0x591B}, {backend: Vulkan, device_type: Cpu, name: \"llvmpipe (LLVM 12.0.0, 256 bits)\", driver: \"llvmpipe\", driver_info: \"Mesa 21.2.6 (LLVM 12.0.0)\", vendor: 0x10005}\n"
]
}
],
"source": [
"import rerun as rr\n",
"rr.init('ext_visualization')\n",
"rr.spawn()"
]
},
{
"cell_type": "code",
2024-05-28 11:07:35 +08:00
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"rr.log(\"world/base\", rr.Transform3D(translation=[0,0,0], rotation=rr.Quaternion(xyzw=[0,0,0,1])))"
]
},
{
"cell_type": "code",
2024-05-28 11:07:35 +08:00
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"t=[0.28945, 0, -0.046825]\n",
"R = Rotation.from_euler(seq='xyz', angles=[0, 2.8782, 0])\n",
"q = R.as_quat()\n",
"rr.log(\"world/base/lidar\", rr.Transform3D(translation=t, rotation=rr.Quaternion(xyzw=q)))"
]
},
{
"cell_type": "code",
2024-05-28 11:08:56 +08:00
"execution_count": 35,
2024-05-28 11:07:35 +08:00
"metadata": {},
"outputs": [],
"source": [
2024-05-28 11:08:56 +08:00
"import numpy as np\n",
"result['ext_wrt_base']['lidar_wrt_base']=np.vstack([np.hstack([R.as_matrix(), np.array(t).reshape(3,1)]), np.array([0,0,0,1])])"
2024-05-28 11:07:35 +08:00
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"base infra1\n",
"base imu\n",
"base infra2\n",
"base color\n",
"base marker\n",
"base lidar\n"
]
}
],
"source": [
"import pinocchio as pin\n",
"for key, T in result['ext_wrt_base'].items():\n",
" child, parent = key.split('_wrt_')\n",
" print(parent, child)\n",
" qq = pin.Quaternion(T[0:3,0:3])\n",
" rr.log(f\"{parent}/{child}\", rr.Transform3D(translation=T[0:3,-1].tolist(), rotation=rr.Quaternion(xyzw=[qq.x,qq.y,qq.z, qq.w])))"
]
2024-05-28 11:07:35 +08:00
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}