资源简介
图片和视频转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 串口读写
评论
共有 条评论