Depth data works, but not in Background mode As the titel says, I found a workaround for obtaining a depth image of the camera's FOV by using this workaround. It works just perfectly by accessing the pixel data of the image with python: 

 pixels = bpy.data.images['Viewer Node'].pixels


BUT: This method works only when the GUI is used as well. In Background mode (using the attribute -b in cmd line) this does not work. The farest I got was to check if the image "has" some data with:

 pixels = bpy.data.images['Viewer Node'].has_data


which gave me a clear false.  Therefore my question is, if there is a way how to enable this data also in Background mode? 

I googled a lot and the only other option I found to access depth data, is to use the Camera Data Node's depth output. However, I do not know how to access this data via python script.
Rendering of viewer nodes and previews in background mode was disabled in 2013 for speed optimization (see here). However, you can easily enable it again by modifying 2 files of the blender sources and compiling blender yourself (as described here).

In the file source/blender/compositor/operations/COM_ViewerOperation.h, line ~58:

bool isOutputOperation(bool /*rendering*/) const { if (G.background) return false; return isActiveViewerOutput();


should be changed to

bool isOutputOperation(bool /*rendering*/) const {return isActiveViewerOutput(); }


and in file source/blender/compositor/operations/COM_PreviewOperation.h, line ~48:

bool isOutputOperation(bool /*rendering*/) const { return !G.background; }


should be changed to

bool isOutputOperation(bool /*rendering*/) const { return true; }


After these changes, the pixels array gets properly updated in background mode.