python获取游戏画面信息(python游戏开发之视频转彩色字符动画)
类别:脚本大全 浏览量:2362
时间:2021-10-12 00:32:39 python获取游戏画面信息
python游戏开发之视频转彩色字符动画本文实例为大家分享了python视频转彩色字符动画的具体代码,供大家参考,具体内容如下
一、效果
原图:
转换后:
效果可通过代码开头几行的参数调节
二、代码
开头几行代码,自己看着调整,把效果调到最佳就ok。
依赖库:
pip install opencv-python
pip install pygame
代码:
|
import pygame import cv2 font_size = 18 # 字体大小,可自行调整 win_size = ( 1440 , 1000 ) # 窗口大小,可自行调整 video_size = ( 30 , 30 ) # 视频大小,可自行调整 video_path = './cat.jpg" alt="python获取游戏画面信息(python游戏开发之视频转彩色字符动画)" border="0" /> str_text = '假装失智' # 替换字符,可自定义,没有长度限制,但至少得有一个 def video2imgs(video_name, size): img_list = [] cap = cv2.videocapture(video_name) while cap.isopened(): ret, frame = cap.read() if ret: img = cv2.resize(frame, size, interpolation = cv2.inter_area) img_list.append(img) else : break cap.release() return img_list # 初始化pygame def main(): pygame.init() winsur = pygame.display.set_mode(win_size) imgs = video2imgs(video_path, video_size) btnfont = pygame.font.sysfont( "fangsong" , font_size) btnfont.set_bold(true) # 生成surface sur_list = [] for img in imgs: height, width, color = img.shape surface = pygame.surface(win_size) a = 0 x, y = 0 , 0 for row in range (height): x = 0 for col in range (width): # 获取当前像素rgb rgb = img[row][col] rgb[ 0 ], rgb[ 2 ] = rgb[ 2 ], rgb[ 0 ] text_texture = btnfont.render(str_text[a], true, rgb) a = a + 1 a = a % len (str_text) surface.blit(text_texture, (x, y)) x = x + font_size y = y + font_size sur_list.append(surface) # 游戏主循环 current_frame = 0 while true: for event in pygame.event.get(): if event. type = = pygame.quit: exit() pygame.time.delay( int ( 1000 / 24 )) winsur.fill(( 0 , 0 , 0 )) winsur.blit(sur_list[current_frame], [ 0 , 0 ]) current_frame + = 1 current_frame % = len (sur_list) # 刷新界面 pygame.display.flip() if __name__ = = '__main__' : main() |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持开心学习网。
原文链接:https://blog.csdn.net/qq_39687901/article/details/83347915
您可能感兴趣
- python数组矩阵操作(Python矩阵和Numpy数组的那些事儿)
- python八卦图(Python实现九宫格式的朋友圈功能内附“马云”朋友圈)
- python编写的小程序(几个适合python初学者的简单小程序,看完受益匪浅!推荐)
- python正则表达式入门(Python正则表达式实现简易计算器功能示例)
- python编写小程序实现密码验证(python实现扫描ip地址的小程序)
- python 正则表达式在代码里的使用(python中正则表达式与模式匹配)
- python 聚类找出同一类别的数据(Python实现简单层次聚类算法以及可视化)
- 如何用python爬取最新电影(详解Python爬取并下载《电影天堂》3千多部电影)
- pythonsocket详细用法(Python中的Socket 与 ScoketServer 通信及遇到问题解决方法)
- python json转换字符串(python3 json数据格式的转换dumps/loads的使用、dict to str/str to dict、json字符串/字典)
- python循环创建字典(Python字典的基本用法实例分析创建、增加、获取、修改、删除)
- python取当前日期(Python实现根据日期获取当天凌晨时间戳的方法示例)
- opencv调用摄像头图像识别(Python+OpenCV采集本地摄像头的视频)
- python自定义定时任务(python的schedule定时任务模块二次封装方法)
- 利用python合并pdf(Python合并同一个文件夹下所有PDF文件的方法)
- python数字图像处理入门(python图像处理入门一)
- 通过体温就能为智能手表充电 原来是用NASA在空间站用的黑科技(通过体温就能为智能手表充电)
- 智能手表兼容Windows和Android 无需充电挑战苹果(智能手表兼容Windows和Android)
- 一天一冲也算表 麦步,一款待机 21 天的智能手表体验评测(一天一冲也算表)
- 魅族智能手表充电座曝光 Type-C 接口,线座分离设计(魅族智能手表充电座曝光)
- 华为 Watch GT2 Pro 智能手表曝光,新增支持无线充电(华为WatchGT2)
- vivo首款智能手表来了 也有血氧饱和度监测,一次充电18天续航(vivo首款智能手表来了)
热门推荐
- css图片3D效果(用CSS实现图片的3D凹凸感凸出镜框外或凹陷镜框里)
- ASP.NET抓取网页内容
- vmware使用教程win10(VMware Workstation安装并安装WIN10操作系统连接外网步骤指导超详细教程)
- css自动换行左右对齐(CSS自动换行、强制不换行、强制断行、超出显示省略号)
- binlog怎么恢复mysql数据库(mysql5.7使用binlog 恢复数据的方法)
- nginx配置404状态码(解决Nginx 配置 proxy_pass 后 返回404问题)
- python贪吃蛇项目介绍(python简单贪吃蛇开发)
- vue请求token无效(关于Vue 消除Token过期时刷新页面的重复提示问题)
- mysqldecimal类型数据转换(mysql decimal数据类型转换的实现)
- python怎么从数组中取内容(python调用c++ ctype list传数组或者返回数组的方法)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9