1 Star 0 Fork 0

sd-web/sd-webui-openpose-editor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
process_keypoints.py 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
huchenlei 提交于 2年前 . :bug:Fix default hands
"""
Used to process keypoints generated from ControlNet extension.
"""
import json
from typing import List, Tuple
def process_keypoints(nums: List[float], width: int, height: int) -> List[List[float]]:
if not nums:
return []
assert len(nums) % 3 == 0
def find_min(nums: float):
return min(num for num in nums if num > 0)
base_x = find_min(nums[::3])
base_y = find_min(nums[1::3])
normalized = all(abs(num) <= 1.0 for num in nums)
x_factor = width if normalized else 1.0
y_factor = height if normalized else 1.0
return [
[(x-base_x) * x_factor, (y-base_y) * y_factor, c]
for x, y, c in zip(nums[::3], nums[1::3], nums[2::3])
]
if __name__ == '__main__':
with open('pose_hand_fixed.json', 'r') as f:
pose = json.load(f)
person = pose["people"][0]
with open('output_pose.json', 'w') as f:
width = pose['canvas_width']
height = pose['canvas_height']
json.dump({
'left_hand': process_keypoints(person.get('hand_left_keypoints_2d'), width, height),
'right_hand': process_keypoints(person.get('hand_right_keypoints_2d'), width, height),
'face': process_keypoints(person.get('face_keypoints_2d'), width, height),
}, f, indent=4)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sd-web/sd-webui-openpose-editor.git
git@gitee.com:sd-web/sd-webui-openpose-editor.git
sd-web
sd-webui-openpose-editor
sd-webui-openpose-editor
main

搜索帮助