forked from HQU-gxy/CVTH3PE
Single-person detection and DLT, but there is no complete tracking
This commit is contained in:
122
smooth_3d_kps.ipynb
Normal file
122
smooth_3d_kps.ipynb
Normal file
@ -0,0 +1,122 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"id": "0d48b7eb",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"from pathlib import Path\n",
|
||||
"import numpy as np"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"id": "dfd27584",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"KPS_PATH = Path(\"samples/WeiHua_03.json\")\n",
|
||||
"with open(KPS_PATH, \"r\") as file:\n",
|
||||
" data = json.load(file)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"id": "360f9c50",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'index:1, shape: (33, 133, 3)'"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'index:2, shape: (662, 133, 3)'"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"for item_object_index in data.keys():\n",
|
||||
" item_object = np.array(data[item_object_index])\n",
|
||||
" display(f'index:{item_object_index}, shape: {item_object.shape}')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# 对data['2']的662帧3d关键点数据进行滑动窗口平滑处理\n",
|
||||
"object_points = np.array(data['2']) # shape: (662, 133, 3)\n",
|
||||
"window_size = 5\n",
|
||||
"kernel = np.ones(window_size) / window_size\n",
|
||||
"# 对每个关键点的每个坐标轴分别做滑动平均\n",
|
||||
"smoothed_points = np.zeros_like(object_points)\n",
|
||||
"# 遍历133个关节\n",
|
||||
"for kp_idx in range(object_points.shape[1]):\n",
|
||||
" # 遍历每个关节的空间三维坐标点\n",
|
||||
" for axis in range(3):\n",
|
||||
" # 对第i帧的滑动平滑方式 smoothed[i] = (point[i-2] + point[i-1] + point[i] + point[i+1] + point[i+2]) / 5\n",
|
||||
" smoothed_points[:, kp_idx, axis] = np.convolve(object_points[:, kp_idx, axis], kernel, mode='same')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"id": "24c6c0c9",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'smoothed_points shape: (662, 133, 3)'"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"display(f'smoothed_points shape: {smoothed_points.shape}')\n",
|
||||
"with open(\"samples/smoothed_3d_kps.json\", \"w\") as file:\n",
|
||||
" json.dump({'1':smoothed_points.tolist()}, file)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "cvth3pe",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.12.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user