display_images_test.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import rospy
00004 from sensor_msgs.msg import Image
00005 from geometry_msgs.msg import Pose
00006 
00007 import copy
00008 import numpy as np
00009 import cv2
00010 from cv_bridge import CvBridge, CvBridgeError
00011 import tf
00012 import math
00013 
00014 from rviz_textured_quads.msg import TexturedQuad, TexturedQuadArray
00015 
00016 
00017 def pub_image():
00018 
00019     rospy.init_node('rviz_display_image_test', anonymous=True)
00020     image_pub = rospy.Publisher("/targets", TexturedQuadArray, queue_size=10)
00021 
00022     img1 = cv2.imread('./textures/bebop_drone.jpg',cv2.IMREAD_COLOR)
00023     img_msg1 = CvBridge().cv2_to_imgmsg(img1, "bgr8")
00024 
00025     img2 = cv2.imread('./textures/Decal.png',cv2.IMREAD_COLOR)
00026     img_msg2 = CvBridge().cv2_to_imgmsg(img2, "bgr8")
00027 
00028     cap = cv2.VideoCapture('/home/mohitshridhar/Downloads/ICRA_2010.mov')
00029 
00030     display_image = TexturedQuad()
00031 
00032     pose = Pose()
00033 
00034     pose.position.x =  -1.2
00035     pose.position.y =  -0.5
00036     pose.position.z =  2.0
00037 
00038     # pose.orientation.x = 0.70710678
00039     # pose.orientation.y = 0.0
00040     # pose.orientation.z = 0.0
00041     # pose.orientation.w = 0.70710678
00042 
00043     pose.orientation.x = 0.0
00044     pose.orientation.y = 0.0
00045     pose.orientation.z = 0.0
00046     pose.orientation.w = 1.0
00047 
00048     scale = 0.5
00049 
00050     display_image.image = img_msg1
00051     display_image.pose = pose
00052     display_image.width = scale
00053     display_image.height = (scale * img_msg1.height)/img_msg1.width
00054     display_image.border_color = [1., 0., 0., 0.5]
00055     display_image.border_size = 0.05
00056     display_image.caption = 'ICRA Video'
00057 
00058 
00059     second_image = copy.deepcopy(display_image)
00060     second_image.image = img_msg2
00061     second_image.width = 1.0
00062     second_image.height = 1.0
00063     second_image.pose.position.x = 2.2
00064     second_image.pose.position.y = -0.3
00065     second_image.pose.position.z = 2.0
00066 
00067     second_image.pose.orientation.x = 0.0
00068     second_image.pose.orientation.y = 0.70710678
00069     second_image.pose.orientation.z = 0.0
00070     second_image.pose.orientation.w = 0.70710678
00071     second_image.border_color = [0.5, 1.0, 0.0, 0.5]
00072     second_image.border_size = 0.1
00073     second_image.caption = 'Decal'
00074 
00075     display_images = TexturedQuadArray()
00076     display_images = np.array([display_image, second_image])
00077 
00078     rate = rospy.Rate(30) # 10hz
00079     deg_increment = 0.005
00080     angle = 0
00081     count = 0
00082 
00083     while not rospy.is_shutdown():
00084         if (cap.isOpened()):
00085             ret, frame = cap.read()
00086 
00087             display_image.image = CvBridge().cv2_to_imgmsg(frame, "bgr8")
00088 
00089         angle += deg_increment
00090 
00091         second_image.pose.position.x = 2.0 * math.sin(angle)
00092         second_image.pose.position.y = 2.0 * math.cos(angle)
00093 
00094 
00095         q = tf.transformations.quaternion_from_euler(angle + deg_increment, 0., 0.);
00096         second_image.pose.orientation.x = q[0]
00097         second_image.pose.orientation.y = q[1]
00098         second_image.pose.orientation.z = q[2]
00099         second_image.pose.orientation.w = q[3]
00100 
00101         # q = tf.transformations.quaternion_from_euler(0., angle + deg_increment, 0.);
00102         # display_image.pose.orientation.x = q[0]
00103         # display_image.pose.orientation.y = q[1]
00104         # display_image.pose.orientation.z = q[2]
00105         # display_image.pose.orientation.w = q[3]
00106 
00107 
00108         count = count + 1
00109 
00110         image_pub.publish(display_images)
00111         rate.sleep()
00112 
00113     cap.release()
00114 
00115 if __name__ == '__main__':
00116 
00117     try:
00118         pub_image()
00119     except rospy.ROSInterruptException:
00120         pass


rviz_textured_quads
Author(s): Mohit Shridhar
autogenerated on Thu Jun 6 2019 19:50:52