Skip to content

Commit 2945cf3

Browse files
committed
add some stuff as an example for jiahe
1 parent 417761f commit 2945cf3

5 files changed

+156
-5
lines changed

launch/calibrate_extrinsics_easyhandeye.launch

+8-3
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,20 @@
2424
<include file="$(find rpad_ros)/launch/launch_rgbd.launch">
2525
<arg name="camera_id" value="$(arg camera_id)"/>
2626
<arg name="synchronized" value="false"/>
27+
<arg name="ir_mono8_scaling_factor" value="0.05" />
2728
</include>
2829

2930
<!-- Launch the tracker. -->
3031
<include file="$(find rpad_ros)/launch/aruco_single.launch">
3132
<arg name="markerId" value="$(arg aruco_marker_id)"/>
3233
<arg name="markerSize" value="$(arg aruco_marker_size)"/>
33-
<arg name="camera_frame" value="k4a_$(arg camera_id)/rgb_camera_link"/>
34-
<arg name="camera_info_topic" value="/k4a_$(arg camera_id)/rgb/camera_info"/>
35-
<arg name="image_rect_color_topic" value="/k4a_$(arg camera_id)/rgb/image_rect_color"/>
34+
<!-- <arg name="camera_frame" value="k4a_$(arg camera_id)/rgb_camera_link"/> -->
35+
<!-- <arg name="camera_info_topic" value="/k4a_$(arg camera_id)/rgb/camera_info"/> -->
36+
<arg name="camera_frame" value="k4a_$(arg camera_id)/depth_camera_link"/>
37+
<arg name="camera_info_topic" value="/k4a_$(arg camera_id)/ir/camera_info"/>
38+
<!-- <arg name="image_rect_color_topic" value="/k4a_$(arg camera_id)/rgb/image_rect_color"/> -->
39+
<arg name="image_rect_color_topic" value="/k4a_$(arg camera_id)/ir/image_rect_ir"/>
40+
3641
</include>
3742

3843
<!-- Launch static publishers which describe the frame of the tag w.r.t. the robot. -->

launch/launch_rgbd.launch

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<arg name="camera_id" default="0"/>
99
<arg name="synchronized" default="false"/>
1010
<!-- Only need the scaling factor when calibrating IR. -->
11-
<arg name="ir_mono8_scaling_factor" value="1.0" />
11+
<arg name="ir_mono8_scaling_factor" default="1.0" />
1212

1313
<!-- Derived fields. -->
1414
<arg name="sensor_sn" value="$(eval '000003493812,000180921812,000059793712,000263392612'.split(',')[arg('camera_id')])"/>
@@ -20,12 +20,13 @@
2020
<include file="$(find azure_kinect_ros_driver)/launch/kinect_rgbd.launch">
2121
<arg name="sensor_sn" value="$(arg sensor_sn)"/>
2222
<arg name="tf_prefix" value="k4a_$(arg camera_id)/"/>
23-
<arg name="color_resolution" value="1536P"/>
23+
<arg name="color_resolution" value="2160P"/>
2424
<arg name="depth_mode" value="NFOV_UNBINNED"/>
2525
<arg name="required" value="true"/>
2626
<arg name="overwrite_robot_description" value="false"/>
2727
<arg name="point_cloud" value="false"/>
2828
<arg name="rgb_point_cloud" value="false"/>
29+
<arg name="point_cloud_in_depth_frame" value="false"/>
2930
<arg name="ir_mono8_scaling_factor" value="$(arg ir_mono8_scaling_factor)" />
3031
<arg name="wired_sync_mode" value="$(arg wired_sync_mode)"/>
3132
<arg name="node_start_delay" value="$(arg camera_id)"/>
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<launch>
2+
<!-- Launch all the cameras. Make sure they're not snapped.-->
3+
<include file="$(find rpad_ros)/launch/launch_table1_cameras.launch">
4+
<arg name="publish_snapped" value="true"/>
5+
</include>
6+
7+
<!-- Record point clouds to the ROS_HOME, which should be specified. -->
8+
9+
<node name="pointcloud_to_pcd0" pkg="pcl_ros" type="pointcloud_to_pcd" output="screen" >
10+
<remap from="input" to="/k4a_0/depth_to_rgb/points_filtered"/>
11+
<param name="prefix" value="0/"/>
12+
<param name="fixed_frame" value="panda_link0" />
13+
</node>
14+
15+
<node name="pointcloud_to_pcd1" pkg="pcl_ros" type="pointcloud_to_pcd" output="screen">
16+
<remap from="input" to="/k4a_1/depth_to_rgb/points_filtered"/>
17+
<param name="prefix" value="1/"/>
18+
<param name="fixed_frame" value="panda_link0" />
19+
</node>
20+
21+
<node name="pointcloud_to_pcd2" pkg="pcl_ros" type="pointcloud_to_pcd" output="screen">
22+
<remap from="input" to="/k4a_2/depth_to_rgb/points_filtered"/>
23+
<param name="prefix" value="2/"/>
24+
<param name="fixed_frame" value="panda_link0" />
25+
</node>
26+
27+
<node name="pointcloud_to_pcd3" pkg="pcl_ros" type="pointcloud_to_pcd" output="screen">
28+
<remap from="input" to="/k4a_3/depth_to_rgb/points_filtered"/>
29+
<param name="prefix" value="3/"/>
30+
<param name="fixed_frame" value="panda_link0" />
31+
</node>
32+
33+
</launch>

scripts/apriltag_6x10.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
target_type: 'aprilgrid' #gridtype
2+
tagCols: 10 #number of apriltags
3+
tagRows: 7 #number of apriltags
4+
tagSize: 0.025 #size of apriltag, edge to edge [m]
5+
tagSpacing: 0.3 #ratio of space between tags to tagSize
6+
#example: tagSize=2m, spacing=0.5m --> tagSpacing=0.25[-]

scripts/manual_calibration.py

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
from pyk4a import PyK4A
2+
from matplotlib import pyplot as plt
3+
from pyk4a.calibration import CalibrationType
4+
import open3d as o3d
5+
import numpy as np
6+
def main():
7+
# Capture a depth image and an rgb image from the camera.
8+
9+
# Load camera with the default config
10+
k4a = PyK4A(
11+
device_id=1,
12+
)
13+
k4a.start()
14+
15+
# Get the next capture (blocking function)
16+
capture = k4a.get_capture()
17+
img_color = capture.color
18+
img_depth = capture.depth
19+
capture_pts = capture.depth_point_cloud
20+
21+
# # Display with pyplot
22+
# plt.imshow(img_color[:, :, 2::-1]) # BGRA to RGB
23+
# plt.show()
24+
25+
# get the transform from the rgb frame to the depth frame.
26+
R, t = k4a.calibration.get_extrinsic_parameters(CalibrationType.DEPTH, CalibrationType.COLOR)
27+
print(R, t)
28+
29+
# get the intrinsics from the depth camera.
30+
K = k4a.calibration.get_camera_matrix(CalibrationType.DEPTH)
31+
print(K)
32+
33+
# Backproject the depth image into 3D space.
34+
# This is a 2D array of 3D points.
35+
# Do it manually, without calling the k4a api.
36+
# Do it vectorized.
37+
# Do it with numpy.
38+
39+
# Get a numpy meshgrid of the pixel coordinates.
40+
# This is a 2D array of 2D points.
41+
xx, yy = np.meshgrid(np.arange(img_depth.shape[1]), np.arange(img_depth.shape[0]))
42+
43+
# Reshape the meshgrid into a 2D array of 2D points.
44+
# This is a 2D array of 2D points.
45+
xx = xx.reshape(-1)
46+
yy = yy.reshape(-1)
47+
48+
# Get the depth values.
49+
# This is a 1D array of depth values.
50+
zz = img_depth.reshape(-1)
51+
52+
# Get the camera intrinsics.
53+
# This is a 2D array of camera intrinsics.
54+
KK = np.array(K).reshape(3, 3)
55+
56+
# Get the inverse of the camera intrinsics.
57+
# This is a 2D array of camera intrinsics.
58+
KK_inv = np.linalg.inv(KK)
59+
60+
# Get the 2D points in the camera frame.
61+
# This is a 2D array of 2D points.
62+
points_2d = np.stack([xx, yy, np.ones_like(xx)], axis=0)
63+
64+
# Get the 3D points in the camera frame.
65+
# This is a 2D array of 3D points.
66+
points_3d = KK_inv @ points_2d
67+
68+
# Scale the 3D points by the depth values.
69+
# This is a 2D array of 3D points.
70+
points_3d = points_3d * zz
71+
72+
# breakpoint()
73+
74+
75+
76+
# # Visualize the 3D point cloud.
77+
# pcd2 = o3d.geometry.PointCloud()
78+
# pcd2.points = o3d.utility.Vector3dVector(points_3d.T)
79+
# pcd2.paint_uniform_color([1, 0.706, 0])
80+
# # o3d.visualization.draw_geometries([pcd3])
81+
82+
# pcd = o3d.geometry.PointCloud()
83+
# pcd.points = o3d.utility.Vector3dVector(capture_pts.reshape(-1, 3))
84+
# pcd.paint_uniform_color([0, 0.651, 0.929])
85+
# o3d.visualization.draw_geometries([pcd, pcd2])
86+
87+
# Visualize color to depth points
88+
color_3d = capture.transformed_color
89+
color = capture.color
90+
plt.subplot(1, 2, 1)
91+
plt.imshow(color[:, :, 2::-1])
92+
plt.subplot(1, 2, 2)
93+
plt.imshow(color_3d[:, :, 2::-1])
94+
plt.show()
95+
96+
# color_to_depth = k4a.calibration.color_to_depth_3d()
97+
# pcd3 = o3d.geometry.PointCloud()
98+
# pcd3.points = o3d.utility.Vector3dVector(color_to_depth @ color_3d.T)
99+
100+
101+
102+
103+
104+
105+
if __name__ == "__main__":
106+
main()

0 commit comments

Comments
 (0)