Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import cv2
  4. import rospy
  5. from cv_bridge import CvBridge, CvBridgeError
  6. from sensor_msgs.msg import Image
  7.  
  8.  
  9. WIN_NAME = "cv"
  10.  
  11. class DemoBridge(object):
  12. def __init__(self):
  13. rospy.init_node("cv_demo")
  14. cv2.namedWindow(WIN_NAME)
  15. self._bridge = CvBridge()
  16. self._sub = rospy.Subscriber("/mysensor/camera/image_raw",
  17. Image,
  18. self.cb)
  19.  
  20. def cb(self, data):
  21. try:
  22. cv_image = self._bridge.imgmsg_to_cv2(data, "bgr8")
  23. cv2.imshow(WIN_NAME, cv_image)
  24. cv2.waitKey(3)
  25. except CvBridgeError as e:
  26. rospy.logerr(e)
  27.  
  28.  
  29. def main():
  30. obj = DemoBridge()
  31. try:
  32. rospy.spin()
  33. except KeyboardInterrupt:
  34. pass
  35. finally:
  36. cv2.DestroyAllWindows()
  37.  
  38. if __name__ == "__main__":
  39. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement