Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 79be410

Browse filesBrowse files
committed
add qr code tutorial
1 parent 74d573e commit 79be410
Copy full SHA for 79be410

File tree

Expand file treeCollapse file tree

8 files changed

+108
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

8 files changed

+108
-1
lines changed
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+3Lines changed: 3 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
3333
- [How to Control your Keyboard in Python](https://www.thepythoncode.com/article/control-keyboard-python). ([code](general/keyboard-controller))
3434
- [How to Make a Process Monitor in Python](https://www.thepythoncode.com/article/make-process-monitor-python). ([code](general/process-monitor))
3535
- [How to Make a Screen Recorder in Python](https://www.thepythoncode.com/article/make-screen-recorder-python). ([code](general/screen-recorder))
36+
- [How to Generate and Read QR Code in Python](https://www.thepythoncode.com/article/generate-read-qr-code-python). ([code](general/generating-reading-qrcode))
37+
38+
- ### [Web Scraping](https://www.thepythoncode.com/topic/web-scraping)
3639
- [How to Access Wikipedia in Python](https://www.thepythoncode.com/article/access-wikipedia-python). ([code](general/wikipedia-extractor))
3740
- [How to Extract YouTube Data in Python](https://www.thepythoncode.com/article/get-youtube-data-python). ([code](general/youtube-extractor))
3841

Collapse file
+27Lines changed: 27 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# [How to Generate and Read QR Code in Python](https://www.thepythoncode.com/article/generate-read-qr-code-python)
2+
To run this:
3+
- `pip3 install -r requirements.txt`
4+
- If you want to generate a QR code, run `generate_qrcode.py`.
5+
6+
For instance, if you want to generate a QR code that contains the data: "https://www.thepythoncode.com" to a file named `site.png`, you can:
7+
```
8+
python generate_qrcode.py https://www.thepythoncode.com site.png
9+
```
10+
- If you want to read a QR code, run `read_qrcode.py`.
11+
12+
For instance, if you want to read a QR code from a file named `site.png`, you can run:
13+
```
14+
python read_qrcode.py site.png
15+
```
16+
A new window will appear that contains the QR code surrounded by a blue square.
17+
and **outputs**:
18+
```
19+
QRCode data:
20+
https://www.thepythoncode.com
21+
```
22+
- If you want to read QR codes live using your cam, just run:
23+
```
24+
python read_qrcode_live.py
25+
```
26+
27+
If you want to know how these are created, head to this tutorial: [How to Generate and Read QR Code in Python](https://www.thepythoncode.com/article/generate-read-qr-code-python).
Collapse file
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import qrcode
2+
import sys
3+
4+
data = sys.argv[1]
5+
filename = sys.argv[2]
6+
7+
# generate qr code
8+
img = qrcode.make(data)
9+
# save img to a file
10+
img.save(filename)
Collapse file
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import cv2
2+
import sys
3+
4+
filename = sys.argv[1]
5+
6+
# read the QRCODE image
7+
img = cv2.imread(filename)
8+
9+
# initialize the cv2 QRCode detector
10+
detector = cv2.QRCodeDetector()
11+
12+
# detect and decode
13+
data, bbox, straight_qrcode = detector.detectAndDecode(img)
14+
15+
# if there is a QR code
16+
if bbox is not None:
17+
print(f"QRCode data:\n{data}")
18+
# display the image with lines
19+
# length of bounding box
20+
n_lines = len(bbox)
21+
for i in range(n_lines):
22+
# draw all lines
23+
point1 = tuple(bbox[i][0])
24+
point2 = tuple(bbox[(i+1) % n_lines][0])
25+
cv2.line(img, point1, point2, color=(255, 0, 0), thickness=2)
26+
27+
28+
29+
# display the result
30+
cv2.imshow("img", img)
31+
cv2.waitKey(0)
32+
cv2.destroyAllWindows()
Collapse file
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import cv2
2+
3+
# initalize the cam
4+
cap = cv2.VideoCapture(0)
5+
6+
# initialize the cv2 QRCode detector
7+
detector = cv2.QRCodeDetector()
8+
9+
while True:
10+
_, img = cap.read()
11+
12+
# detect and decode
13+
data, bbox, _ = detector.detectAndDecode(img)
14+
15+
# check if there is a QRCode in the image
16+
if bbox is not None:
17+
# display the image with lines
18+
for i in range(len(bbox)):
19+
# draw all lines
20+
cv2.line(img, tuple(bbox[i][0]), tuple(bbox[(i+1) % len(bbox)][0]), color=(255, 0, 0), thickness=2)
21+
22+
if data:
23+
print("[+] QR Code detected, data:", data)
24+
25+
# display the result
26+
cv2.imshow("img", img)
27+
28+
if cv2.waitKey(1) == ord("q"):
29+
break
30+
31+
cap.release()
32+
cv2.destroyAllWindows()
33+
Collapse file
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
opencv-python
2+
qrcode
Collapse file
698 Bytes
  • Display the source diff
  • Display the rich diff
Loading
Collapse file

‎machine-learning/face_detection/live_face_detection.py‎

Copy file name to clipboardExpand all lines: machine-learning/face_detection/live_face_detection.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
cap = cv2.VideoCapture(0)
55

66
# initialize the face recognizer (default face haar cascade)
7-
face_cascade = cv2.CascadeClassifier("cascades/haarcascade_fontalface_default.xml")
7+
face_cascade = cv2.CascadeClassifier("C:/Users/STRIX/Desktop/vscodes/repos/pythoncode-tutorials/machine-learning/face_detection/cascades/haarcascade_fontalface_default.xml")
88

99
while True:
1010
# read the image from the cam

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.