publish_mouse_event.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 import cv2
5 import numpy as np
6 
7 import rospy
8 from sensor_msgs.msg import Image
9 import cv_bridge
10 from image_view2.msg import MouseEvent
11 
12 
13 def main():
14  pub_plus = rospy.Publisher('~plus_rect_event', MouseEvent, queue_size=1)
15  pub_minus = rospy.Publisher('~minus_rect_event', MouseEvent, queue_size=1)
16 
17  width = rospy.get_param('~image_width')
18  height = rospy.get_param('~image_height')
19  plus_events = [
20  MouseEvent(type=3, x=width/4, y=height/4, width=width, height=height),
21  MouseEvent(type=4, x=width/2, y=height/2, width=width, height=height),
22  MouseEvent(type=2, x=3*width/4, y=3*height/4, width=width, height=height),
23  ]
24  minus_events = [
25  MouseEvent(type=3, x=3*width/4, y=3*height/4, width=width, height=height),
26  MouseEvent(type=4, x=width/2, y=height/2, width=width, height=height),
27  MouseEvent(type=2, x=width/4, y=height/4, width=width, height=height),
28  ]
29  rate = rospy.Rate(10)
30  while not rospy.is_shutdown():
31  for e in plus_events:
32  e.header.stamp = rospy.get_rostime()
33  pub_plus.publish(e)
34  rate.sleep()
35  for e in minus_events:
36  e.header.stamp = rospy.get_rostime()
37  pub_minus.publish(e)
38  rate.sleep()
39 
40 
41 if __name__ == '__main__':
42  rospy.init_node('publish_mouse_event')
43  main()


image_view2
Author(s): Kei Okada
autogenerated on Tue Feb 6 2018 03:45:03