Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # Python libs
  4. import sys, time
  5. import numpy as np
  6. # OpenCV
  7. import cv2 as cv
  8. # Ros libraries
  9. import roslib
  10. import rospy
  11. # Ros Messages
  12. from sensor_msgs.msg import CompressedImage
  13.  
  14.  
  15. class Image:
  16.     def __init__(self):
  17.         # self.bridge = CvBridge()
  18.  
  19.         # subscribed Topic
  20.         self.subscriber = rospy.Subscriber("team1/camera/rgb/compressed",
  21.                                            CompressedImage,
  22.                                            self.callback,
  23.                                            queue_size=1)
  24.  
  25.     def callback(self, ros_data):
  26.         #### direct conversion to CV2 ####
  27.         np_arr = np.fromstring(ros_data.data, np.uint8)
  28.         self.image_np = cv.imdecode(np_arr, cv.IMREAD_COLOR)
  29.         # print "Callback"
  30.  
  31.         cv.imshow('RGB', self.image_np)
  32.         k = cv.waitKey(1)
  33.  
  34. def main(args):
  35.     '''Initializes and cleanup ros node'''
  36.     rospy.init_node('drive_car', anonymous=True)
  37.     # define frame object and detect
  38.     frame = Image()
  39.  
  40.     try:
  41.         rospy.spin()
  42.     except KeyboardInterrupt:
  43.         print "Shutting down ROS Image feature detector module"
  44.     cv.destroyAllWindows()
  45.  
  46. if __name__ == '__main__':
  47.     main(sys.argv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement