Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run demo_webcam_smooth with box pose #160

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 124 additions & 17 deletions demo.ipynb

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion demo_webcam_smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from FaceBoxes import FaceBoxes
from TDDFA import TDDFA
from utils.render import render
from utils.pose import viz_pose
# from utils.render_ctypes import render
from utils.functions import cv_draw_landmark

Expand Down Expand Up @@ -99,6 +100,8 @@ def main(args):
img_draw = cv_draw_landmark(queue_frame[n_pre], ver_ave, size=1)
elif args.opt == '3d':
img_draw = render(queue_frame[n_pre], [ver_ave], tddfa.tri, alpha=0.7)
elif args.opt == 'box_pose':
img_draw = viz_pose(queue_frame[n_pre], param_lst, [ver_ave], show_flag=False)
else:
raise ValueError(f'Unknown opt {args.opt}')

Expand All @@ -115,7 +118,7 @@ def main(args):
parser = argparse.ArgumentParser(description='The smooth demo of webcam of 3DDFA_V2')
parser.add_argument('-c', '--config', type=str, default='configs/mb1_120x120.yml')
parser.add_argument('-m', '--mode', default='cpu', type=str, help='gpu or cpu mode')
parser.add_argument('-o', '--opt', type=str, default='2d_sparse', choices=['2d_sparse', '2d_dense', '3d'])
parser.add_argument('-o', '--opt', type=str, default='2d_sparse', choices=['2d_sparse', '2d_dense', '3d', "box_pose"])
parser.add_argument('-n_pre', default=1, type=int, help='the pre frames of smoothing')
parser.add_argument('-n_next', default=1, type=int, help='the next frames of smoothing')
parser.add_argument('--onnx', action='store_true', default=False)
Expand Down
Binary file added examples/inputs/box_pose.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ python3 demo_video_smooth.py -f examples/inputs/videos/214.avi --onnx

# 4. running on webcam
python3 demo_webcam_smooth.py --onnx

# 5. running on webcam with box pose

python3 demo_webcam_smooth.py --onnx --opt box_pose
```

The implementation of tracking is simply by alignment. If the head pose > 90° or the motion is too fast, the alignment may fail. A threshold is used to trickly check the tracking state, but it is unstable.
Expand All @@ -104,6 +108,11 @@ Running on a video will give:
<img src="docs/images/out.gif" alt="demo" width="512px">
</p>

Running on a webcam will give:

<p align="center">
<img src="examples/inputs/box_pose.jpeg", width="512px">
</p>
More results or demos to see: [Hathaway](https://guojianzhu.com/assets/videos/hathaway_3ddfa_v2.mp4).

<!-- Obviously, the eyes parts are not good. -->
Expand Down
6 changes: 2 additions & 4 deletions utils/pose.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,10 @@ def viz_pose(img, param_lst, ver_lst, show_flag=False, wfp=None):
img = plot_pose_box(img, P, ver)
# print(P[:, :3])
print(f'yaw: {pose[0]:.1f}, pitch: {pose[1]:.1f}, roll: {pose[2]:.1f}')

# writing yaw, pitch, roll in the upper left of the display
img = cv2.putText(img, f"yaw: {pose[0]:.1f} pitch: {pose[1]:.1f} roll: {pose[2]:.1f}", (10, 20), 2, .8, (255, 0, 0), 2)
if wfp is not None:
cv2.imwrite(wfp, img)
print(f'Save visualization result to {wfp}')

if show_flag:
plot_image(img)

return img