Skip to content
Snippets Groups Projects
Commit b243f38c authored by Olivier Bertrand's avatar Olivier Bertrand
Browse files

Add vanHateren data

parent c5ac730a
No related branches found
No related tags found
No related merge requests found
Source diff could not be displayed: it is too large. Options to address this: view the blob.
File added
...@@ -2,28 +2,30 @@ ...@@ -2,28 +2,30 @@
""" """
import sys import sys
import argparse
import os import os
import inspect import inspect
import pkg_resources import pkg_resources
import tempfile import tempfile
from navipy.scripts import parser_logger, args_to_logparam
# Following need to be imported in blender as well # Following need to be imported in blender as well
import yaml import yaml
import numpy as np import numpy as np
from navipy.sensors.renderer import BlenderRender from navipy.sensors.renderer import BlenderRender
import navipy.maths.constants as mconst import navipy.maths.constants as mconst
from navipy import logger
importwithinblender = [ importwithinblender = [
'import yaml', 'import yaml',
'import numpy as np', 'import numpy as np',
'from navipy.sensors.renderer import BlenderRender', 'from navipy.sensors.renderer import BlenderRender',
'import navipy.maths.constants as mconst'] 'import navipy.maths.constants as mconst',
'from navipy import logger']
def parser_blend_ongrid(): def parser_blend_ongrid():
# Create command line options # Create command line options
parser = argparse.ArgumentParser() parser = parser_logger()
arghelp = 'Path to the environment (.blend) in which your agent lives' arghelp = 'Path to the environment (.blend) in which your agent lives'
defaultworld = pkg_resources.resource_filename( defaultworld = pkg_resources.resource_filename(
'navipy', 'resources/twocylinders_world.blend') 'navipy', 'resources/twocylinders_world.blend')
...@@ -52,18 +54,11 @@ def parser_blend_ongrid(): ...@@ -52,18 +54,11 @@ def parser_blend_ongrid():
default=None, default=None,
help=arghelp) help=arghelp)
arghelp = 'To display some stuff \n'
arghelp += ' * -v print command \n'
arghelp += ' * -vv print also script'
parser.add_argument('-v', '--verbose',
action='count',
default=0,
help=arghelp)
return parser return parser
def run(config_file, outputfile): def run(config_file, outputfile, level, logfile):
logger(level, logfile)
renderer = BlenderRender() renderer = BlenderRender()
renderer.config_file = config_file renderer.config_file = config_file
try: try:
...@@ -136,6 +131,7 @@ def main(): ...@@ -136,6 +131,7 @@ def main():
# Fetch arguments # Fetch arguments
args = parser_blend_ongrid().parse_args() args = parser_blend_ongrid().parse_args()
loglevel, logfile = args_to_logparam(args)
# Some output # Some output
print('-----') print('-----')
print('Config file:\n{}'.format(args.config_file)) print('Config file:\n{}'.format(args.config_file))
...@@ -154,8 +150,9 @@ def main(): ...@@ -154,8 +150,9 @@ def main():
tfile.write(line.encode(encoding)) tfile.write(line.encode(encoding))
tfile.write('\n\n'.encode(encoding)) tfile.write('\n\n'.encode(encoding))
tfile.write('try:\n'.encode(encoding)) tfile.write('try:\n'.encode(encoding))
tfile.write(' run("{}","{}")\n'.format( tfile.write(' run("{}","{}",{},"{}")\n'.format(
args.config_file, args.output_file).encode(encoding)) args.config_file, args.output_file, loglevel,
logfile).encode(encoding))
tfile.write(' sys.exit(0)\n'.encode(encoding)) tfile.write(' sys.exit(0)\n'.encode(encoding))
tfile.write('except Exception:\n'.encode(encoding)) tfile.write('except Exception:\n'.encode(encoding))
tfile.write(' sys.exit(1)\n'.encode(encoding)) tfile.write(' sys.exit(1)\n'.encode(encoding))
......
...@@ -483,6 +483,7 @@ class BlenderRender(AbstractRender): ...@@ -483,6 +483,7 @@ class BlenderRender(AbstractRender):
.. note: A temporary file will be written on the harddrive, .. note: A temporary file will be written on the harddrive,
due to API blender limitation due to API blender limitation
""" """
self._logger.info('get image')
# save image as a temporary file, and then loaded # save image as a temporary file, and then loaded
# sadly the rendered image pixels can not directly be access # sadly the rendered image pixels can not directly be access
keyframe = bpy.context.scene.frame_current keyframe = bpy.context.scene.frame_current
...@@ -492,6 +493,9 @@ class BlenderRender(AbstractRender): ...@@ -492,6 +493,9 @@ class BlenderRender(AbstractRender):
self.tmp_fileoutput['ext']) self.tmp_fileoutput['ext'])
im_width, im_height = self.camera_resolution im_width, im_height = self.camera_resolution
im = bpy.data.images.load(filename) im = bpy.data.images.load(filename)
# remote image once we read it. To avoid storing all images
self._logger.debug('Delete file {}'.format(filename))
os.remove(filename)
pixels = np.array(im.pixels) pixels = np.array(im.pixels)
pixels = pixels.reshape([im_height, im_width, -1]) pixels = pixels.reshape([im_height, im_width, -1])
# The last channel is the alpha channel # The last channel is the alpha channel
...@@ -511,6 +515,7 @@ class BlenderRender(AbstractRender): ...@@ -511,6 +515,7 @@ class BlenderRender(AbstractRender):
.. todo: use @property .. todo: use @property
def distance(self) def distance(self)
""" """
self._logger.info('get distances')
# save image as a temporary file, and then loaded # save image as a temporary file, and then loaded
# sadly the rendered image pixels can not directly be access # sadly the rendered image pixels can not directly be access
keyframe = bpy.context.scene.frame_current keyframe = bpy.context.scene.frame_current
...@@ -520,6 +525,8 @@ class BlenderRender(AbstractRender): ...@@ -520,6 +525,8 @@ class BlenderRender(AbstractRender):
self.tmp_fileoutput['ext']) self.tmp_fileoutput['ext'])
im_width, im_height = self.camera_resolution im_width, im_height = self.camera_resolution
im = bpy.data.images.load(filename) im = bpy.data.images.load(filename)
# remote image once we read it. To avoid storing all images
# somehow failing os.remove(filename)
distance = np.array(im.pixels) distance = np.array(im.pixels)
distance = distance.reshape([im_height, im_width, -1]) distance = distance.reshape([im_height, im_width, -1])
# Distance are channel independent # Distance are channel independent
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment