diff --git a/src/add_qr.py b/src/add_qr.py index 59cb3417bacddc1e67d2f2bba8d949701a0c1fe9..0d327b99cc13b2ec51fb67046bddb19d6bd2fb38 100755 --- a/src/add_qr.py +++ b/src/add_qr.py @@ -2,6 +2,7 @@ import rospy +import json import time import os import qrcode @@ -23,6 +24,21 @@ parser.add_option ("", "--test", action="store_true", dest="test", help="Test mo parser.add_option ("", "--qr", action="store_true", dest="qr", help="Time encoding qr code.") (options, args) = parser.parse_args() +def header_to_json(data): + jobj = { + "seq": data.seq, + "stamp": stamp_to_json(data.stamp), + "frame_id": data.frame_id + + } + return jobj + +def stamp_to_json(data): + jobj = { + "secs": data.secs, + "nsecs": data.nsecs + } + return jobj def image_callback(data): global fifo @@ -33,6 +49,10 @@ def image_callback(data): else: img = bridge.imgmsg_to_cv2(data, desired_encoding='bgr8') + # print(data.header) + jobj = header_to_json(data.header) + print(json.dumps(jobj)) + scaledimg = cv2.resize(img, (1024, 600)) if options.qr: @@ -42,7 +62,8 @@ def image_callback(data): timestamp = time.time() qr = qrcode.QRCode(box_size=2) - qr.add_data(str(timestamp)) + # qr.add_data(str(timestamp)) + qr.add_data(json.dumps(jobj)) qr.make() img_qr = qr.make_image() @@ -72,6 +93,10 @@ def image_callback(data): msg = bridge.cv2_to_compressed_imgmsg(final_image) image_pub.publish(msg) + decoded_data, _ , _ = detector.detectAndDecode(final_image) + print("DECODED DATA:", decoded_data) + + #retval, points = detector.detect(final_image) #print("DETECT:", retval, points) #qr_timestamp, _ , _ = detector.detectAndDecode(final_image) @@ -79,15 +104,15 @@ def image_callback(data): except Exception as exc: print("image_callback exception:", exc) - fifo.close() - fifo = open(options.fifo, 'wb') - print(f'FIFO RE-OPENED: {options.fifo}') + #fifo.close() + #fifo = open(options.fifo, 'wb') + #print(f'FIFO RE-OPENED: {options.fifo}') if __name__ == "__main__": rospy.init_node ("add_qr") - # detector = cv2.QRCodeDetector() + detector = cv2.QRCodeDetector() #try: # os.mkfifo(options.fifo)