5分钟让手绘小人动起来:AnimatedDrawings姿态估计技术全解析
你还在为手绘角色无法动起来而烦恼吗?本文将带你掌握AnimatedDrawings的核心技术,无需专业动画知识,只需简单几步即可让你的涂鸦角色跳起舞来。读完本文,你将学会:
- 使用AI自动生成角色骨架和动作
- 导出透明GIF和MP4动画
- 自定义角色动作和场景背景
项目简介
AnimatedDrawings是一个开源项目,它能将儿童手绘的人物画自动转换为生动的动画。该项目基于论文《A Method for Animating Children's Drawings of the Human Figure》实现,通过深度学习模型检测手绘人物的姿态,再将3D动作数据迁移到手绘角色上。
项目核心功能包括:
- 人物检测与姿态估计
- 自动骨架生成与绑定
- 动作捕捉数据迁移
- 动画渲染与导出
快速开始
环境搭建
首先需要克隆项目并安装依赖:
# 创建并激活虚拟环境
conda create --name animated_drawings python=3.8.13
conda activate animated_drawings
# 克隆代码仓库
git clone https://gitcode.com/GitHub_Trending/an/AnimatedDrawings
cd AnimatedDrawings
# 安装依赖
pip install -e .
运行交互式示例
在Python环境中执行以下代码,即可看到一个会跳舞的手绘小人:
from animated_drawings import render
render.start('./examples/config/mvc/interactive_window_example.yaml')
运行后会打开一个交互式窗口,你可以使用空格键暂停/继续动画,方向键控制时间轴,按q键退出。
核心技术解析
姿态估计算法
AnimatedDrawings的核心是其手绘人物姿态估计算法。该系统使用训练好的深度学习模型自动检测手绘人物的关节位置,生成骨架结构。相关实现位于animated_drawings/model/retargeter.py和animated_drawings/model/joint.py。
算法流程如下:
- 检测手绘人物轮廓(使用掩码图像)
- 识别关键关节点(头、肩、肘、腕、髋、膝、踝等)
- 构建骨骼结构,建立关节间的父子关系
- 将3D动作数据映射到2D手绘角色
从图片到动画的完整流程
项目提供了一个一站式脚本examples/image_to_animation.py,可以直接将手绘图片转换为动画:
from image_to_annotations import image_to_annotations
from annotations_to_animation import annotations_to_animation
def image_to_animation(img_fn: str, char_anno_dir: str, motion_cfg_fn: str, retarget_cfg_fn: str):
# 第一步:从图片生成骨骼标注
image_to_annotations(img_fn, char_anno_dir)
# 第二步:从标注生成动画
annotations_to_animation(char_anno_dir, motion_cfg_fn, retarget_cfg_fn)
这个流程包含两个关键步骤:图片转标注和标注转动画。
实用功能指南
导出MP4视频
要将动画导出为MP4文件,使用以下配置:
from animated_drawings import render
render.start('./examples/config/mvc/export_mp4_example.yaml')
动画将保存为当前目录下的video.mp4文件。
导出透明GIF
如果需要透明背景的GIF动画,使用GIF导出配置:
from animated_drawings import render
render.start('./examples/config/mvc/export_gif_example.yaml')
自定义角色动画
项目提供了多个预定义角色和动作,位于examples/characters/和examples/bvh/目录下。例如,要使用"dab"动作,可以使用examples/config/motion/dab.yaml配置文件。
以下是一个四足动物角色的示例:
from animated_drawings import render
render.start('./examples/config/mvc/four_legs_example.yaml')
多角色场景
你还可以创建包含多个角色的动画场景,配置文件为examples/config/mvc/multiple_characters_example.yaml:
from animated_drawings import render
render.start('./examples/config/mvc/multiple_characters_example.yaml')
高级应用
修复AI标注错误
当AI自动生成的关节位置不准确时,可以使用examples/fix_annotations.py工具手动调整:
python fix_annotations.py garlic_out/
这会启动一个Web界面,你可以在浏览器中拖动关节点到正确位置。
添加自定义背景
通过修改配置文件,可以为动画添加自定义背景图片。例如使用examples/config/mvc/background_example.yaml:
from animated_drawings import render
render.start('./examples/config/mvc/background_example.yaml')
创建自定义动作
你可以使用BVH格式的动作捕捉文件创建自定义动画。项目提供了多个示例动作,如:
- examples/bvh/fair1/dab.bvh - Dab动作
- examples/bvh/fair1/jumping.bvh - 跳跃动作
- examples/bvh/fair1/wave_hello.bvh - 挥手动作
- examples/bvh/rokoko/jesse_dance.bvh - 舞蹈动作
结语
AnimatedDrawings项目为手绘角色动画提供了一个简单而强大的解决方案。无论是教育、娱乐还是创意设计,它都能帮助你快速将静态手绘转换为生动的动画。
如果你想深入了解更多功能,可以查阅examples/config/README.md了解配置文件的详细说明,或查看项目的论文了解技术细节。
现在,轮到你发挥创意,让你的手绘角色动起来了!
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考







