将自己学的贴一下

import base64
import tkinter as mytk
import tkinter.filedialog as dialog
import requests
from PIL import Image, ImageTk  # pip install pillow
from PIL.Image import Resamplingwindow = mytk.Tk()  # 实例化对象imgpath = mytk.StringVar()def get_imgpath():files_img_path = dialog.askopenfilename(title='选择图片', initialdir='.',filetypes=(('图像文件', '*.jpg;*.jpeg;*.bmp;*.png'), ('所有文件', '*.*')))if files_img_path == ' ':passelse:imgpath.set(files_img_path)image = Image.open(files_img_path)img_re = image.resize((240, 320), Resampling.BILINEAR)img = ImageTk.PhotoImage(img_re)canvas.create_image(0, 0, image=img, anchor=mytk.NW)canvas.image = imgdef get_carton():img_path = text1.get()if img_path == '':passelse:with open(img_path, 'rb') as fp:imgdata = base64.b64encode(fp.read())# 编码为base64格式二进制文件'''获取属于你自己的访问令牌(access_token)需要API Key和Secret Key,在官网获取,包含在host内'''host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id' \'=your API Key&client_secret=your Secret Key'response = requests.get(host)access_token = response.json()['access_token']request_url = "https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime"params = {"image": imgdata}request_url = request_url + "?access_token=" + access_tokenheaders = {'content-type': 'application/x-www-form-urlencoded'}response = requests.post(request_url, data=params, headers=headers)  # 将图片包含进表单内提交data_json = response.json()  # 获取json文件print('获取到json')img_base = data_json['image']  # 提取返回的图片print('获取到编码')img_res = base64.b64decode(img_base)  # 解码图片print('正在创建画布')with open('D:\Scrapy\\' + img_path.split('/')[-1], 'wb') as file:  # 解码的图片写入到文件夹file.write(img_res)file.close()new_img = Image.open('D:\Scrapy\\' + img_path.split('/')[-1])new_img = new_img.resize((240, 320), Image.BILINEAR)  # 尺寸调整out_img = ImageTk.PhotoImage(new_img)canvas2.create_image(0, 0, image=out_img, anchor=mytk.NW)canvas2.image = out_img  # 在第二张画布输出图片# 主窗口
window.title("获取你的动漫脸")
sc_wid = window.winfo_screenwidth()  # 1536
sc_heig = window.winfo_screenheight()  # 864
win_wid, win_heig = 800, 450
init_x = (sc_wid - win_wid) / 2  # 368
init_y = (sc_heig - win_heig) / 2  # 207
window.geometry('%dx%d+%d+%d' % (win_wid, win_heig, init_x, init_y))# 按键
button1 = mytk.Button(window, text='载入图片', font=('微软雅黑', 12, 'bold'), command=get_imgpath)
button1.place(x=2, y=3)
text1 = mytk.Entry(window, textvariable=imgpath, font=('微软雅黑', 12, 'bold'), width=35)
text1.place(x=150, y=3)
button2 = mytk.Button(window, text='开始生成', font=('微软雅黑', 12, 'bold'), command=get_carton)
button2.place(x=500, y=3)# 画布
canvas = mytk.Canvas(window, width=240, height=320)
canvas.place(x=150, y=100)
canvas2 = mytk.Canvas(window, width=240, height=320)
canvas2.place(x=400, y=100)window.mainloop()  # 持续运行

调用百度API实现漫画脸生成相关推荐

  1. 百度api 人物漫画脸

    百度ai开放平台 文档地址 导入依赖 <dependencies><dependency><groupId>com.baidu.aip</groupId> ...

  2. Java调用百度API生成短网址

    由于百度短网址旧API更新,故更新下原博客内容(仅供参考),希望小伙伴们以官方API为主,以防影响使用. 官方API:https://dwz.cn/console/apidoc package com ...

  3. python aipspeech_Python调用百度API实现语音识别(二)

    咪哥杂谈 本篇阅读时间约为 5 分钟. 1 前言 上一篇文章里,大致介绍了百度官方 api 的一些前置准备工作. 想回顾的同学,可以看完本篇在下面找到历史链接. 今天就来上手实战编码,体验一下代码实现 ...

  4. mac下载的api文档怎么_Python调用百度API实现语音识别(二)

    Python调用百度API实现语音识别(二) 前言 上一篇文章里,大致介绍了百度官方 api 的一些前置准备工作. 想回顾的同学,可以看完本篇在下面找到历史链接. 今天就来上手实战编码,体验一下代码实 ...

  5. 调用百度api实现驾车路线和时间距离计算

    毕设篇:调用百度api实现驾车路线和时间距离计算 效果展示 html页面: <!DOCTYPE html> <html lang="en"><head ...

  6. java实现文本纠错功能_调用百度API进行文本纠错

    毕设做的是文本纠错方面,然后今天进组见研究生导师 .老师对我做的东西蛮感兴趣.然后介绍自己现在做的一些项目,其中有个模块需要有用到文本纠错功能. 要求1:有多人同时在线编辑文档,然后文档功能有类似Wo ...

  7. 【微信小程序调用百度API实现图像识别功能】----项目实战

    本章主要讲述: 如何更快的上手小程序 如何搭建一个页面以及跳转到另一个页面 如何调用百度API接口实现图像识别技术 如何在微信小程序的后台添加合法域名 私信获取源码,有问题可以关注留言或私信,计算机毕 ...

  8. 调用百度API 对文本进行情感倾向分析(舆情分析)

    @[TOC] # 1.准备工作 1.注册百度账号,登录百度智能云,点击总览选择自然语言处理,创建应用(创建选项认真阅读,填写) 创建好应用会生成相应的AppID API Key  Secret Key ...

  9. 调用百度API实现logo商标识别

    1.作者介绍 严松,男,西安工程大学电子信息学院,2022级研究生 研究方向:机器人抓取检测 电子邮件:2448052777@qq.com 2.百度API实现logo商标识别接口介绍 该请求用于检测和 ...

最新文章

  1. JS获取系统时间--JavaScript基础
  2. ACM入门之【单调栈】
  3. python数独游戏源代码100行_python实现自动解数独小程序
  4. 信息学奥赛一本通 1018:其他数据类型存储空间大小 | OpenJudge NOI 1.2 03
  5. oracle下的inventory文件夹,oracle INVENTORY 详解
  6. Django里面的sql查询语句
  7. linux oracle 删除为空的dbf,Linux上Oracle误删除一个没有用的dbf表空间文件
  8. 常用的Linux命令行文本处理工具总结
  9. canvas.clipPath canvas.clipRect() 无效的原因
  10. 分享大三改进后的python写的【银行管理系统】,超详细 【内附源码】
  11. ps界面为啥突然变大了_PS如何用快速蒙版抠图,超实用的技巧!!!
  12. html5课件动画制作,ppt如何制作课件动画
  13. Ticket Lock的Relaxed Atomics优化
  14. 这家山炮公司,居然让腾讯又有了梦想!?
  15. linux 配置局域网内部www服务器,局域网内部邮件服务器搭建方法
  16. InsecureProgramming-master——abo3
  17. 自己写的一点福利代码(三)
  18. 不动点迭代 开平方 Excel演示
  19. 优酷视频如何登录优酷账号?
  20. 服务端高并发分布式架构演进

热门文章

  1. 如何使用Midjourney自己设计独特的Logo,常用的提示和使用效果展示(内附Midjourney提示词网站)
  2. win10自带邮箱和网易邮箱的同步问题
  3. css实现海浪动效,这是最简单的实现方式了!
  4. 使firefox默认在新的标签页打开书签
  5. 百分之九十的人玩《荒野行动》竟然都是为了匹配日本人?
  6. CES 2018:2020年,三星将在其所有设备上安装人工智能
  7. a8三星手机android,三星A5更名A8 2018,将搭载骁龙660,运行安卓7.1.1
  8. 基于物理的渲染(PBR)白皮书 | 迪士尼原则的BRDF与BSDF相关总结
  9. 说说如何实现不清理微信缓存,就能看到实时更新的页面
  10. spark wordcount函数解析