鱼C论坛

 找回密码
 立即注册
查看: 3623|回复: 0

[学习笔记] python 视频转字符画 大佬们多多指教

[复制链接]
发表于 2020-8-12 20:24:11 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. from PIL import Image

  2. codeLib = '''...................................................................  '''
  3. count = len(codeLib)
  4. print(count)

  5. def transform(image_file):
  6.     image_file.convert("L")
  7.     codePic = ''
  8.     for h in range(0,image_file.size[1]):  
  9.        for w in range(0,image_file.size[0]):
  10.            gray = image_file.getpixel((w,h))  
  11.            #print(gray)
  12.            gray1=int((gray[0]+gray[1]+gray[2])/3)
  13.            #print(gray1)
  14.             #映射
  15.            if gray1<150:
  16.                 codePic=codePic+codeLib[0]
  17.            else:
  18.                 codePic=codePic+codeLib[68]
  19.            
  20.            #codePic = codePic + codeLib[int((count*gray1)/256)]
  21.            codePic=codePic+'  '
  22.        codePic = codePic + '\n'
  23.     print(codePic)
  24.     return codePic
  25.             
  26. fp = open('3.jpg','rb')
  27. image_file = Image.open(fp)
  28. image_file =image_file.resize((int(image_file.size[0]*0.2),int(image_file.size[1]*0.2)))
  29. text = transform(image_file)
  30. tmp = open(r'C:\Users\acer\Desktop\Python案例\Alan.txt','w')
  31. tmp.write(text)
  32. tmp.close()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-1 02:48

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表