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

Sign up
Appearance settings

Commit 603a7ef

Browse files
committed
二维码识别器
1 parent 2a1e5e4 commit 603a7ef

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

‎my10-识别二维码/QR_Scaner1.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2018年12月31日 18:35
3+
# @Author : play4fun
4+
# @File : QR_Scaner1.py
5+
# @Software: PyCharm
6+
7+
"""
8+
QR_Scaner1.py:
9+
"""
10+
11+
from pyzbar.pyzbar import decode
12+
# from PIL import Image
13+
import cv2
14+
15+
16+
def main():
17+
fp = 'macbookPro.jpg'
18+
# img = Image.open(fp)
19+
# img.show()
20+
image = cv2.imread(fp)
21+
barcodes = decode(image)
22+
decoded = barcodes[0]
23+
print(decoded)
24+
#
25+
url: bytes = decoded.data
26+
url = url.decode()
27+
print(url)
28+
# rect
29+
rect = decoded.rect
30+
print(rect) # Rect(left=19, top=19, width=292, height=292)
31+
32+
# loop over the detected barcodes
33+
for barcode in barcodes:
34+
# extract the bounding box location of the barcode and draw the
35+
# bounding box surrounding the barcode on the image
36+
(x, y, w, h) = barcode.rect
37+
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)
38+
39+
# the barcode data is a bytes object so if we want to draw it on
40+
# our output image we need to convert it to a string first
41+
barcodeData = barcode.data.decode("utf-8")
42+
barcodeType = barcode.type
43+
44+
# draw the barcode data and barcode type on the image
45+
text = "{} ({})".format(barcodeData, barcodeType)
46+
cv2.putText(image, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
47+
0.5, (0, 0, 255), 2)
48+
49+
# print the barcode type and data to the terminal
50+
print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData))
51+
52+
# show the output image
53+
cv2.imshow("Image", image)
54+
cv2.imwrite('macbook_qr_rect.jpg', image)
55+
cv2.waitKey(0) # 按任意键退出
56+
57+
58+
if __name__ == '__main__':
59+
main()

‎my10-识别二维码/macbookPro.jpg

719 Bytes
Loading[フレーム]
43.9 KB
Loading[フレーム]

‎my10-识别二维码/创建二维码.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
# 创建二维码
3+
4+
- 参考
5+
- https://github.com/lincolnloop/python-qrcode
6+
- [使用Python的库qrcode生成二维码](https://www.jianshu.com/p/b4b14e314b2a)
7+
8+
- 安装
9+
- pip install qrcode[pil]
10+
11+
- 创建
12+
```python
13+
import qrcode
14+
15+
url='https://item.jd.com/7842699.html'
16+
img = qrcode.make(url, border=6)
17+
img.save('macbookPro.jpg')
18+
19+
```
20+
21+
-
22+
```bash
23+
qr 'Some data' > test.png
24+
```

‎my10-识别二维码/识别二维码.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## my10-识别二维码
2+
3+
- 参考
4+
- https://github.com/NaturalHistoryMuseum/pyzbar
5+
- [用ZBar做OpenCV识别器-条形码+二维码](https://www.pyimagesearch.com/2018/05/21/an-opencv-barcode-and-qr-code-scanner-with-zbar/)
6+
7+
- 安装
8+
- 安装 ZBar
9+
- Ubuntu
10+
- sudo apt-get install libzbar0
11+
- macOS Mojave
12+
- brew install zbar
13+
- pip install pyzbar

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /