import os
import cv2
# 此字符表用于生字符帧,对应256个像素,字符越多且不同样式,字符帧越精细
str_table = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@#$%^&*~()_=|"
# 读取视频
video = cv2.VideoCapture('CSQ.mp4')
# 读取帧
ret, frame = video.read()
while ret: # 逐帧读取
# 用于装饰字符画
str_img = ""
# 灰度转换
grey_img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# 缩小图像
small_grey_img = cv2.resize(grey_img, (150, 50))
# 遍历每一个像素
for i in small_grey_img:
for j in i:
index = int(j / 256 * len(str_table))
str_img += str_table[index]
str_img += "\n"
os.system("cls")
print(str_img)
# 读取下一帧
ret, frame = video.read()
# 等待
# cv2.waitKey(1)
参考文章:https://www.jb51.net/article/184553.htm
网友评论