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

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()

相关文章:

  • 阳光学院【2020下】计算机网络原理-A卷-试卷-期末考试试卷
  • 北斗如何赋能雨水情监测?
  • 南方科技大学Science! 自由基不对称催化新突破 | 乐研试剂
  • 性能优化--无分支编程的实际应用场景
  • 佰力博科技准静态d33测试的注意事项
  • SAP汽配解决方案:无锡哲讯科技助力企业数字化转型
  • amd架构主机构建arm架构kkfileview
  • rtty操作记录说明
  • 日志链路ID配置,traceId多线程不打印什么鬼?
  • 如何在sheel中运行spark
  • 驱动无忧,打印随心:统信推出全新驱动下载平台
  • 从代码学习深度学习 - 全卷积神经网络 PyTorch版
  • YOLOv11融合[AAAI2025]的PConv模块
  • 技术视角下的TikTok店铺运营:从0到1的5个关键点
  • Flask+HTML+Jquery 文件上传下载
  • DeepSeek 赋能汽车全生态:从产品到服务的智能化跃迁
  • supabase 怎么新建项目?
  • Oracle 在线日志文件和控制文件损坏处理思路
  • FedTracker:为联邦学习模型提供所有权验证和可追溯性
  • 黑马k8s(五)
  • 甘肃发布外卖食品安全违法行为典型案例:一商家用鸭肉冒充牛肉被罚
  • 【社论】个人破产探索,要守住“诚实而不幸”的底线
  • 威尼斯建筑双年展总策划:山的另一边有什么在等着我们
  • 支持企业增强战略敏捷更好发展,上海市领导密集走访外贸外资企业
  • 最高降价三成,苹果中国iPhone开启大促销,能拉动多少销量?
  • 总没胃口,一吃就饱……别羡慕,也可能是生病了