6 from sensor_msgs.msg
import Image, CameraInfo
14 global latest_camera_info
15 latest_camera_info = msg;
24 global latest_camera_info, latest_image, frame_id
26 if latest_image
is not None:
28 r = math.sqrt((msg.point.x - latest_image.width/2)*(msg.point.x - latest_image.width/2)+ (msg.point.y - latest_image.height/2.0) * (msg.point.y - latest_image.height/2.0))
32 x = -(msg.point.y - latest_image.height/2.0) / r * math.sin(phi)
33 y = (msg.point.x - latest_image.width/2.0) / r * math.sin(phi)
34 z = 1.0 * math.cos(phi)
36 pose.pose.position.x = 0
37 pose.pose.position.y = 0
38 pose.pose.position.z = 0
40 first_vec = [x, -y,-z]
42 dot = np.dot(first_vec, second_vec)/(tf.transformations.vector_norm(first_vec)*tf.transformations.vector_norm(second_vec))
45 M = tf.transformations.rotation_matrix(c,np.cross(first_vec, second_vec))
46 quat = tf.transformations.quaternion_from_matrix(M)
47 pose.pose.orientation.x = quat[0]
48 pose.pose.orientation.y = quat[1]
49 pose.pose.orientation.z = quat[2]
50 pose.pose.orientation.w = quat[3]
52 pose.header.frame_id=frame_id
55 point = PointStamped()
56 point.header.stamp = rospy.Time.now()
57 point.header.frame_id= frame_id
63 if __name__ ==
"__main__":
64 rospy.init_node(
"click_to_pose")
66 pub = rospy.Publisher(
"~output", PoseStamped, queue_size=1)
67 pub_p = rospy.Publisher(
"~output_point", PointStamped, queue_size=1)
68 frame_id = rospy.get_param(
"~frame_id",
"fisheye")
69 rospy.Subscriber(
"clicked_point", PointStamped, cloud_cb)
70 rospy.Subscriber(
"camera_info", CameraInfo, camera_info_cb)
71 rospy.Subscriber(
"image", Image, image_cb)