标签:alt 图片 des com mamicode badapple lis text pen
用python的opencv模块和os模块就很方便
//安装cv2模块:
pip install opencv-python
//这个慢(超时)可以用镜像
//os模块在python中属于内置模块,即不需要额外安装。
不知道为什么,闪屏
import cv2 as cv
import os
ascii_char = list("$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`‘.")
length = len(ascii_char)
#加载视频
cap = cv.VideoCapture(‘C:/Users/Vincent/Desktop/badapple.mp4‘)
while True:
#读取每一帧
hasFrame,frame = cap.read()
if not hasFrame:
break
#视频长宽
width = frame.shape[0]
height = frame.shape[1]
#转灰度图
img_gray = cv.cvtColor(frame,cv.COLOR_RGB2GRAY)
image_resize = cv.resize(img_gray,(int(width/5),int(height/15)))
text = ‘‘
#遍历图片像素点
for r in image_resize:
for pixel in r:
#根据像素值,选择对应字符
text += ascii_char[int(pixel/256*length)]
text += ‘\n‘
#清屏
os.system(‘cls‘)
#输出生成的字符画
print(text)
标签:alt 图片 des com mamicode badapple lis text pen
原文地址:https://www.cnblogs.com/serendipity-my/p/12914792.html