Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import rospy
- from pyzbar import pyzbar
- from cv_bridge import CvBridge
- from sensor_msgs.msg import Image
- bridge = CvBridge()
- rospy.init_node('barcode_test')
- # Image subscriber callback function
- def image_callback(data):
- cv_image = bridge.imgmsg_to_cv2(data, 'bgr8') # OpenCV image
- barcodes = pyzbar.decode(cv_image)
- for barcode in barcodes:
- b_data = barcode.data.encode("utf-8")
- b_type = barcode.type
- (x, y, w, h) = barcode.rect
- xc = x + w/2
- yc = y + h/2
- print ("Found {} with data {} with center at x={}, y={}".format(b_type, b_data, xc, yc))
- image_sub = rospy.Subscriber('main_camera/image_raw', Image, image_callback, queue_size=1)
- rospy.spin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement