forked from p-szm/posenet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
render_poses.py
53 lines (43 loc) · 1.65 KB
/
render_poses.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
import argparse
import os
import sys
import numpy as np
sys.path.append(os.path.dirname(__file__)) # So that next imports work
from posenet.blender import *
from posenet.utils import *
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--pose', type=float, nargs=7, action='store', required=False)
parser.add_argument('-f', '--def_file', action='store', required=False)
parser.add_argument('-o', '--output', type=str, action='store', required=True)
parser.add_argument('-s', '--size', type=int, nargs=2, action='store', required=False,
default=[300,300])
args = parser.parse_args(preprocess_args(sys.argv))
def read_label_file(def_file):
paths = []
labels = []
with open(def_file) as f:
lines = list(map(lambda line: line.rstrip("\n").split(" "), f.readlines()[3:]))
paths = list(map(lambda line: line[0], lines))
labels = list(map(lambda line: list(map(lambda x: float(x), line[1:])), lines))
return list(paths), list(labels)
def split_pose(pose):
x = np.array(pose[0:3])
q = np.array(pose[3:7])
q = q/np.linalg.norm(q)
return x, q
if not args.def_file and not args.pose:
print('Definition file or pose required')
sys.exit(1)
camera = Camera(width=args.size[0], height=args.size[1])
if args.def_file:
paths, labels = read_label_file(args.def_file)
for path, label in zip(paths, labels):
x, q = split_pose(label)
camera.setLocation(x)
camera.setRotation(q)
camera.takePicture(os.path.join(args.output, path))
elif args.pose:
x, q = split_pose(args.pose)
camera.setLocation(x)
camera.setRotation(q)
camera.takePicture(args.output)