DIYer22 / bpycv

Computer vision utils for Blender (generate instance annoatation, depth and 6D pose by one line code)
MIT License
464 stars 58 forks source link

Replace OpenEXR with minexr #20

Closed iantra closed 3 years ago

iantra commented 3 years ago

Should probably be tested more thoroughly, but it seems to me like all the needed functionality is there More information: https://pypi.org/project/minexr/ This is the exr interface that https://github.com/cheind/pytorch-blender uses, which is where I got the idea from.

DIYer22 commented 3 years ago

Yes, installing OpenEXR is unreliable! Thanks for this PR, it is very useful. And I found that when using CYCLES as render engine, minexr will raise error.

Here is minimal reproduce code:

$ blender -b --python-expr 'import bpy,bpycv,boxx;bpy.data.scenes[0].render.engine = "CYCLES";boxx.tree(bpycv.render_data())'

Error: Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/dl/mygit/bpycv/bpycv/render_utils.py", line 117, in render_data
    render_result["exr"] = parser_exr(exr_path)
  File "/home/dl/mygit/bpycv/bpycv/exr_image_parser.py", line 141, in parser_exr
    exr = ExrImage(fp)
  File "/home/dl/mygit/bpycv/bpycv/exr_image_parser.py", line 44, in __init__
    self.reader = ExrReader(fp)
  File "/home/dl/miniconda3/lib/python3.7/site-packages/minexr/reader.py", line 39, in __init__
    self._read_header()
  File "/home/dl/miniconda3/lib/python3.7/site-packages/minexr/reader.py", line 97, in _read_header
    assert b2 == b3 == b4 == 0, 'Not a single-part scan line file.'
AssertionError: Not a single-part scan line file.

location: <unknown location>:-1

I tried to figure out, but didn't get it. Can you help take a look?

iantra commented 3 years ago

Nice catch, my project only uses eevee so I hadn't noticed that.

The latest commit should fix this, it happens because minexr tries to check that the file is in a readable format first and it seems cycles uses long attribute names so this was breaking it. I think the length of attribute names doesn't matter so much so I now override the header reading and skip checking for it, but I'm not sure if this has any undersired side effects. It seems to work for me but you might want to run your own tests to be 100% sure.

I'm also submitting pull requests to minexr with these fixes, so hopefully they get published to pypi at some point and we don't have to manually add them anymore.

More info: https://www.openexr.com/documentation/openexrfilelayout.pdf (Page 6)