Created
June 5, 2026 05:15
-
-
Save aspose-com-gists/ea5cb55edd80496952c161d5eec943b7 to your computer and use it in GitHub Desktop.
Step-by-Step Guide to Read QR Code from Image in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Step-by-Step Guide to Read QR Code from Image in Python | |
| # Read the full guide here: https://blog.aspose.com/barcode/step-by-step-guide-to-read-qr-code-from-image-in-python/ | |
| # Complete working example for reading a QR code from an image file | |
| # Import the BarCodeReader class from Aspose.BarCode | |
| from asposebarcode import BarCodeReader, DecodeType | |
| def read_qr_from_image(image_path: str) -> str: | |
| """ | |
| Reads a QR code from the specified image file and returns the decoded text. | |
| Supported image formats: PNG, JPEG, BMP, GIF, TIFF. | |
| """ | |
| # Initialize the reader for QR codes only (optional but speeds up detection) | |
| with BarCodeReader(image_path, DecodeType.QR) as reader: | |
| # Iterate over all detected barcodes (there may be more than one) | |
| for result in reader.read(): | |
| # Return the first decoded QR code text | |
| return result.code_text | |
| # If no QR code is found, return an empty string | |
| return "" | |
| if __name__ == "__main__": | |
| image_file = "sample_qr.png" # Replace with your image file path | |
| decoded_text = read_qr_from_image(image_file) | |
| if decoded_text: | |
| print(f"Decoded QR text: {decoded_text}") | |
| else: | |
| print("No QR code detected in the image.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment