-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun_openpose.py
55 lines (36 loc) · 1.18 KB
/
run_openpose.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import numpy as np
import pyopenpose as op
import cv2
from glob import glob
params = dict()
# OpenPose models folder
params["model_folder"] = '../data/models/'
# Do not use the face detector.
# Define constant face rectangles.
params["face_detector"] = 2
params["face"] = True
params["body"] = 0
opWrapper = op.WrapperPython()
opWrapper.configure(params)
opWrapper.start()
# Face area in the video
face_rects = [op.Rectangle(400, 30, 512, 512),]
def op_process_file(filename):
img = cv2.imread(filename)
datum = op.Datum()
datum.cvInputData = img
datum.faceRectangles = face_rects
opWrapper.emplaceAndPop([datum])
keypoints = datum.faceKeypoints[0]
return keypoints
def main():
frames_dir = '../data/moface/frames'
op_keypoints_dir = '../data/moface/openpose_keypoints'
for filename in glob('{}/*.png'.format(frames_dir)):
keypoints = op_process_file(filename)
filename = filename.split('/')[-1].split('.')[0] + '.tsv'
with open('{}/{}'.format(op_keypoints_dir, filename), 'w') as wf:
for k in keypoints:
wf.write('{}\t{}\t{}\n'.format(k[0], k[1], k[2]))
if __name__ == '__main__':
main()