|
@ -10,7 +10,7 @@ from visualization_msgs.msg import MarkerArray |
|
|
from geometry_msgs.msg import Transform, Pose, Vector3, Quaternion, Point |
|
|
from geometry_msgs.msg import Transform, Pose, Vector3, Quaternion, Point |
|
|
from sensor_msgs.msg import CameraInfo |
|
|
from sensor_msgs.msg import CameraInfo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FrustumNode: |
|
|
class FrustumNode: |
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
self.color_count = 0 |
|
|
self.color_count = 0 |
|
@ -18,8 +18,8 @@ class FrustumNode: |
|
|
self.camera_types = ['depth', 'color'] |
|
|
self.camera_types = ['depth', 'color'] |
|
|
# only publish a single frustum for every N camera info |
|
|
# only publish a single frustum for every N camera info |
|
|
# messages received |
|
|
# messages received |
|
|
self.skip_publishing = 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.skip_publishing = 5 |
|
|
|
|
|
|
|
|
# minimum-Z depth for D435i |
|
|
# minimum-Z depth for D435i |
|
|
# 1280x720 0.28 m |
|
|
# 1280x720 0.28 m |
|
|
# 848x480 0.195 m |
|
|
# 848x480 0.195 m |
|
@ -43,12 +43,12 @@ class FrustumNode: |
|
|
if (self.depth_count % self.skip_publishing) == 0: |
|
|
if (self.depth_count % self.skip_publishing) == 0: |
|
|
self.camera_info_callback(camera_info, camera_type='depth') |
|
|
self.camera_info_callback(camera_info, camera_type='depth') |
|
|
self.depth_count = self.depth_count + 1 |
|
|
self.depth_count = self.depth_count + 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def color_camera_info_callback(self, camera_info): |
|
|
def color_camera_info_callback(self, camera_info): |
|
|
if (self.color_count % self.skip_publishing) == 0: |
|
|
if (self.color_count % self.skip_publishing) == 0: |
|
|
self.camera_info_callback(camera_info, camera_type='color') |
|
|
self.camera_info_callback(camera_info, camera_type='color') |
|
|
self.color_count = self.color_count + 1 |
|
|
self.color_count = self.color_count + 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def camera_info_callback(self, camera_info, camera_type=None): |
|
|
def camera_info_callback(self, camera_info, camera_type=None): |
|
|
if camera_type not in self.camera_types: |
|
|
if camera_type not in self.camera_types: |
|
|
print('WARNING: FrustumNode camera_info_callback camera_type = {0} unrecognized. Valid types = {1}.'.format(camera_type, self.camera_types)) |
|
|
print('WARNING: FrustumNode camera_info_callback camera_type = {0} unrecognized. Valid types = {1}.'.format(camera_type, self.camera_types)) |
|
@ -101,28 +101,28 @@ class FrustumNode: |
|
|
marker.type = marker.TRIANGLE_LIST |
|
|
marker.type = marker.TRIANGLE_LIST |
|
|
marker.action = marker.ADD |
|
|
marker.action = marker.ADD |
|
|
marker.lifetime = rospy.Duration(0.5) #0.2 |
|
|
marker.lifetime = rospy.Duration(0.5) #0.2 |
|
|
marker.text = 'D435i_frustum' |
|
|
|
|
|
marker.header.frame_id = frame_id |
|
|
marker.header.frame_id = frame_id |
|
|
marker.header.stamp = timestamp |
|
|
marker.header.stamp = timestamp |
|
|
marker.id = 0 |
|
|
marker.id = 0 |
|
|
marker.scale.x = 1.0 |
|
|
marker.scale.x = 1.0 |
|
|
marker.scale.y = 1.0 |
|
|
marker.scale.y = 1.0 |
|
|
marker.scale.z = 1.0 |
|
|
marker.scale.z = 1.0 |
|
|
if camera_type == 'depth': |
|
|
|
|
|
|
|
|
marker.pose.orientation.w = 1.0 |
|
|
|
|
|
if camera_type == 'depth': |
|
|
# frustum color and transparency |
|
|
# frustum color and transparency |
|
|
# gray |
|
|
# gray |
|
|
marker.color.r = 1.0 |
|
|
marker.color.r = 1.0 |
|
|
marker.color.g = 1.0 |
|
|
marker.color.g = 1.0 |
|
|
marker.color.b = 1.0 |
|
|
marker.color.b = 1.0 |
|
|
marker.color.a = 0.4 |
|
|
marker.color.a = 0.4 |
|
|
elif camera_type == 'color': |
|
|
|
|
|
|
|
|
elif camera_type == 'color': |
|
|
# frustum color and transparency |
|
|
# frustum color and transparency |
|
|
# yellow |
|
|
# yellow |
|
|
marker.color.r = 1.0 |
|
|
marker.color.r = 1.0 |
|
|
marker.color.g = 1.0 |
|
|
marker.color.g = 1.0 |
|
|
marker.color.b = 0.0 |
|
|
marker.color.b = 0.0 |
|
|
marker.color.a = 0.4 |
|
|
marker.color.a = 0.4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def adjacent_corners(c0, c1): |
|
|
def adjacent_corners(c0, c1): |
|
|
# return True if the corners are adjacent to one another and False otherwise |
|
|
# return True if the corners are adjacent to one another and False otherwise |
|
|
faces0 = c0[1] |
|
|
faces0 = c0[1] |
|
@ -170,23 +170,23 @@ class FrustumNode: |
|
|
|
|
|
|
|
|
points = [] |
|
|
points = [] |
|
|
quad_ids = ['near', 'far', 'top', 'bottom', 'left', 'right'] |
|
|
quad_ids = ['near', 'far', 'top', 'bottom', 'left', 'right'] |
|
|
for s in quad_ids: |
|
|
|
|
|
|
|
|
for s in quad_ids: |
|
|
quad_xyz = corners_to_quad(frustum_corners_xyz, s) |
|
|
quad_xyz = corners_to_quad(frustum_corners_xyz, s) |
|
|
triangles = quad_to_triangles(quad_xyz) |
|
|
triangles = quad_to_triangles(quad_xyz) |
|
|
points.extend(triangles) |
|
|
points.extend(triangles) |
|
|
marker.points = points |
|
|
marker.points = points |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if camera_type == 'depth': |
|
|
if camera_type == 'depth': |
|
|
self.depth_frustum_marker_pub.publish(marker) |
|
|
self.depth_frustum_marker_pub.publish(marker) |
|
|
elif camera_type == 'color': |
|
|
elif camera_type == 'color': |
|
|
self.color_frustum_marker_pub.publish(marker) |
|
|
self.color_frustum_marker_pub.publish(marker) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(self): |
|
|
def main(self): |
|
|
rospy.init_node('FrustumNode') |
|
|
rospy.init_node('FrustumNode') |
|
|
self.node_name = rospy.get_name() |
|
|
self.node_name = rospy.get_name() |
|
|
rospy.loginfo("{0} started".format(self.node_name)) |
|
|
rospy.loginfo("{0} started".format(self.node_name)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.color_camera_topic = '/camera/color/camera_info' |
|
|
self.color_camera_topic = '/camera/color/camera_info' |
|
|
self.depth_camera_topic = '/camera/depth/camera_info' |
|
|
self.depth_camera_topic = '/camera/depth/camera_info' |
|
|
self.depth_camera_info_subscriber = rospy.Subscriber(self.depth_camera_topic, CameraInfo, self.depth_camera_info_callback) |
|
|
self.depth_camera_info_subscriber = rospy.Subscriber(self.depth_camera_topic, CameraInfo, self.depth_camera_info_callback) |
|
|