当前位置:网站首页>我用字符画出了一个谷爱凌!
我用字符画出了一个谷爱凌!
2022-07-27 08:11:00 【51CTO】
之前经常在网上看到那种由一个个字符构成的视频,非常炫酷。一直不懂是怎么做的,这两天研究了一下,发现并不难。
先来看一个最终效果(如果模糊的话,点击下方链接看高清版):
https://bytedance.feishu.cn/docx/doxcnCvvY051xFCBAmSqYZgiP7b
怎么实现的?
简单来说,要将一个彩色的视频变成字符画出来的黑白视频,用下面几步就能搞定:
- 对原视频进行抽帧,对每一帧黑白化,并将像素点用对应的字符表示。
- 将表示出来的字符串再重新组合成字符图像。
- 将所有的字符图像再组合成字符视频。
- 将原视频的音频导入到新的字符视频中。
运行方法
完整的代码我放在文章末尾了,直接运行python3 video2char.py即可。程序会要求你输入视频的本地路径和转变后的清晰度(0最模糊,1最清晰。当然越清晰,转变越慢)。
运行代码的话需要用到tqdm、opencv_python、moviepy等几个库,首先得pip3 install确保它们都有了。
原理分析
这里面最关键的步骤就是如何将一帧彩色图像转变为黑白的字符图像,如下图所示:

从青蛙公主视频抽帧出来的

用字符画出来的
而转变的原理其实很简单。首先因为一个字符画在图像里会占据很大一个像素块,所以必须先对彩色图像进行压缩,连续的一个像素块可以合并,这个压缩过程就是opencv的resize操作。
然后将压缩后的像素点转变为黑白像素点,并转变为对应的字符。字符的话我这里采用的是下面的字符串,从黑到白,经过我的实践这一组是效果最好的:
"#8XOHLTI)i=+;:,. "
接着就需要将转变后的字符画到新的画布上去,需要注意的点是排布得均匀紧凑了,画布四周最好不要有太多多余的空白。
最后把所有的字符图像合并成视频就行了,但是合并后是没有声音的,需要用moviepy库把原视频的声音导入过来。
完整代码
边栏推荐
猜你喜欢

Idea remote debugging

Risk control and application of informatization project

What is the real HTAP? (1) Background article
![[applet] how to get wechat applet code upload key?](/img/b4/76e2f12269601c0a969a709ff8a397.png)
[applet] how to get wechat applet code upload key?

ERP production operation control Huaxia

Gossip: is rotting meat in the pot to protect students' rights and interests?

Download and usage of sequel Pro

Five day travels to Beijing

"PHP Basics" PHP statements and statement blocks
Development of three database general SQL code based on PG Oracle and MySQL
随机推荐
DEMO:ST05 找文本ID 信息
Shell Scripts相关
C language: optimized Hill sort
JS access cookie example
Use of "PHP Basics" Boolean
[flight control development foundation tutorial 4] crazy shell · open source formation UAV - serial port (optical flow data acquisition)
Gossip: is rotting meat in the pot to protect students' rights and interests?
软件调优方法有哪些?看看飞腾技术专家怎么说 | 龙蜥技术
Lu Xun: I don't remember saying it, or you can check it yourself!
containerd拉取私库镜像失败(kubelet)
[golang] golang develops wechat official account web page authorization function
Graph node deployment and testing
瑞芯微RK3399-I2C4挂载EEPROM的修改案例
Shenzhi Kalan Temple
Grandson's questions are difficult, and his son's invigilation is strict. I can't do it. Pay back my school money
3D laser slam: Interpretation of logo-loam paper --- Abstract
[target detection] yolov6 theoretical interpretation + practical test visdrone data set
The dragon lizard exhibition area plays a new trick this time. Let's see whose DNA moved?
How to obtain the cash flow data of advertising services to help analyze the advertising effect?
【目标检测】YOLOv6理论解读+实践测试VisDrone数据集