zoukankan      html  css  js  c++  java
  • 字符视频

    视频 转 图片

    import cv2
    path = '/Users/xiaojiayudeapple/Desktop/未命名文件夹 2/002 - 蔡徐坤打篮球原视频.mp4'#路径
    cp = cv2.VideoCapture(path)
    s = cp.isOpened()
    count = 0
    while s:
        count += 1
        s, frame = cp.read()
        params = []
        params.append(2)
        cv2.imwrite('frames\%d.jpg' % count, frame, params)
    
    cp.release()
    print('unlock movie: ', count)
    

    图片 转 字符

    from PIL import Image
    
    def main():
        for a in range(1385, 2947):
            #金坷垃0000.jpg
            print(a)
            if a < 10:
                pic = "金坷垃000" + str(a) + ".jpg"
            if a >= 10 and a < 100:
                pic = "金坷垃00" + str(a) + ".jpg"
            if a >= 100 and a < 1000:
                pic = "金坷垃0" + str(a) + ".jpg"
            if a >= 1000:
                pic = "金坷垃" + str(a) + ".jpg"
            # 0000
            # 10个字符表示按“灰度级别”从高到低排序
            asciis = "@%#*+=-:. "
            # 设置缩放系数
            zoom = 2
            # 设置垂直比例系数
            vscale = 1
            texts = pic2ascii(pic, asciis, zoom, vscale)
            
            with open(str(a)+".txt", "w") as file:
                file.write(texts)
    
    def pic2ascii(pic_, asciis, zoom, vscale):
        img = Image.open(pic_)
        # 打开图片并转换为灰度模式
        out = img.convert("L")
        # 获取图片的宽度和高度
        width, height = out.size
        # 由于字符的宽度并不会等于高度,所以需要进行调整
        out = out.resize((int(width * zoom), int(height * zoom * vscale)))
        ascii_len = len(asciis)
        texts = ''
    
        for row in range(out.height):
            for col in range(out.width):
                gray = out.getpixel((col, row))
                texts += asciis[int((gray / 255) * (ascii_len - 1))]
            texts += '
    '
    
        return texts
    
    if __name__ == "__main__":
        main()
    

    输出

    import sys
    from time import sleep
    
    for a in range(0, 3030):
        sleep(0.3)
        with open(str(a) + '.txt','r',encoding='utf-8') as f:
            for line in f.readlines():
                # end=''控制文本中换行时不读取出换行号
                print(line,end='')
        # 定义列表
        ls = ["sunny","dghahdfg"]
        with open('demo.txt','a',encoding='utf-8') as f:
            for line in ls:
                # 写入文件
                f.write('{}
    '.format(line))
    
    没有未来的未来不是我想要的未来
  • 相关阅读:
    Linux注意到Makefile
    coco2dx c++ HTTP实现
    怎么样putty打开图形化管理工具,在终端上
    javabean总结
    发布Ubuntu/Linux系统cache,增加可用内存空间
    Java获得正则表达式
    uva 11992 为矩阵更新查询段树
    oracle在schema是什么意思?
    zoj 3288 Domination (可能dp)
    学习算法
  • 原文地址:https://www.cnblogs.com/Little-Turtle--QJY/p/13333903.html
Copyright © 2011-2022 走看看