1
【OpenCV4】二维码
source link: https://www.guofei.site/2022/11/05/cv4.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
版权声明:本文作者是郭飞。转载随意,但需要标明原文链接,并通知本人
原文链接:https://www.guofei.site/2022/11/05/cv4.html
生成二维码
https://github.com/lincolnloop/python-qrcode
import qrcode
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data('信息')
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
img.save("img.png")
读取二维码:opencv
# -*-coding:utf-8 -*-
import cv2 as cv
import numpy as np
src_image = cv.imread("./img.png")
qrcode = cv.QRCodeDetector()
# qr检测并解码
msg, points, straight_qrcode = qrcode.detectAndDecode(src_image)
# 绘制qr检测到的边框
cv.drawContours(src_image, [np.int32(points)], 0, (0, 0, 255), 2)
print("points", points)
# 打印解码结果
print("qrcode :", msg)
cv.imshow("result", src_image)
cv.waitKey(0)
- 对拍照之类的都能准确定位边框
- 某些系统产出的二维码无法提取信息(但边框检测还是可以准确定位)
您的支持将鼓励我继续创作!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK