-
Notifications
You must be signed in to change notification settings - Fork 21
/
generate_pictures.py
57 lines (43 loc) · 1.53 KB
/
generate_pictures.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
56
57
"""
@file generate_pictures.py
@copyright Software License Agreement (BSD License).
Copyright (c) 2017, Rutgers the State University of New Jersey, New Brunswick.
All Rights Reserved. For a full description see the file named LICENSE.
Authors: Chaitanya Mitash, Kostas Bekris, Abdeslam Boularias.
"""
import os, sys, shutil
import os.path as osp
import time, random
from datetime import datetime
from ConfigParser import ConfigParser
import Label
random.seed(datetime.now())
if os.environ.get('BLENDER_PATH') == None:
print("Please set BLENDER_PATH in bashrc!")
sys.exit()
g_blender_executable_path = os.environ['BLENDER_PATH']
g_blank_blend_file_path = 'blank.blend'
# call blender to render images
blank_file = osp.join(g_blank_blend_file_path)
render_code = osp.join('simulate_and_render.py')
syn_images_folder = 'rendered_images'
if os.path.exists(syn_images_folder):
shutil.rmtree(syn_images_folder)
os.mkdir(syn_images_folder)
os.mkdir(syn_images_folder + "/debug")
start = time.time()
try:
render_cmd = '%s %s -b --python %s' % \
(g_blender_executable_path, blank_file, render_code)
os.system(render_cmd)
except:
print('render failed. render_cmd: %s' % (render_cmd))
cfg = ConfigParser("config.yml")
num_of_images = cfg.getNumTrainingImages()
pLabel = Label.Label()
if cfg.getLabelType() == 'pixel':
pLabel.get_segmentation_labels(syn_images_folder, num_of_images)
else:
pLabel.draw_bboxes(syn_images_folder, num_of_images)
end = time.time()
print ("%d images generated in %f seconds!" % (num_of_images, end - start))