python识别二维码。获取二维码中的网页链接

方法一:
#读取图像

imgs = cv2.imread(‘图片地址')

#解码

QR_code = decode(imgs)

此处的decode函数需要额外导入,from pyzbar.pyzbar import decode,导入decode包,需要下载动态链接库:https://download.microsoft.com/download/F/3/5/F3500770-8A08-488E-94B6-17A1E1DD526F/vcredist_x64.exe
输出展示:

[Decoded(data=b'http://weixin.qq.com/q/02WVJAQnled7i1y9d7hA18', type='QRCODE', rect=Rect(left=568, top=307, width=256, height=256), polygon=[Point(x=568, y=307), Point(x=568, y=563), Point(x=824, y=563), Point(x=824, y=307)], quality=1, orientation='UP')]

函数会给我们返回二维码中含有的网页链接和二维码的参数
这里data中的网页链接不能直接返回,因为是以字节的形式存储的

for i in QR_code:
    QR_data = i.data.decode('utf-8')

方法二:
是我在某个教学视频里学到的

imgs = cv2.imread(图片地址)
qrcode = cv2.QRCodeDetector()
result,point,code = qrcode.detectAndDecode(imgs)
qrcode.detectAndDecode(imgs)
 print(result,point,code)

返回的result是网页地址,其余的两个是二维码的顶点参数,后面两个参数返回的是两个矩阵

猜你喜欢

转载自blog.csdn.net/weixin_44052130/article/details/130662018
今日推荐