当前位置: 首页 > ops >正文

3d关键点 可视化

目录

pygame

pygame保存mp4

mayavi


pygame

import pygame
from pygame.locals import *
import numpy as np
import sys# 初始化Pygame
pygame.init()
width, height = 800, 600
screen = pygame.display.set_mode((width, height))
clock = pygame.time.Clock()# 生成示例数据
n_frames = 20
n_joints = 17
keypoints_3d = np.random.rand(n_frames, n_joints, 3) * 2 - 1# 投影3D到2D(简化版)
def project_3d_to_2d(x, y, z, scale=200):return int(width / 2 + x * scale), int(height / 2 - y * scale)frame = 0
running = True
while running:for event in pygame.event.get():if event.type == QUIT:running = Falsescreen.fill((255, 255, 255))# 获取当前帧current_frame = keypoints_3d[frame % n_frames]# 绘制关键点for x, y, z in current_frame:px, py = project_3d_to_2d(x, y, z)pygame.draw.circle(screen, (255, 0, 0), (px, py), 5)# 绘制骨骼连线for i in range(n_joints - 1):x1, y1, z1 = current_frame[i]x2, y2, z2 = current_frame[i + 1]p1 = project_3d_to_2d(x1, y1, z1)p2 = project_3d_to_2d(x2, y2, z2)pygame.draw.line(screen, (0, 0, 255), p1, p2, 2)pygame.display.flip()frame += 1n=1clock.tick(n)  # n帧/秒pygame.quit()
sys.exit()

pygame保存mp4

import pygame
import imageio
import numpy as np# 初始化 Pygame
pygame.init()
width, height = 640, 480
screen = pygame.display.set_mode((width, height))
clock = pygame.time.Clock()# 视频帧列表
frames = []running = True
frame_count = 0
max_frames = 300  # 保存300帧,大概10秒@30fpswhile running and frame_count < max_frames:for event in pygame.event.get():if event.type == pygame.QUIT:running = False# 清屏和绘制内容screen.fill((0, 0, 0))pygame.draw.circle(screen, (255, 0, 0), (frame_count % width, height // 2), 30)pygame.display.flip()# 截图保存为 numpy 数组buffer = pygame.surfarray.array3d(screen)frame = np.transpose(buffer, (1, 0, 2))  # 转换为 HWC 格式frames.append(frame)frame_count += 1clock.tick(30)  # 控制帧率为30FPSpygame.quit()# 保存为MP4
imageio.mimsave("output.mp4", frames, fps=30)
print("视频保存为 output.mp4")

mayavi

import numpy as np
from mayavi import mlab# 生成示例数据
n_frames = 20
n_joints = 17
keypoints_3d = np.random.rand(n_frames, n_joints, 3)# 创建动画
@mlab.animate(delay=100)  # 每帧100ms
def animate():for i in range(n_frames):mlab.clf()  # 清空当前帧current_frame = keypoints_3d[i]# 绘制关键点pts = mlab.points3d(current_frame[:, 0], current_frame[:, 1], current_frame[:, 2],color=(1, 0, 0), scale_factor=0.05)# 绘制骨骼连线for j in range(n_joints - 1):mlab.plot3d([current_frame[j, 0], current_frame[j+1, 0]],[current_frame[j, 1], current_frame[j+1, 1]],[current_frame[j, 2], current_frame[j+1, 2]],tube_radius=0.01, color=(0, 0, 1))yield  # 切换到下一帧animate()
mlab.show()

http://www.xdnf.cn/news/5711.html

相关文章:

  • WPF的UI元素类型详解
  • 大容量存储的高性能 T-BOX 方案对智能网联汽车的支撑
  • 免费专业级 PDF 处理!SolidPDF OCR 识别 + 精准转换批量处理
  • Dinky 安装部署并配置提交 Flink Yarn 任务
  • 某实战项目登录口处的渗透测试
  • 运行Spark程序-在Spark-shell——RDD
  • #跟着若城学鸿蒙#HarmonyOS NEXT学习之Blank组件详解
  • 2025年01月10日浙江鑫越系统科技前端面试
  • 商业航天运动控制系统中的高可靠性芯片解决方案:挑战、策略与应用研究
  • Spark处理过程-转换算子
  • K8s 图形界面管理kubesphere
  • 遨游5G-A防爆手机:赋能工业通信更快、更安全
  • SAM论文学习
  • LVGL(lv_led LED灯控件)
  • 【ROS2】通信部署概述(以话题(Topic)通信为例)
  • The 2024 Sichuan Provincial Collegiate Programming Contest部分题解(L,H,E,B,I)
  • vue H5解决安卓手机软键盘弹出,页面高度被顶起
  • 连接词化归律详解
  • Linux系统管理与编程19:自动部署dns
  • 十二、操作符重载
  • 多媒体预研
  • 基于STM32、HAL库的BME680气压传感器 驱动程序设计
  • 如何找正常运行虚拟机
  • 【Kubernetes】初识基础理论(第一篇)
  • OSCP - Hack The Box - Sau
  • 【面试真题】王者荣耀亿级排行榜,如何设计?
  • 项目售后服务承诺书,软件售后服务方案,软件安装文档,操作文档,维护文档(Word原件)
  • MySQL性能调优探秘:我的实战笔记 (下篇:深入内核、锁与监控)
  • java反序列化commons-collections链1
  • 如何使用 WMIC 命令在 Windows 11 或 10 上卸载软件