Skip to content
Snippets Groups Projects
Commit cabdd7ba authored by Tommy Persson's avatar Tommy Persson
Browse files

Work on qr code.

parent 6c6ee2f4
Branches
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import rospy import rospy
import json
import time import time
import os import os
import qrcode import qrcode
...@@ -23,6 +24,21 @@ parser.add_option ("", "--test", action="store_true", dest="test", help="Test mo ...@@ -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.") parser.add_option ("", "--qr", action="store_true", dest="qr", help="Time encoding qr code.")
(options, args) = parser.parse_args() (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): def image_callback(data):
global fifo global fifo
...@@ -33,6 +49,10 @@ def image_callback(data): ...@@ -33,6 +49,10 @@ def image_callback(data):
else: else:
img = bridge.imgmsg_to_cv2(data, desired_encoding='bgr8') 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)) scaledimg = cv2.resize(img, (1024, 600))
if options.qr: if options.qr:
...@@ -42,7 +62,8 @@ def image_callback(data): ...@@ -42,7 +62,8 @@ def image_callback(data):
timestamp = time.time() timestamp = time.time()
qr = qrcode.QRCode(box_size=2) qr = qrcode.QRCode(box_size=2)
qr.add_data(str(timestamp)) # qr.add_data(str(timestamp))
qr.add_data(json.dumps(jobj))
qr.make() qr.make()
img_qr = qr.make_image() img_qr = qr.make_image()
...@@ -72,6 +93,10 @@ def image_callback(data): ...@@ -72,6 +93,10 @@ def image_callback(data):
msg = bridge.cv2_to_compressed_imgmsg(final_image) msg = bridge.cv2_to_compressed_imgmsg(final_image)
image_pub.publish(msg) image_pub.publish(msg)
decoded_data, _ , _ = detector.detectAndDecode(final_image)
print("DECODED DATA:", decoded_data)
#retval, points = detector.detect(final_image) #retval, points = detector.detect(final_image)
#print("DETECT:", retval, points) #print("DETECT:", retval, points)
#qr_timestamp, _ , _ = detector.detectAndDecode(final_image) #qr_timestamp, _ , _ = detector.detectAndDecode(final_image)
...@@ -79,15 +104,15 @@ def image_callback(data): ...@@ -79,15 +104,15 @@ def image_callback(data):
except Exception as exc: except Exception as exc:
print("image_callback exception:", exc) print("image_callback exception:", exc)
fifo.close() #fifo.close()
fifo = open(options.fifo, 'wb') #fifo = open(options.fifo, 'wb')
print(f'FIFO RE-OPENED: {options.fifo}') #print(f'FIFO RE-OPENED: {options.fifo}')
if __name__ == "__main__": if __name__ == "__main__":
rospy.init_node ("add_qr") rospy.init_node ("add_qr")
# detector = cv2.QRCodeDetector() detector = cv2.QRCodeDetector()
#try: #try:
# os.mkfifo(options.fifo) # os.mkfifo(options.fifo)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment