broadcast.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD License)
3 #
4 # Copyright (c) 2008, Willow Garage, Inc.
5 # Copyright (c) 2016, Tal Regev.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 # * Neither the name of the Willow Garage nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 
35 import sys
36 import time
37 import math
38 import rospy
39 import cv2
40 
41 import sensor_msgs.msg
42 from cv_bridge import CvBridge
43 
44 
45 # Send each image by iterate it from given array of files names to a given topic,
46 # as a regular and compressed ROS Images msgs.
47 class Source:
48 
49  def __init__(self, topic, filenames):
50  self.pub = rospy.Publisher(topic, sensor_msgs.msg.Image)
51  self.pub_compressed = rospy.Publisher(topic + "/compressed", sensor_msgs.msg.CompressedImage)
52  self.filenames = filenames
53 
54  def spin(self):
55  time.sleep(1.0)
56  cvb = CvBridge()
57  while not rospy.core.is_shutdown():
58  cvim = cv2.imload(self.filenames[0])
59  self.pub.publish(cvb.cv2_to_imgmsg(cvim))
60  self.pub_compressed.publish(cvb.cv2_to_compressed_imgmsg(cvim))
61  self.filenames = self.filenames[1:] + [self.filenames[0]]
62  time.sleep(1)
63 
64 
65 def main(args):
66  s = Source(args[1], args[2:])
67  rospy.init_node('Source')
68  try:
69  s.spin()
70  rospy.spin()
71  outcome = 'test completed'
72  except KeyboardInterrupt:
73  print "shutting down"
74  outcome = 'keyboard interrupt'
75  rospy.core.signal_shutdown(outcome)
76 
77 if __name__ == '__main__':
78  main(sys.argv)
def main(args)
Definition: broadcast.py:65
def __init__(self, topic, filenames)
Definition: broadcast.py:49
def spin(self)
Definition: broadcast.py:54


opencv_tests
Author(s): James Bowman
autogenerated on Thu Dec 12 2019 03:52:13