mirror of
https://github.com/CopterExpress/clover.git
synced 2026-05-27 13:39:33 +00:00
Add test for QR recognition
This commit is contained in:
BIN
builder/test/qr.gif
Normal file
BIN
builder/test/qr.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
39
builder/test/qr.py
Normal file
39
builder/test/qr.py
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test QG recognition example
|
||||
# Should be synced with the documentation: /docs/en/camera.md, /docs/ru/camera.md
|
||||
|
||||
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))
|
||||
rospy.signal_shutdown()
|
||||
|
||||
image_sub = rospy.Subscriber('main_camera/image_raw', Image, image_callback, queue_size=1)
|
||||
|
||||
# ==============================================================================
|
||||
# Publish test image
|
||||
|
||||
print('Testing QR code recognition')
|
||||
import cv2
|
||||
img = cv2.imread('qr.gif')
|
||||
image_pub = rospy.Publisher('main_camera/image_raw', Image, image_callback, queue_size=1)
|
||||
image_pub.publish(bridge.cv2_to_imgmsg(img))
|
||||
|
||||
rospy.spin()
|
||||
@@ -29,3 +29,5 @@ import pigpio
|
||||
from pyzbar import pyzbar
|
||||
|
||||
print(cv2.getBuildInformation())
|
||||
|
||||
from . import qr
|
||||
|
||||
Reference in New Issue
Block a user