-
Python二维码生成
2018-05-29 13:11:01Python生成二维码的代码,包括在二维码中加logo与不加lago -
python二维码生成
2017-10-24 11:46:54使用前,需要qrcode库,还需要PIL库,这是一个非常简单的生成方式 -
python 二维码生成
2020-10-19 10:06:38import qrcode qr=qrcode.QRCode(version = 2,error_correction = qrcode.constants.ERROR_CORRECT_L,box_size=10,border=10,) qr.add_data('显示的文本内容') qr.make(fit=True) img = qr.make_image() ...import qrcode qr=qrcode.QRCode(version = 2,error_correction = qrcode.constants.ERROR_CORRECT_L,box_size=10,border=10,) qr.add_data('显示的文本内容') qr.make(fit=True) img = qr.make_image() img.show() #img.save('D:/test.jpg')
-
Python二维码生成识别实例详解
2020-09-19 01:22:34主要介绍了Python二维码生成识别实例详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 -
python二维码生成带logo
2015-07-01 14:22:44python二维码生成带logo import qrcode qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data('Some data') qr.make(fit=True) ... -
Python二维码生成解码
2021-04-12 00:41:41Python制作二维码,需要安装依赖库都是pip,可以简单的生成解码+带有中间logo的生成 -
python二维码生成器
2018-12-13 20:38:50本资源为一个基于python的二维码生成器,只要用到qrcode这个库,界面UI主要采用pyqt5,感兴趣的话,可以下载参考一下。 -
python二维码生成识别代码_Python学习案例之二维码生成识别
2020-11-29 05:51:32前言在 JavaWeb 开发中,一般使用 Zxing 来生成和识别二维码,但是,Zxing 的识别有点差强人意,不少相对模糊的二维码识别率很低。不过就最新版本的测试来说,识别率有了现显著提高。对比在没接触 Python 之前,曾...前言
在 JavaWeb 开发中,一般使用 Zxing 来生成和识别二维码,但是,Zxing 的识别有点差强人意,不少相对模糊的二维码识别率很低。不过就最新版本的测试来说,识别率有了现显著提高。
对比
在没接触 Python 之前,曾使用 Zbar 的客户端进行识别,测了大概几百张相对模糊的图片,Zbar的识别速度要快很多,识别率也比 Zxing 稍微准确那边一丢丢,但是,稍微模糊一点就无法识别。相比之下,微信和支付宝的识别效果就逆天了。
代码案例
# -*- coding:utf-8 -*-
import os
import qrcode
import time
from PIL import Image
from pyzbar import pyzbar
"""
# 升级 pip 并安装第三方库
pip install -U pip
pip install Pillow
pip install pyzbar
pip install qrcode
"""
def make_qr_code_easy(content, save_path=None):
"""
Generate QR Code by default
:param content: The content encoded in QR Codeparams
:param save_path: The path where the generated QR Code image will be saved in.
If the path is not given the image will be opened by default.
"""
img = qrcode.make(data=content)
if save_path:
img.save(save_path)
else:
img.show()
def make_qr_code(content, save_path=None):
"""
Generate QR Code by given params
:param content: The content encoded in QR Code
:param save_path: The path where the generated QR Code image will be saved in.
If the path is not given the image will be opened by default.
"""
qr_code_maker = qrcode.QRCode(version=2,
error_correction=qrcode.constants.ERROR_CORRECT_M,
box_size=8,
border=1,
)
qr_code_maker.add_data(data=content)
qr_code_maker.make(fit=True)
img = qr_code_maker.make_image(fill_color="black", back_color="white")
if save_path:
img.save(save_path)
else:
img.show()
def make_qr_code_with_icon(content, icon_path, save_path=None):
"""
Generate QR Code with an icon in the center
:param content: The content encoded in QR Code
:param icon_path: The path of icon image
:param save_path: The path where the generated QR Code image will be saved in.
If the path is not given the image will be opened by default.
:exception FileExistsError: If the given icon_path is not exist.
This error will be raised.
:return:
"""
if not os.path.exists(icon_path):
raise FileExistsError(icon_path)
# First, generate an usual QR Code image
qr_code_maker = qrcode.QRCode(version=4,
error_correction=qrcode.constants.ERROR_CORRECT_H,
box_size=8,
border=1,
)
qr_code_maker.add_data(data=content)
qr_code_maker.make(fit=True)
qr_code_img = qr_code_maker.make_image(fill_color="black", back_color="white").convert('RGBA')
# Second, load icon image and resize it
icon_img = Image.open(icon_path)
code_width, code_height = qr_code_img.size
icon_img = icon_img.resize((code_width // 4, code_height // 4), Image.ANTIALIAS)
# Last, add the icon to original QR Code
qr_code_img.paste(icon_img, (code_width * 3 // 8, code_width * 3 // 8))
if save_path:
qr_code_img.save(save_path)
else:
qr_code_img.show()
def decode_qr_code(code_img_path):
"""
Decode the given QR Code image, and return the content
:param code_img_path: The path of QR Code image.
:exception FileExistsError: If the given code_img_path is not exist.
This error will be raised.
:return: The list of decoded objects
"""
if not os.path.exists(code_img_path):
raise FileExistsError(code_img_path)
# Here, set only recognize QR Code and ignore other type of code
return pyzbar.decode(Image.open(code_img_path), symbols=[pyzbar.ZBarSymbol.QRCODE], scan_locations=True)
if __name__ == "__main__":
# # 简易版
# make_qr_code_easy("make_qr_code_easy", "make_qr_code_easy.png")
# results = decode_qr_code("make_qr_code_easy.png")
# if len(results):
# print(results[0].data.decode("utf-8"))
# else:
# print("Can not recognize.")
#
# # 参数版
# make_qr_code("make_qr_code", "make_qr_code.png")
# results = decode_qr_code("make_qr_code.png")
# if len(results):
# print(results[0].data.decode("utf-8"))
# else:
# print("Can not recognize.")
#
# 带中间 logo 的
# make_qr_code_with_icon("https://blog.52itstyle.vip", "icon.jpg", "make_qr_code_with_icon.png")
# results = decode_qr_code("make_qr_code_with_icon.png")
# if len(results):
# print(results[0].data.decode("utf-8"))
# else:
# print("Can not recognize.")
# 识别答题卡二维码 16 识别失败
t1 = time.time()
count = 0
for i in range(1, 33):
results = decode_qr_code(os.getcwd()+"\\img\\"+str(i)+".png")
if len(results):
print(results[0].data.decode("utf-8"))
else:
print("Can not recognize.")
count += 1
t2 = time.time()
print("识别失败数量:" + str(count))
print("测试时间:" + str(int(round(t2 * 1000))-int(round(t1 * 1000))))
测试了32张精挑细选的模糊二维码:
识别失败数量:1
测试时间:130
使用最新版的 Zxing 识别失败了三张。
源码
-
python二维码生成模块_详解 Python qrcode 二维码模块
2020-12-02 23:26:02 -
python解析二维码_Python二维码生成识别实例详解
2020-11-21 03:30:29前言在 JavaWeb 开发中,一般使用 Zxing 来生成和识别二维码,但是,Zxing 的识别有点差强人意,不少相对模糊的二维码识别率很低。不过就最新版本的测试来说,识别率有了现显著提高。对比在没接触 Python 之前,曾...前言
在 JavaWeb 开发中,一般使用 Zxing 来生成和识别二维码,但是,Zxing 的识别有点差强人意,不少相对模糊的二维码识别率很低。不过就最新版本的测试来说,识别率有了现显著提高。
对比
在没接触 Python 之前,曾使用 Zbar 的客户端进行识别,测了大概几百张相对模糊的图片,Zbar的识别速度要快很多,识别率也比 Zxing 稍微准确那边一丢丢,但是,稍微模糊一点就无法识别。相比之下,微信和支付宝的识别效果就逆天了。
代码案例
# -*- coding:utf-8 -*-
import os
import qrcode
import time
from PIL import Image
from pyzbar import pyzbar
"""
# 升级 pip 并安装第三方库
pip install -U pip
pip install Pillow
pip install pyzbar
pip install qrcode
"""
def make_qr_code_easy(content, save_path=None):
"""
Generate QR Code by default
:param content: The content encoded in QR Codeparams
:param save_path: The path where the generated QR Code image will be saved in.
If the path is not given the image will be opened by default.
"""
img = qrcode.make(data=content)
if save_path:
img.save(save_path)
else:
img.show()
def make_qr_code(content, save_path=None):
"""
Generate QR Code by given params
:param content: The content encoded in QR Code
:param save_path: The path where the generated QR Code image will be saved in.
If the path is not given the image will be opened by default.
"""
qr_code_maker = qrcode.QRCode(version=2,
error_correction=qrcode.constants.ERROR_CORRECT_M,
box_size=8,
border=1,
)
qr_code_maker.add_data(data=content)
qr_code_maker.make(fit=True)
img = qr_code_maker.make_image(fill_color="black", back_color="white")
if save_path:
img.save(save_path)
else:
img.show()
def make_qr_code_with_icon(content, icon_path, save_path=None):
"""
Generate QR Code with an icon in the center
:param content: The content encoded in QR Code
:param icon_path: The path of icon image
:param save_path: The path where the generated QR Code image will be saved in.
If the path is not given the image will be opened by default.
:exception FileExistsError: If the given icon_path is not exist.
This error will be raised.
:return:
"""
if not os.path.exists(icon_path):
raise FileExistsError(icon_path)
# First, generate an usual QR Code image
qr_code_maker = qrcode.QRCode(version=4,
error_correction=qrcode.constants.ERROR_CORRECT_H,
box_size=8,
border=1,
)
qr_code_maker.add_data(data=content)
qr_code_maker.make(fit=True)
qr_code_img = qr_code_maker.make_image(fill_color="black", back_color="white").convert('RGBA')
# Second, load icon image and resize it
icon_img = Image.open(icon_path)
code_width, code_height = qr_code_img.size
icon_img = icon_img.resize((code_width // 4, code_height // 4), Image.ANTIALIAS)
# Last, add the icon to original QR Code
qr_code_img.paste(icon_img, (code_width * 3 // 8, code_width * 3 // 8))
if save_path:
qr_code_img.save(save_path)
else:
qr_code_img.show()
def decode_qr_code(code_img_path):
"""
Decode the given QR Code image, and return the content
:param code_img_path: The path of QR Code image.
:exception FileExistsError: If the given code_img_path is not exist.
This error will be raised.
:return: The list of decoded objects
"""
if not os.path.exists(code_img_path):
raise FileExistsError(code_img_path)
# Here, set only recognize QR Code and ignore other type of code
return pyzbar.decode(Image.open(code_img_path), symbols=[pyzbar.ZBarSymbol.QRCODE], scan_locations=True)
if __name__ == "__main__":
# # 简易版
# make_qr_code_easy("make_qr_code_easy", "make_qr_code_easy.png")
# results = decode_qr_code("make_qr_code_easy.png")
# if len(results):
# print(results[0].data.decode("utf-8"))
# else:
# print("Can not recognize.")
#
# # 参数版
# make_qr_code("make_qr_code", "make_qr_code.png")
# results = decode_qr_code("make_qr_code.png")
# if len(results):
# print(results[0].data.decode("utf-8"))
# else:
# print("Can not recognize.")
#
# 带中间 logo 的
# make_qr_code_with_icon("https://blog.52itstyle.vip", "icon.jpg", "make_qr_code_with_icon.png")
# results = decode_qr_code("make_qr_code_with_icon.png")
# if len(results):
# print(results[0].data.decode("utf-8"))
# else:
# print("Can not recognize.")
# 识别答题卡二维码 16 识别失败
t1 = time.time()
count = 0
for i in range(1, 33):
results = decode_qr_code(os.getcwd()+"\\img\\"+str(i)+".png")
if len(results):
print(results[0].data.decode("utf-8"))
else:
print("Can not recognize.")
count += 1
t2 = time.time()
print("识别失败数量:" + str(count))
print("测试时间:" + str(int(round(t2 * 1000))-int(round(t1 * 1000))))
测试了32张精挑细选的模糊二维码:
识别失败数量:1
测试时间:130
使用最新版的 Zxing 识别失败了三张。
源码
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
-
python二维码生成模块_python之qrcode模块生成二维码
2020-12-08 01:43:47用Python的qrcode包来生成二维码很简单一、前期准备:pip install qrcodeqrcode 依赖 Image 这个包:pip install Image二、安装好之后就可以通过代码实现二维码了- 1. 简单生成二维码:import qrcode //模块导入//... -
Python二维码生成库qrcode安装和使用示例
2020-12-25 01:18:45由于生成 qrcode 图片需要依赖 Python 的图像库,所以需要先安装 Python 图像库 PIL(Python Imaging Library),不然会遇到 “ImportError: No module named Image” 的错误: 复制代码 代码如下: sudo -
Python二维码生成器
2020-07-11 11:58:42但想要生成自己的二维码又非常麻烦,需要用别人的软件,这些很多不可靠甚至有病毒,所以作为技术人员的我们还是要靠自己 先说一下二维码的原理 二维码的原理是二进制运算,总的来说,二维码利用二进制的0和1作为... -
python二维码生成模块_Python使用QRCode模块生成二维码实例详解
2020-12-02 23:26:02Python使用QRCode模块生成...简介python-qrcode是个用来生成二维码图片的第三方模块,依赖于 PIL 模块和 qrcode 库。简单用法import qrcodeimg = qrcode.make('hello, qrcode')img.save('test.png')高级用法imp... -
python 二维码生成图片
2021-02-18 11:16:021、python环境 2、涉及到的python库需要 pip install 包名 安装 pip install pillow 二、效果图展示 完整代码: # coding = utf-8 import random,string,sys,math from PIL import Image,ImageDraw,ImageFont,...