字符畫,一種由字母、標點、漢字或其他字符組成的圖畫。簡單的字符畫是利用字符的形狀代替圖畫的線條來構成簡單的人物、事物等形象,它一般由人工制作而成;復雜的字符畫通常利用占用不同數量像素的字符代替圖畫上不同明暗的點,它一般由程式制作而成。字符畫是互聯網時代的產物,通常應用於即時聊天中。
首先,也是最重要的,先放源碼
from PIL import Image as im from tkinter import * import cv2 # 隨便打 codeLib = '''*.1''' count = len(codeLib) def transform(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 + '\r\n' return codePic def image2char(image_file): image_file = image_file.resize((int(image_file.size[0] * 0.16), int(image_file.size[1] * 0.06))) # 調整圖片大小 return transform(image_file), image_file.size[0], image_file.size[1] def frame2image(cap, i): cap.set(cv2.CAP_PROP_POS_FRAMES, i) _, b = cap.read() image = im.fromarray(cv2.cvtColor(b, cv2.COLOR_BGR2RGB)) return image def gui(path): cap = cv2.VideoCapture(path) root = Tk() t = frame2image(cap, 0) _, w, h = image2char(t) text = Text(root, width=w, height=h) text.pack() framenum = int(cap.get(7)) for i in range(framenum): image = frame2image(cap, i) content, _, _ = image2char(image) text.insert(INSERT, content) root.update() text.删除(0.0, END) if __name__ == '__main__': gui(r'C:\Users\Administrator\Desktop\油性極大.mp4')
然後,選擇一個短視頻
最後選擇視頻的路徑,修改程式碼的档案路徑,在運行程式碼
到此這篇關於Python制作動態字符畫的源碼的文章就介紹到這瞭,更多相關Python動態字符畫內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支援!
You may also like
相关贴文:
- 教你用Python實現簡易版學生信息管理系統(含源碼) python 程式碼
- Python源碼學習之PyType Type和PyBaseObject Type詳解 python 程式碼
- Python源碼學習之PyObject和PyTypeObject python 程式碼
- 再也不用花錢買漫畫!Python爬取某漫畫的腳本及源碼 python 程式碼
- Django drf請求模塊源碼解析 python 程式碼
- 手把手教你利用opencv實現人臉識別功能(附源碼+文檔) python 程式碼
- Pytorch教程內置模型源碼實現 python 程式碼
- 關於Python dict存中文字符dumps()的問題 python 程式碼
近期文章
- WooCommerce的完美產品過濾器插件!
- 5個最佳WooCommerce SEO插件在2024年
- WooCommerce的折扣規則 – 概述視頻
- 2024年WooCommerce的5個最佳AI插件
- 使用ProductX快速建立一家商店-WordPress的最終Gutenberg WooCommerce插件
- WordPress 2024的10個最佳WooCommerce主題(嚴重)
- Shopify vs WooCommerce:最佳電子商務平台|全面的比較評論
- 您不想錯過的十大WooCommerce附加組件!
- 提高您的WooCommerce商店使用Upsell的銷售,Cross Sell | WooCommerce教程
發佈留言