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

Add more infos in log, and remove tmp file after loading image

parent 6d7fe10f
No related branches found
No related tags found
No related merge requests found
......@@ -119,6 +119,7 @@ class AbstractRender():
distance[distance > self.worldlimit] = self.worldlimit
scene[..., -1] = distance
if mode == 'database':
self._logger.info('Write image')
dataloger.write_image(posorient, scene)
elif mode == 'array':
if imformat == '.npy':
......@@ -493,13 +494,14 @@ class BlenderRender(AbstractRender):
self.tmp_fileoutput['ext'])
im_width, im_height = self.camera_resolution
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).copy()
pixels = pixels.reshape([im_height, im_width, -1])
# The last channel is the alpha channel
pixels = pixels[..., :(pixels.shape[2] - 1)]
self._logger.debug('Image -> Ok')
# remote image once we read it. To avoid storing all images
self._logger.debug('Delete file {}'.format(filename))
os.remove(filename)
return pixels
@property
......@@ -525,12 +527,16 @@ class BlenderRender(AbstractRender):
self.tmp_fileoutput['ext'])
im_width, im_height = self.camera_resolution
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).copy()
self._logger.debug('Reshape {}->{}'.format(
distance.shape, self.camera_resolution))
distance = distance.reshape([im_height, im_width, -1])
# Distance are channel independent
distance = distance[:, :, 0]
self._logger.debug('Distance -> Ok')
# remote image once we read it. To avoid storing all images
self._logger.debug('Delete file {}'.format(filename))
os.remove(filename)
return distance[..., np.newaxis]
def update(self, posorient):
......@@ -560,6 +566,7 @@ class BlenderRender(AbstractRender):
specified by scene.camera.rotation_mode
:type posorient: pandas Series with multi-index
"""
self._logger.info('update posorient to {}'.format(posorient))
if isinstance(posorient, pd.Series):
# set frame
cframe = int(posorient.name)
......@@ -614,6 +621,7 @@ class BlenderRender(AbstractRender):
is the distance.
:rtype: a double numpy array
"""
self._logger.info('get a scene')
self.update(posorient)
toreturn = np.concatenate((self.image,
self.distance), axis=2)
......@@ -627,4 +635,5 @@ is the distance.
toreturn[np.isinf(cim) == 1] = cmax
if ninffound > 0:
warnings.warn('{} Inf found in image'.format(ninffound))
self._logger.info('Scene -> Ok')
return toreturn[..., np.newaxis]
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