9/26/2023

QR detector python code

 refer to code:


.

import cv2
#pip install pyzbar
from pyzbar.pyzbar import decode

def scan_qr_code():
# Start the webcam
cap = cv2.VideoCapture(0)
cap.set(3, 640) # Set the width of the window
cap.set(4, 480) # Set the height of the window
while True:
success, img = cap.read()
if not success:
print("Failed to grab frame")
break
# Decode the QR Code
for barcode in decode(img):
# Get the QR Code position
my_data = barcode.data.decode('utf-8')
pts = barcode.polygon
if len(pts) == 4: # If we have 4 points, then we have a QR code
pts2 = barcode.rect
cv2.putText(img, my_data, (pts2[0], pts2[1]), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (255, 0, 255), 2)
for point in pts:
cv2.circle(img, (point[0], point[1]), 5, (0, 255, 0), cv2.FILLED)
# Display the frame
cv2.imshow('QR Code Scanner', img)
if cv2.waitKey(1) & 0xFF == ord('q'): # Press 'q' to quit
break
cap.release()
cv2.destroyAllWindows()

if __name__ == "__main__":
scan_qr_code()

..


you need to install pyzbar


Thank you.

www.marearts.com

πŸ™‡πŸ»‍♂️




No comments:

Post a Comment