Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
谢语花
e3d_handpose_x
提交
b0dc9f74
e3d_handpose_x
项目概览
谢语花
/
e3d_handpose_x
与 Fork 源项目一致
Fork自
DataBall / e3d_handpose_x
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
e3d_handpose_x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b0dc9f74
编写于
6月 19, 2021
作者:
DataBall
🚴🏻
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
d1e88cf2
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
36 addition
and
41 deletion
+36
-41
e3d_data_iter/datasets.py
e3d_data_iter/datasets.py
+8
-7
yolo_inference.py
yolo_inference.py
+28
-34
未找到文件。
e3d_data_iter/datasets.py
浏览文件 @
b0dc9f74
...
...
@@ -156,7 +156,8 @@ def draw_msra_gaussian(heatmap, center, sigma):
return
heatmap
def
get_heatmap
(
img_fix_size
,
x1y1x2y2
,
handpose_2d
,
ratio
,
dw
,
dh
,
offset_x1
=
0
,
offset_y1
=
0
,
radius
=
20
,
vis
=
False
):
num_objs
=
21
hm
=
np
.
zeros
((
256
,
256
,
num_objs
),
dtype
=
np
.
float32
)
hm
=
np
.
zeros
((
img_fix_size
.
shape
[
0
],
img_fix_size
.
shape
[
1
],
num_objs
),
dtype
=
np
.
float32
)
draw_gaussian
=
draw_msra_gaussian
if
False
else
draw_umich_gaussian
for
k
in
range
(
num_objs
):
...
...
@@ -449,12 +450,12 @@ class LoadImagesAndLabels(Dataset):
hand_w
=
int
((
x2_
-
x1_
)
/
8
)
hand_h
=
int
((
y2_
-
y1_
)
/
8
)
offset_x1
=
random
.
randint
(
-
hand_w
,
int
(
hand_w
/
2
))
offset_y1
=
random
.
randint
(
-
hand_h
,
int
(
hand_h
/
2
))
offset_x2
=
random
.
randint
(
-
int
(
hand_w
/
2
),
hand_w
)
offset_y2
=
random
.
randint
(
-
int
(
hand_h
/
2
),
hand_h
)
hand_w
=
int
((
x2_
-
x1_
)
/
2
)
hand_h
=
int
((
y2_
-
y1_
)
/
2
)
offset_x1
=
random
.
randint
(
-
hand_w
,
int
(
hand_w
/
6
))
offset_y1
=
random
.
randint
(
-
hand_h
,
int
(
hand_h
/
6
))
offset_x2
=
random
.
randint
(
-
int
(
hand_w
/
6
),
hand_w
)
offset_y2
=
random
.
randint
(
-
int
(
hand_h
/
6
),
hand_h
)
# print(" A : x1_,y1_,x2_,y2_ : ",x1_,y1_,x2_,y2_)
x1_new
=
x1_
+
offset_x1
y1_new
=
y1_
+
offset_y1
...
...
yolo_inference.py
浏览文件 @
b0dc9f74
...
...
@@ -36,8 +36,12 @@ from manopth import manolayer
if
__name__
==
"__main__"
:
parser
=
argparse
.
ArgumentParser
(
description
=
' Project Hand Pose 3D Inference'
)
parser
.
add_argument
(
'--model_path'
,
type
=
str
,
default
=
'./model_exp/2021-06-16_10-53-50/resnet_50-size-256-loss-wing_loss-model_epoch-225.pth'
,
help
=
'model_path'
)
# 模型路径
parser
.
add_argument
(
'--model_path'
,
type
=
str
,
default
=
'././model_exp/2021-06-19_14-20-56/resnet_50-size-128-loss-wing_loss-model_epoch-196.pth'
,
help
=
'model_path'
)
# e3d handpose 模型路径
parser
.
add_argument
(
'--detect_model_path'
,
type
=
str
,
default
=
'./if_package/hand_detect_416-20210606.pt'
,
help
=
'model_path'
)
# detect 模型路径
parser
.
add_argument
(
'--handpose_x2d_model_path'
,
type
=
str
,
default
=
'./if_package/handposex_2d_resnet_50-size-256-wingloss102-0.119.pth'
,
help
=
'model_path'
)
# 手2维关键点 模型路径
parser
.
add_argument
(
'--model'
,
type
=
str
,
default
=
'resnet_50'
,
help
=
'''model : resnet_18,resnet_34,resnet_50,resnet_101'''
)
# 模型类型
parser
.
add_argument
(
'--num_classes'
,
type
=
int
,
default
=
63
,
...
...
@@ -46,7 +50,7 @@ if __name__ == "__main__":
help
=
'GPUS'
)
# GPU选择
parser
.
add_argument
(
'--test_path'
,
type
=
str
,
default
=
'./image/'
,
help
=
'test_path'
)
# 测试图片路径
parser
.
add_argument
(
'--img_size'
,
type
=
tuple
,
default
=
(
256
,
256
),
parser
.
add_argument
(
'--img_size'
,
type
=
tuple
,
default
=
(
128
,
128
),
help
=
'img_size'
)
# 输入模型图片尺寸
parser
.
add_argument
(
'--vis'
,
type
=
bool
,
default
=
True
,
help
=
'vis'
)
# 是否可视化图片
...
...
@@ -90,16 +94,17 @@ if __name__ == "__main__":
print
(
'load test model : {}'
.
format
(
ops
.
model_path
))
#----------------- 构建 handpose_x 2D关键点检测模型
handpose_2d_model
=
handpose_x_model
()
handpose_2d_model
=
handpose_x_model
(
model_path
=
ops
.
handpose_x2d_model_path
)
#----------------- 构建 yolo 检测模型
hand_detect_model
=
yolo_v3_hand_model
()
hand_detect_model
=
yolo_v3_hand_model
(
model_path
=
ops
.
detect_model_path
,
model_arch
=
"yolo"
,
conf_thres
=
0.3
)
# hand_detect_model = yolo_v3_hand_model()
#----------------- 构建 manopth
g_side
=
"right"
print
(
'load model finished'
)
pose
,
shape
=
func
.
initiate
(
"zero"
)
pre_useful_bone_len
=
np
.
zeros
((
1
,
15
))
# 骨架点信息
solver
=
LM_Solver
(
num_Iter
=
666
,
th_beta
=
shape
.
cpu
(),
th_pose
=
pose
.
cpu
(),
lb_target
=
pre_useful_bone_len
,
solver
=
LM_Solver
(
num_Iter
=
99
,
th_beta
=
shape
.
cpu
(),
th_pose
=
pose
.
cpu
(),
lb_target
=
pre_useful_bone_len
,
weight
=
1e-5
)
pose0
=
torch
.
eye
(
3
).
repeat
(
1
,
16
,
1
,
1
)
...
...
@@ -110,8 +115,8 @@ if __name__ == "__main__":
root_rot_mode
=
'rotmat'
,
joint_rot_mode
=
'rotmat'
)
print
(
'start ~'
)
point_fliter
=
smoother
.
OneEuroFilter
(
4
.0
,
0.0
)
mesh_fliter
=
smoother
.
OneEuroFilter
(
4
.0
,
0.0
)
point_fliter
=
smoother
.
OneEuroFilter
(
23
.0
,
0.0
)
mesh_fliter
=
smoother
.
OneEuroFilter
(
23
.0
,
0.0
)
shape_fliter
=
smoother
.
OneEuroFilter
(
1.5
,
0.0
)
#--------------------------- 配置点云
view_mat
=
np
.
array
([[
1.0
,
0.0
,
0.0
],
...
...
@@ -136,7 +141,6 @@ if __name__ == "__main__":
test_pcd
=
open3d
.
geometry
.
PointCloud
()
# 定义点云
viewer
.
add_geometry
(
test_pcd
)
print
(
'start pose estimate'
)
pre_uv
=
None
...
...
@@ -145,7 +149,6 @@ if __name__ == "__main__":
shape_flag
=
True
#---------------------------------------------------------------- 预测图片
with
torch
.
no_grad
():
idx
=
0
cap
=
cv2
.
VideoCapture
(
0
)
#一般usb默认相机号为 0,如果没有相机无法启动,如果相机不为0需要自行确定其编号。
...
...
@@ -159,7 +162,7 @@ if __name__ == "__main__":
x_min
,
y_min
,
x_max
,
y_max
,
_
=
hand_bbox
[
0
]
w_
=
max
(
abs
(
x_max
-
x_min
),
abs
(
y_max
-
y_min
))
w_
=
w_
*
1.
5
w_
=
w_
*
1.
6
x_mid
=
(
x_max
+
x_min
)
/
2
y_mid
=
(
y_max
+
y_min
)
/
2
#
...
...
@@ -195,9 +198,9 @@ if __name__ == "__main__":
#--------------------------------
img_lbox
,
ratio
,
dw
,
dh
=
letterbox
(
img
.
copy
(),
height
=
ops
.
img_size
[
0
],
color
=
(
0
,
0
,
0
))
if
ops
.
vis
:
cv2
.
namedWindow
(
"letterbox"
,
0
)
cv2
.
imshow
(
"letterbox"
,
img_lbox
)
#
if ops.vis:
#
cv2.namedWindow("letterbox",0)
#
cv2.imshow("letterbox",img_lbox)
#-------------------------------- get heatmap
x1y1x2y2
=
0
,
0
,
0
,
0
...
...
@@ -219,24 +222,23 @@ if __name__ == "__main__":
image_fusion
=
image_fusion
.
unsqueeze_
(
0
)
if
use_cuda
:
image_fusion
=
image_fusion
.
cuda
()
# (bs, channel, h, w)
print
(
"image_fusion size : {}"
.
format
(
image_fusion
.
size
()))
# print("image_fusion size : {}".format(image_fusion.size()))
#-------------------------------- # handpose_3d predict
pre_
=
model_
(
image_fusion
.
float
())
# 模型推理
output
=
pre_
.
cpu
().
detach
().
numpy
()
output
=
np
.
squeeze
(
output
)
print
(
"handpose_3d output shape : {}"
.
format
(
output
.
shape
))
#
print("handpose_3d output shape : {}".format(output.shape))
pre_3d_joints
=
output
.
reshape
((
21
,
3
))
print
(
"pre_3d_joints shape : {}"
.
format
(
pre_3d_joints
.
shape
))
#
print("pre_3d_joints shape : {}".format(pre_3d_joints.shape))
if
g_side
==
"left"
:
print
(
"------------------->>. left"
)
pre_3d_joints
[:,
0
]
*=
(
-
1.
)
pre_3d_joints
=
torch
.
tensor
(
pre_3d_joints
).
squeeze
(
0
)
pre_3d_joints
=
pre_3d_joints
.
cuda
()
print
(
pre_3d_joints
.
size
())
#
print(pre_3d_joints.size())
#--------------------------------------------------------------------
# now_uv = result['uv'].clone().detach().cpu().numpy()[0, 0]
# now_uv = now_uv.astype(np.float)
...
...
@@ -251,6 +253,8 @@ if __name__ == "__main__":
# fliter_ax.cla()
#
# filted_ax = vis.plot3d(flited_joints + new_tran, fliter_ax)
# pre_useful_bone_len = bone.caculate_length(pre_joints, label="useful")
pre_useful_bone_len
=
bone
.
caculate_length
(
pre_joints
,
label
=
"useful"
)
NGEN
=
0
# PSO 迭代次数
...
...
@@ -274,7 +278,7 @@ if __name__ == "__main__":
pose_R
=
torch
.
from_numpy
(
pose_R
).
float
()
# reconstruction
hand_verts
,
j3d_recon
=
mano
(
pose_R
,
opt_tensor_shape
.
float
())
hand_verts
[:,:,:]
=
hand_verts
[:,:,:]
*
(
0.5
5
)
hand_verts
[:,:,:]
=
hand_verts
[:,:,:]
*
(
0.5
73
)
# print(j3d_recon.size())
mesh
.
triangles
=
open3d
.
utility
.
Vector3iVector
(
mano
.
th_faces
)
...
...
@@ -312,7 +316,7 @@ if __name__ == "__main__":
pre_joints
=
pre_joints
*
70
pre_joints
[:,
1
]
-=
40
pre_joints
[:,
0
]
-=
0
print
(
"pre_joints"
,
pre_joints
.
shape
)
#
print("pre_joints",pre_joints.shape)
test_pcd
.
points
=
open3d
.
utility
.
Vector3dVector
(
pre_joints
)
# test_pcd.points = open3d.utility.Vector3dVector(pre_joints[1,:].reshape(1,3))
# rgb = np.asarray([250,0,250])
...
...
@@ -342,8 +346,8 @@ if __name__ == "__main__":
mask_2
=
np
.
where
(
image_3d
[:,:,
2
]
!=
120
,
1
,
0
)
img_mask
=
np
.
logical_or
(
mask_0
,
mask_1
)
img_mask
=
np
.
logical_or
(
img_mask
,
mask_2
)
cv2
.
namedWindow
(
"img_mask"
,
0
)
cv2
.
imshow
(
"img_mask"
,
img_mask
.
astype
(
np
.
float
))
#
cv2.namedWindow("img_mask",0)
#
cv2.imshow("img_mask",img_mask.astype(np.float))
locs
=
np
.
where
(
img_mask
!=
0
)
xx1
=
np
.
min
(
locs
[
1
])
...
...
@@ -356,7 +360,7 @@ if __name__ == "__main__":
#----------
cv2
.
namedWindow
(
"image_3d"
,
0
)
cv2
.
imshow
(
"image_3d"
,
image_3d
)
scale_
=
((
x_max
-
x_min
)
/
(
xx2
-
xx1
)
+
(
y_max
-
y_min
)
/
(
yy2
-
yy1
))
/
2.
scale_
=
((
x_max
-
x_min
)
/
(
xx2
-
xx1
)
+
(
y_max
-
y_min
)
/
(
yy2
-
yy1
))
/
2.
*
1.01
w_3d_
=
(
xx2
-
xx1
)
*
scale_
h_3d_
=
(
yy2
-
yy1
)
*
scale_
x_mid_3d
=
(
xx1
+
xx2
)
/
2.
...
...
@@ -372,7 +376,6 @@ if __name__ == "__main__":
crop_mask
=
np
.
where
(
crop_mask
[:,:]
>
0.
,
1.
,
0.
)
crop_mask
=
np
.
expand_dims
(
crop_mask
,
2
)
# print("-----------------------------ppppppppppppppwwww : ",crop_.shape,crop_mask.shape,h_r,w_r)
try
:
img_ff
=
img_yolo_x
[
int
(
y_mid
-
h_r
):
int
(
y_mid
+
h_r
),
int
(
x_mid
-
w_r
):
int
(
x_mid
+
w_r
),:]
*
(
1.
-
crop_mask
)
+
crop_
*
crop_mask
img_yolo_x
[
int
(
y_mid
-
h_r
):
int
(
y_mid
+
h_r
),
int
(
x_mid
-
w_r
):
int
(
x_mid
+
w_r
),:]
=
img_ff
.
astype
(
np
.
uint8
)
...
...
@@ -383,15 +386,6 @@ if __name__ == "__main__":
real_hand_h
=
h_r
*
2
depth_z
=
(
model_hand_h
/
real_hand_h
+
model_hand_w
/
real_hand_w
)
/
2.
# 相对深度 z
#
# ff_img = (img_yolo_x[int(y_mid - h_r ):int(y_mid + h_r ),int(x_mid - w_r ):int(x_mid + w_r ),:]*(1.-crop_mask)
# + crop_mask * crop_)
# img_yolo_x[int(y_mid - h_r ):int(y_mid + h_r ),int(x_mid - w_r ):int(x_mid + w_r ),:]
# cv2.namedWindow("crop_mask",0)
# cv2.imshow("crop_mask",crop_mask)
# cv2.rectangle(img_yolo_x, (x1,y1),(x2,y2), (0,255,0), 5) # 绘制空心矩形
# print("scale : {}".format(scale_))
# cv2.rectangle(image_3d, (xx1,yy1), (xx2,yy2), (255,0,255), 5) # 绘制空心矩形
cv2
.
putText
(
img_yolo_x
,
" Relative Depth_Z :{:.3f} "
.
format
(
depth_z
),
(
4
,
42
),
cv2
.
FONT_HERSHEY_DUPLEX
,
1.1
,
(
55
,
0
,
220
),
7
)
cv2
.
putText
(
img_yolo_x
,
" Relative Depth_Z :{:.3f} "
.
format
(
depth_z
),
(
4
,
42
),
cv2
.
FONT_HERSHEY_DUPLEX
,
1.1
,
(
25
,
180
,
250
),
2
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录