Skip to content

Commit 8845c63

Browse files
authored
Merge pull request #31 from DhanashreePetare/qrcode-branch
Add QR Code Scanner script in Python (#4)
2 parents 60f159c + 76f3783 commit 8845c63

File tree

6 files changed

+119
-1
lines changed

6 files changed

+119
-1
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore Python virtual environments
2+
Python/venv/
3+
4+
# Ignore __pycache__ folders
5+
**/__pycache__/

Python/INDEX.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ This directory contains Python scripts contributed to the Code_Script repository
1818

1919
---
2020

21+
### 2. QR Code Scanner
22+
**Path:** `Python/qr_code_scanner/`
23+
**Description:** Simple script that scans and decodes QR codes from image files.
24+
**Features:**
25+
- Detects and decodes one or multiple QR codes in an image
26+
- Displays decoded text or URL directly in the terminal
27+
- Uses `opencv-python`, `pyzbar`, and `Pillow`
28+
- Beginner-friendly and easy to extend
29+
30+
**Usage:** See [qr_code_scanner/README.md](qr_code_scanner/README.md)
31+
32+
---
33+
2134
## 🚀 How to Use
2235

2336
Each script has its own directory with:
@@ -43,4 +56,4 @@ See [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
4356

4457
---
4558

46-
**Last Updated:** October 5, 2025
59+
**Last Updated:** October 7, 2025

Python/QRcode_Scanner/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# 🧾 QR Code Scanner
2+
3+
A beginner-friendly Python script that scans and decodes QR codes from an image.
4+
5+
---
6+
7+
## 📋 Features
8+
- Reads QR codes from image files (PNG, JPG, etc.)
9+
- Prints the decoded text or URL to the terminal
10+
- Uses simple, widely available libraries (`opencv-python`, `pyzbar`, `Pillow`)
11+
12+
---
13+
14+
## 🚀 Usage
15+
16+
1️⃣ Install dependencies
17+
pip install -r requirements.txt
18+
19+
2️⃣ Run the script
20+
python qr_scanner.py sample_images/test_qr.png
21+
If the image contains a valid QR code, you’ll see:
22+
✅ QR Code Detected: Hello Hacktoberfest 2025!
23+
24+
25+
📁 Folder structure
26+
qr_code_scanner/
27+
28+
├── qr_scanner.py # main script
29+
├── README.md # usage instructions
30+
├── requirements.txt # dependencies
31+
└── sample_images/ # test images
32+
🧠 Notes
33+
Make sure your image path is correct while testing in CLI.
34+
Works with multiple QR codes in one image.
35+
Tested with Python 3.9+.
36+
37+
🎯 Author
38+
Dhanashree Petare
39+
Contribution for Hacktoberfest 2025 under issue #4 (QR Code Scanner)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
QR Code Scanner 🧾
3+
-------------------
4+
A simple Python script to read and decode QR codes from an image file.
5+
6+
Dependencies:
7+
pip install opencv-python pyzbar Pillow
8+
9+
Usage:
10+
python qr_scanner.py <path_to_image>
11+
12+
Example:
13+
python qr_scanner.py sample_images/test_qr.png
14+
"""
15+
16+
import sys
17+
import cv2
18+
from pyzbar.pyzbar import decode
19+
from PIL import Image
20+
21+
22+
def scan_qr_code(image_path):
23+
"""
24+
Reads an image and decodes QR codes inside it.
25+
Returns a list of decoded strings (text/URLs).
26+
"""
27+
try:
28+
# Read the image using OpenCV
29+
img = cv2.imread(image_path)
30+
if img is None:
31+
print("⚠️ Could not read the image. Check the path.")
32+
return []
33+
34+
# Decode any QR codes present in the image
35+
qr_codes = decode(img)
36+
if not qr_codes:
37+
print("❌ No QR code found in the image.")
38+
return []
39+
40+
decoded_texts = []
41+
for qr in qr_codes:
42+
data = qr.data.decode('utf-8')
43+
decoded_texts.append(data)
44+
print(f"✅ QR Code Detected: {data}")
45+
46+
return decoded_texts
47+
48+
except Exception as e:
49+
print(f"🚫 Error: {e}")
50+
return []
51+
52+
53+
if __name__ == "__main__":
54+
if len(sys.argv) < 2:
55+
print("Usage: python qr_scanner.py <path_to_image>")
56+
else:
57+
image_path = sys.argv[1]
58+
scan_qr_code(image_path)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
opencv-python
2+
pyzbar
3+
Pillow
25.8 KB
Loading

0 commit comments

Comments
 (0)