国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

基于python實現圖片轉字符畫代碼實例

瀏覽:66日期:2022-07-12 10:59:07

直接上代碼圖片就使用我家爽妹子的吧

基于python實現圖片轉字符畫代碼實例

如果沒有安裝pil模塊的話先cmd安裝下

輸入:pip install pillow

# -*- coding: utf-8 -*-from PIL import ImagecodeLib = ’’’@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/|()1{}[]?-_+~<>i!lI;:,'^`’. ’’’#生成字符畫所需的字符集count = len(codeLib)def transform1(image_file): image_file = image_file.convert('L')#轉換為黑白圖片,參數'L'表示黑白模式 codePic = ’’ for h in range(0,image_file.size[1]): #size屬性表示圖片的分辨率,’0’為橫向大小,’1’為縱向 for w in range(0,image_file.size[0]): gray = image_file.getpixel((w,h)) #返回指定位置的像素,如果所打開的圖像是多層次的圖片,那這個方法就返回一個元組 codePic = codePic + codeLib[int(((count-1)*gray)/256)]#建立灰度與字符集的映射 codePic = codePic+’rn’ return codePicdef transform2(image_file): codePic = ’’ for h in range(0,image_file.size[1]): for w in range(0,image_file.size[0]): g,r,b = image_file.getpixel((w,h)) gray = int(r* 0.299+g* 0.587+b* 0.114) codePic = codePic + codeLib[int(((count-1)*gray)/256)] codePic = codePic+’rn’ return codePicfp = open(r’C:路徑3.jpg’,’rb’)image_file = Image.open(fp)image_file=image_file.resize((int(image_file.size[0]*0.2), int(image_file.size[1]*0.1)))#調整圖片大小print (u’Info:’,image_file.size[0],’ ’,image_file.size[1],’ ’,count)tmp = open(’tmp.txt’,’w’)tmp.write(transform1(image_file))tmp.close()a,b,c=1,2,3print(a,b,c)

結果不知還能否看出來

基于python實現圖片轉字符畫代碼實例

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 江口县| 汾阳市| 新乐市| 宝丰县| 无锡市| 祥云县| 犍为县| 余江县| 澄江县| 城步| 湖南省| 光泽县| 合山市| 富民县| 尼玛县| 冷水江市| 汪清县| 瑞金市| 葵青区| 金阳县| 浦北县| 江川县| 偏关县| 宁河县| 英山县| 灵寿县| 隆安县| 芜湖市| 教育| 泉州市| 津南区| 奇台县| 嘉禾县| 泽普县| 新昌县| 富阳市| 宝应县| 大名县| 邵阳县| 牡丹江市| 吉林省|