python实现少帅下飞机

​@TOC

前言

少帅下飞机 视频转 ascii 艺术字 python 实现 源码复制直接运行

代码


import cv2

import time

import os

import pickle

from blessed import Terminal

import numpy as np

# 初始化 blessed 的终端对象

term = Terminal()

# 更复杂的字符集,用于增强灰度映射效果

ASCII_CHARS = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. "


 

# 将每个像素映射为ASCII字符

def pixel_to_ascii(pixel_value):

    ascii_index = np.uint16(pixel_value) * len(ASCII_CHARS) // 256

    return ASCII_CHARS[min(ascii_index, len(ASCII_CHARS) - 1)]


 

# 将图像转换为ASCII艺术字符,并保留颜色信息

def rgb_to_ansi(r, g, b):

    return f'\033[38;2;{
     
     r};{
     
     g};{
     
     b}m'

def image_to_ascii_colored(frame, width=120):

    height, orig_width, _ = frame.shape

    aspect_ratio = height / orig_width

    new_width = width

    new_height = int(aspect_ratio * new_width * 0.43)

    resized_frame = cv2.resize(frame, (new_width, new_height), interpolation=cv2.INTER_AREA)

    gray_frame = cv2.cvtColor(resized_frame, cv2.COLOR_BGR2GRAY)

 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值