資源簡介
要用命令行開o(寫給小白)
代碼片段和文件信息
import?sys
import?os
import?time
import?threading
import?cv2
import?pyprind
class?Charframe:
????ascii_char?=?“$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:\“^‘‘.?“
????#?像素映射到字符
????def?pixelToChar(self?luminance):
????????return?self.ascii_char[int(luminance?/?256?*?len(self.ascii_char))]
????#?將普通幀轉為?ASCII?字符幀
????def?convert(self?img?limitSize=-1?fill=False?wrap=False):
????????if?limitSize?!=?-1?and?(img.shape[0]?>?limitSize[1]?or?img.shape[1]?>?limitSize[0]):
????????????img?=?cv2.resize(img?limitSize?interpolation=cv2.INTER_AREA)
????????ascii_frame?=?‘‘
????????blank?=?‘‘
????????if?fill:
????????????blank?+=?‘?‘?*?(limitSize[0]?-?img.shape[1])
????????if?wrap:
????????????blank?+=?‘\n‘
????????for?i?in?range(img.shape[0]):
????????????for?j?in?range(img.shape[1]):
????????????????ascii_frame?+=?self.pixelToChar(img[i?j])
????????????ascii_frame?+=?blank
????????return?ascii_frame
class?V2Char(Charframe):
????charVideo?=?[]
????timeInterval?=?0.
評論
共有 條評論