python安装百度aip_PIL+百度aip

1.PIL模块安装

选择PIL

官方没有支持python3.6的PIL库,所以用pillow代替

http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow

链接:https://pan.baidu.com/s/1kW3BuzP 密码:4o66

windows 64位 python36:选择Pillow?4.2.0?cp36?cp36m?win_amd64.whl下载,保存在Scripts文件夹下

然后在~\Python36\Scripts目录下按Shift+鼠标右键,选择【在此处打开命令窗口】输入命令:

先升级pip

python -m pip install --upgrade pip

安装PIL模块

pip install Pillow-4.1.0-cp36-cp36m-win64.whl

pillow配置完成后可以导入pillow模块使用

import Image, ImageFilter, ImageDraw, ImageFont, ImageEnhance, ImageFilter

高级用法:https://www.cnblogs.com/jeffkuang/articles/4859158.html

2.百度aip模块安装

pip install baidu_aip

3.安装colorama模块

pip install colorama

简单使用:https://www.cnblogs.com/xieshengsen/p/6932233.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一份简单的Python百度aip港澳通行证识别的Tkinter代码: ```python from tkinter import * from tkinter import filedialog from tkinter import messagebox from PIL import Image, ImageTk from aip import AipOcr # 百度aip的APP ID、API Key、Secret Key APP_ID = 'your_app_id' API_KEY = 'your_api_key' SECRET_KEY = 'your_secret_key' # 初始化AipOcr对象 client = AipOcr(APP_ID, API_KEY, SECRET_KEY) # 创建Tkinter窗口 root = Tk() root.title("港澳通行证识别") # 添加文件选择按钮 def select_image(): file_path = filedialog.askopenfilename() image = Image.open(file_path) image = image.resize((300, 450)) photo = ImageTk.PhotoImage(image) panel.configure(image=photo) panel.image = photo # 港澳通行证识别 result = recognize(image) messagebox.showinfo("识别结果", result) def recognize(image): # 转成base64编码 img_byte_arr = BytesIO() image.save(img_byte_arr, format='PNG') img_byte_arr = img_byte_arr.getvalue() img = base64.b64encode(img_byte_arr).decode('utf-8') # 识别 try: result = client.basicAccurate(img) words = result['words_result'] name = words['姓名']['words'] card_num = words['证件号码']['words'] return f"姓名: {name}\n证件号码: {card_num}" except: return "识别失败!" panel = Label(root) panel.pack(padx=10, pady=10) btn = Button(root, text="选择图片", command=select_image) btn.pack(padx=10, pady=10) root.mainloop() ``` 需要注意的是,要先安装必要的依赖库,包括Tkinter、Pillow、baidu-aip。此外,还需要在百度aip平台上申请APP ID、API Key和Secret Key,并将它们替换到代码中的`your_app_id`、`your_api_key`和`your_secret_key`处。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值