zoukankan      html  css  js  c++  java
  • badapple制作

    badapple制作

    1. 原版视频的抽帧,生成每一帧的图像
    2. 图像专制为字符文档
    3. 在控制台实现输出

    用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 += '
    '
    	#清屏
    	os.system('cls')
    	#输出生成的字符画
    	print(text)
    

  • 相关阅读:
    PCRE
    [转]如何解决严重的拖延症
    linux系统编程:setjmp和longjmp函数用法
    AWK中几个变量
    关于fork函数
    go mod
    golang+read_file+call_shell+goroutine
    vim for galang
    Linux install go
    为Git branch 打Tag
  • 原文地址:https://www.cnblogs.com/serendipity-my/p/12914792.html
Copyright © 2011-2022 走看看