• python制作动态字符画(简单易上手版)


    嗨害大家好鸭~

    我是和大家一起学习python的小熊猫🖤

    不知道大家喜不喜欢玩字符画


    有什么python相关报错解答自己不会的、或者源码资料/模块安装/女装大佬精通技巧 都可以来这里:(https://jq.qq.com/?_wv=1027&k=2Q3YTfym)或者+V:python10010问我

    在这里插入图片描述

    前一阵子本熊猫我看见了一个很牛的字符画,当时就震惊了,不就是个字符画~我觉得自己也行

    请添加图片描述
    然后我就开始了简单版的尝试

    这还不是轻轻松松有手就行 ~ ~ ~

    上代码!(https://jq.qq.com/?_wv=1027&k=2Q3YTfym)

    from PIL import Image as im
    from tkinter import *
    import cv2
     
    # 随便打
    codeLib = '''*.1'''
    count = len(codeLib)
     
     
    def transform(image_file):
        codePic = ''
        for h in range(0, image_file.size[1]):
            for w in range(0, image_file.size[0]):
                g, r, b = image_file.getpixel((w, h))
                gray = int(r * 0.299 + g * 0.587 + b * 0.114)
                codePic = codePic + codeLib[int(((count - 1) * gray) / 256)]
            codePic = codePic + '\r\n'
        return codePic
     
     
    def image2char(image_file):
        image_file = image_file.resize((int(image_file.size[0] * 0.16), int(image_file.size[1] * 0.06)))  # 调整图片大小
        return transform(image_file), image_file.size[0], image_file.size[1]
     
     
    def frame2image(cap, i):
        cap.set(cv2.CAP_PROP_POS_FRAMES, i)
        _, b = cap.read()
        image = im.fromarray(cv2.cvtColor(b, cv2.COLOR_BGR2RGB))
        return image
     
     
    def gui(path):
        cap = cv2.VideoCapture(path)
        root = Tk()
        t = frame2image(cap, 0)
        _, w, h = image2char(t)
        text = Text(root, width=w, height=h)
        text.pack()
        framenum = int(cap.get(7))
        for i in range(framenum):
            image = frame2image(cap, i)
            content, _, _ = image2char(image)
            text.insert(INSERT, content)
            root.update()
            text.delete(0.0, END)
     
     
    if __name__ == '__main__':
        gui(r'C:\Users\Administrator\Desktop\油性极大.mp4')
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50

    素材用的是…

    在这里插入图片描述
    最后选择视频的路径,修改代码的文件路径,在运行代码

    请添加图片描述

    害,这个是超级无敌简单版的哈

    今天的教程就到这里,我是小熊猫,咱下篇文章再见啦(✿◡‿◡)

    在这里插入图片描述

  • 相关阅读:
    ContentType的作用
    笔试强训48天——day8
    实验室信息化建设的基本内容
    C++ 序容器
    基础知识与问题
    《深度学习进阶:自然语言处理》读书笔记:第7章 基于RNN生成文本
    安装内核切换内核
    实现阿里云模型服务灵积 DashScope 的 Semantic Kernel Connector
    基于最小均方误差linear minimum mean square error(LMMSE)插值算法的图像超分辨重构研究-附Matlab代码
    第一章:最新版零基础学习 PYTHON 教程(第十二节 - Python 语句中的 – Python 中的链接比较运算符)
  • 原文地址:https://blog.csdn.net/m0_67575344/article/details/126138759