5 import tf2_geometry_msgs
7 from sensor_msgs.msg
import CameraInfo
8 from geometry_msgs.msg
import PointStamped
9 from geometry_msgs.msg
import PoseStamped
10 from image_geometry
import PinholeCameraModel
21 self.
pub = rospy.Publisher(
"~output", PointStamped, queue_size=1)
23 rospy.Subscriber(
'~input/camera_info', CameraInfo, self.
camera_info_cb)
27 self.cameramodels.fromCameraInfo(msg)
34 pose_stamped = PoseStamped()
35 pose_stamped.pose.position.x = msg.point.x
36 pose_stamped.pose.position.y = msg.point.y
37 pose_stamped.pose.position.z = msg.point.z
39 transform = self.tf_buffer.lookup_transform(self.
frame_id, msg.header.frame_id, rospy.Time(0), rospy.Duration(1.0))
40 except (tf2_ros.LookupException, tf2_ros.ConnectivityException, tf2_ros.ExtrapolationException)
as e:
41 rospy.logerr(
'lookup_transform failed: {}'.format(e))
43 position_transformed = tf2_geometry_msgs.do_transform_pose(pose_stamped, transform).pose.position
44 pub_point = (position_transformed.x, position_transformed.y, position_transformed.z)
45 u, v = self.cameramodels.project3dToPixel(pub_point)
46 rospy.logdebug(
"u, v : {}, {}".format(u, v))
47 pub_msg = PointStamped()
48 pub_msg.header = msg.header
49 pub_msg.header.frame_id = self.
frame_id 53 self.pub.publish(pub_msg)
56 if __name__ ==
'__main__':
57 rospy.init_node(
"xyz_to_screenpoint")
def camera_info_cb(self, msg)
def point_stamped_cb(self, msg)