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