資源簡介
圖片和視頻轉ASCII碼,輸出圖片或視頻
代碼片段和文件信息
“““
python?Video&Image2Text.py?file_name?[-color]
“““
import?os
import?cv2
import?sys
import?numpy?as?np
from?PIL?import?Image
from?PIL?import?ImageDraw
from?PIL?import?ImageFont
import?time
chars?=?‘#@&%x*^.?‘
color?=?False
def?handle_one_frame(img):
????start?=?time.time()
????img?=?img.convert(‘L‘)?if?not?color?else?img??#?convert?to?gray?if?color?is?False.
????img?=?np.array(img)
????width?=?img.shape[1]
????height?=?img.shape[0]
????output_img?=?Image.new(mode?=?‘RGB‘?if?color?else?‘L‘?size?=?(width?height)
???????????????????????????color?=?(255?255?255)?if?color?else?(255))??#?use?‘1‘?rather?than?‘L‘?is?more?clear.
????draw?=?ImageDraw.Draw(output_img)??#?to?write?text?to?image.
????font?=?ImageFont.truetype(font?=?‘segoeui.ttf‘?size?=?13?if?col
- 上一篇:基于遷移學習的識別交通標志(python)
- 下一篇:python 串口讀寫
評論
共有 條評論