qrcode模块安装

运行命令行工具(cmd),使用pip安装工具分别安装qrcode。

pip install qrcode 

先来个简单的例子

import qrcode

# 二维码内容
data = "hello world"
# 生成二维码
img = qrcode.make(data=data)
# 直接显示二维码
img.show()
# 保存二维码为文件
# img.save("hello.jpg")

效果

我们来修改配置等

import qrcode

# 二维码内容
data = "hello world" qr = qrcode.QRCode(
version=2,
error_correction=qrcode.constants.ERROR_CORRECT_L,#二维码的纠错范围
box_size=10,# 每个点(方块)中的像素个数
border=4#二维码距图像外围边框距离,默认为4,而且相关规定最小为4
) qr.add_data(data)
qr.make(fit=True) # 生成二维码
img = qr.make_image()
# 直接显示二维码
img.show()
# 保存二维码为文件
# img.save("hello.jpg")

安装pyzbar

pip install pyzbar

来测试

import pyzbar.pyzbar as pyzbar
from PIL import Image,ImageEnhance image = "hello.jpg" img = Image.open(image) #img = ImageEnhance.Brightness(img).enhance(2.0)#增加亮度 #img = ImageEnhance.Sharpness(img).enhance(17.0)#锐利化 #img = ImageEnhance.Contrast(img).enhance(4.0)#增加对比度 #img = img.convert('L')#灰度化 img.show() barcodes = pyzbar.decode(img) for barcode in barcodes:
barcodeData = barcode.data.decode("utf-8")
print(barcodeData)

测试一下

python3 + opencv +pyzbar 摄像头检测二维码并获取二维码内容

https://blog.csdn.net/zx66zx/article/details/82785334

# coding:utf8

import cv2
import pyzbar.pyzbar as pyzbar def decodeDisplay(image):
barcodes = pyzbar.decode(image)
for barcode in barcodes:
# 提取条形码的边界框的位置
# 画出图像中条形码的边界框
(x, y, w, h) = barcode.rect
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2) # 条形码数据为字节对象,所以如果我们想在输出图像上
# 画出来,就需要先将它转换成字符串
barcodeData = barcode.data.decode("utf-8")
barcodeType = barcode.type # 绘出图像上条形码的数据和条形码类型
text = "{} ({})".format(barcodeData, barcodeType)
cv2.putText(image, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
.5, (0, 0, 125), 2) # 向终端打印条形码数据和条形码类型
print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData))
return image def detect(): camera = cv2.VideoCapture(0) while True:
# 读取当前帧
ret, frame = camera.read()
# 转为灰度图像
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
im=decodeDisplay(gray) cv2.waitKey(5)
cv2.imshow("camera", im) camera.release()
cv2.destroyAllWindows() if __name__ == '__main__':
detect()

python二维码模块(qrcode)的更多相关文章

  1. python二维码操作:QRCode和MyQR入门

    1.QRCode QRCode最简单的使用 import qrcode qrcode.make("第一个二维码").get_image().show() 根据文本生成二维码并且直接 ...

  2. Python 二维码制作

    Python 二维码制作 先介绍python 二维码制作的第三方库 QRCode .MyQR QRCode    生成这个二维码只用三行 import qrcode img = qrcode.make ...

  3. jQuery生成二维码 jquery.qrcode.js

    https://github.com/jeromeetienne/jquery-qrcode 1.将jquery.qrcode.min.js和jquery添加到您的网页中 <script src ...

  4. vue2.0 自定义 生成二维码(QRCode)组件

    1.自定义 生成二维码组件 QRCode.vue <!-- 生成二维码 组件 --> <template> <canvas class="qrcode-canv ...

  5. QRCode生成二维码,jq QRCode生成二维码,QRCode生成电子名片

    [QRCode官网]http://phpqrcode.sourceforge.net/ PHP QRCode生成二维码 官网下载QRCode源码包,引入源码包中的 qrlib.php . <?p ...

  6. Python 二维码解码

    二维码解析 Python中关于二维码解析的现成模块有很多,比较著名的就是Zbar以及ZXing.然而很不幸的是,官方的版本都是支持到python2.x,下面是在python2.x的例子: import ...

  7. python 二维码

    pip3 install Pillow pip3 install qrcode import qrcode text ="gisoracle我爱你呀" #input("输 ...

  8. 二维码(QRcode)容量的计算与版本

    4.版本信息:即二维码的规格,QR码符号共有40种规格的矩阵(一般为黑白色),从21x21(版本1),到177x177(版本40),每一版本符号比前一版本每边增加4个模块. 177 = 21+(40- ...

  9. Yii 安装二维码扩展Qrcode

    比如要添加 https://github.com/2amigos/yii2-qrcode-helper 生成二维码的 这个扩展第一种方法 :    1.打开根目录的composer.json, 在re ...

随机推荐

  1. Linux shell - cut命令用法(转载)

    cut  [-bn] [file] 或 cut [-c] [file]  或  cut [-df] [file] 使用说明 cut 命令从文件的每一行剪切字节.字符和字段并将这些字节.字符和字段写至标 ...

  2. 6、Shiro之自定义realm

    1.创建一个包存放我们自定义的realm文件: 创建一个类名为CustomRealm继承AuthorizingRealm并实现父类AuthorizingRealm的方法,最后重写: CustomRea ...

  3. c++实验7 二叉树

    二叉树数据结构表示及基本操作算法实现 1.所加载的库函数或常量定义及类的定义: #include<stdlib.h> #include<stdio.h> #include&qu ...

  4. pyinstaller-python->exe

    pip install pyinstaller. pyinstaller -F /home/base64_decode.py https://www.imooc.com/article/26772 h ...

  5. C—LINQ小结

    LINQ代表语言集成查询(Language-Integrated Query),它包括用于从数据源检索信息的一组功能.数据检索是许多程序的重要组成功能. 简介:System.Linq; var num ...

  6. Delphi中TQuery.Filter用法

    今天维护一个老项目是用delphi5 + BDE写的.为了更方便查询数据,就增加一个查询功能.由于数据量查询出来后就比较少,于是就想到Filter like 但 BDE并不支持 Filter = 'n ...

  7. 【ABAP系列】SAP ABAP SY-SUBRC的含义解析

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP SY-SUBR ...

  8. Lesson 2 Thirteen equals one

    vicar 牧师 grocer 杂货铺店主 with a start 由于受到惊吓 Whtaever are you dong up here?你究竟在这上面干什么?whatever用于疑问句中,用以 ...

  9. Chapter02 第一节 开始学习C++

    2.1 进入C++ 第一个示例程序: //myfirst.cpp #include <bits/stdc++.h> using namespace std; int main() { co ...

  10. 【Qt开发】事件循环与线程 二

    事件循环与线程 二 Qt 线程类 Qt对线程的支持已经有很多年了(发布于2000年九月22日的Qt2.2引入了QThread类),Qt 4.0版本的release则对其所有所支持平台默认地是对多线程支 ...