Skip to content

Commit 1c066ef

Browse files
authored
Merge pull request #353 from CodeReaper-10/qr-and-barcode-scanner
QR and Barcode Scanner
2 parents 3cb6498 + 940d320 commit 1c066ef

File tree

4 files changed

+90
-2
lines changed

4 files changed

+90
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,6 @@ Once you are done working on your script edit this `README.md` file and add the
9595
68| Mood Sentiment Analyzer| Evaluate given texts/sentences general mood. | [Find me Here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/Mood%20Sentiment%20Analyzer)
9696
69| Morse Code Translation | Convert morse code to english language and vice versa | [Find me here](https://github.com/mahalrupi/General-Purpose-Scripts/tree/main/scripts/Morse-code-translation)
9797
70| Plagiarism Checker| Find similarity/plagiarism score between 2 texts | [Find me Here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/Plagiarism-Checker)
98-
71 | Water Reminder | Reminds you to drink water every 2 hours | [Find me Here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/Water%20Reminder)
99-
### Good Luck and don't forget to have fun with Open Source 🚀
98+
71| Water Reminder | Reminds you to drink water every 2 hours | [Find me Here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/Water%20Reminder)
99+
72| QR and Barcode Scanner | Scans both QR Codes and Barcodes | [Find me Here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/QR%20and%20Barcode%20Scanner) |
100+
### Good Luck and don't forget to have fun with Open Source 🚀
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## How to run
2+
3+
1. Clone the repository
4+
```
5+
git clone [email protected]:GDSC-RCCIIT/General-Purpose-Scripts.git
6+
```
7+
2. Install the script requirements
8+
```
9+
pip install -r requirements.txt
10+
```
11+
3. Navigate to `QR and Barcode Scanner` directory
12+
```
13+
cd General-Purpose-Scripts/scripts/QR and Barcode Scanner
14+
```
15+
4. Replace "frame.png" with the image path of the QR/Barcode or, with the name of the png file if it is in the same directory as the script.
16+
### Note
17+
The png file can also be placed in the same directory as the script and renamed to "frame.png" to avoid making changes to the code.
18+
5. Run the script to scan the QR/Barcode
19+
```
20+
python scanner.py
21+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
numpy==1.21.2
2+
pyzbar==0.1.8
3+
opencv_python==4.5.3.56
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from __future__ import print_function
2+
import pyzbar.pyzbar as pyzbar
3+
import numpy as np
4+
import cv2
5+
6+
# Image Path Or Image Name if in Same Directory or Replace the png file with your image
7+
8+
img_path = "frame.png"
9+
10+
11+
def decode(im):
12+
# Find barcodes and QR codes
13+
decodedObjects = pyzbar.decode(im)
14+
15+
# Print results
16+
for obj in decodedObjects:
17+
print("Type : ", obj.type)
18+
s = str(obj.data)
19+
s = s.replace(s[0], "")
20+
s = s.replace("'", "")
21+
print("Data : ", s, "\n")
22+
23+
return decodedObjects
24+
25+
26+
# Display barcode and QR code location
27+
def display(im, decodedObjects):
28+
29+
# Loop over all decoded objects
30+
for decodedObject in decodedObjects:
31+
points = decodedObject.polygon
32+
33+
# If the points do not form a quad, find convex hull
34+
if len(points) > 4:
35+
hull = cv2.convexHull(
36+
np.array([point for point in points], dtype=np.float32)
37+
)
38+
hull = list(map(tuple, np.squeeze(hull)))
39+
else:
40+
hull = points
41+
42+
# Number of points in the convex hull
43+
n = len(hull)
44+
45+
# Draw the convext hull
46+
for j in range(0, n):
47+
cv2.line(im, hull[j], hull[(j + 1) % n], (255, 0, 0), 3)
48+
49+
# Display results
50+
cv2.imshow("Results", im)
51+
cv2.waitKey(0)
52+
print("Done")
53+
54+
55+
# Main
56+
if __name__ == "__main__":
57+
58+
# Read image
59+
im = cv2.imread(img_path)
60+
61+
decodedObjects = decode(im)
62+
63+
display(im, decodedObjects)

0 commit comments

Comments
 (0)