-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
it would be better to use hdf5 files to export depth images, rather than exr #24
Comments
@qiuwch In case it would be helpful, I'd be happy to provide a simple standalone C++ demo that saves a float array as an hdf5 file. Please do send me a note if you think this would be helpful. |
Thanks. I think this is an awesome idea. I am considering how to get more complex and structural data (the mesh you mentioned in another thread, for example) from unrealcv. A good file format that can support that is ideal. The constraint I am facing is using 3rd library in UE4 is tricky. I prefer to use the 3rd libraries bundled with UE4 if possible, but if it is important to include new ones, I am also happy to do that. To use hdf5, I think I need to include hdf5 source code or compiled lib within unrealcv. To make it cross-platform, I can not ask users to install dependency with I did some research about hdf5 yesterday, I found they provide compiled binaries in here, but no Mac version. I will need to start a new branch for this and merge it until it is considered stable. I would be very helpful if I can get any help from you, such as the demo. |
Actually, I am also considering yaml or xml. But not sure whether the overhead is too big to bear. |
@qiuwch Sure thing, happy to help. I was thinking about this yesterday too. I 100% agree with your assessment. EXR is a tolerable format for depth images, but for other more general data streams you might want to export, it would be very unpleasant to try to pack them into EXR images, like triangle meshes, etc. HDF5 would be much better for more general data streams. I'll start by providing the standalone example usage of HDF5. And then I'll help to test the HDF5 branch. Getting the HDF5 binaries for Mac is easy using macports or brew. Getting the Python HDF5 dependencies for Mac is also easy. This is in contrast to reading EXR files, which I've concluded is not straightforward at all on Mac (see AcademySoftwareFoundation/openexr#207 and AcademySoftwareFoundation/openexr#208). |
@qiuwch I think XML would be tolerable as well. Obviously HDF5 would be better for large assets. But even for dense image data, it wouldn't be the end of the world to store this in XML. I believe the COLLADA interchange format between 3D modeling programs is totally XML based, and people manage to make that work for large assets. Obviously XML will take longer than necessary to load. But I think a depth image stored as XML could be loaded and parsed in less than a second. |
@qiuwch One more thing. The a raw binary blob could also be dumped to a file. This is unsafe and non-portable across machines due to endian issues, but as long as you're running the UnrealCV Python/Matlab client on the same machine as the Unreal game, this strategy is safe. Of course, requiring that these two applications be running on the same machine is certainly an unpleasant limitation, even if this is how most people would use UnrealCV in practice. Of all these potential strategies, I think supporting HDF5 is the preferred option. |
@qiuwch In case it is helpful, I'm including an end-to-end minimal code example for writing HDF5 files from C++, and reading them in Python. This code example assumes that your compiler knows where to find the HDF5 C++ headers and binary files. I obtained these files on OSX by typing This code also assumes that your compiler knows where to find the andres::Marray library. andres::Marray is an extremely lightweight, header-only multidimensional array library for C++, with a very convenient high-level interface for reading and writing HDF5 files. andres::Marray is only 3 header files. You can simply download the 3 header files from GitHub and you're good to go. Here is the complete C++ program for writing HDF5 files. Note that if you already have a raw pointer to your data, andres::Marray allows you to create a lightweight view object over the data (similar to a NumPy view), and save the data to HDF5 using the view. So you can avoid an extra data copy. I demonstrate this approach in the second half of this code snippet.
I compiled this example by naming it In Python, I can read the data with the following code snippet. Note that this code snippet assumes that you have the h5py Python module installed. This module came pre-installed with Enthought Canopy, and can be easily obtained from your favorite package manager.
|
I am working on integrating protobuf with UnrealCV I chose protobuf is because it provides a flexible way to define message and the proto file can naturally serve as documentation. It is currently in a very early stage and I will keep you updated. |
@qiuwch It is really useful a protobuf integration |
@bhack Actually I changed my mind after this half an year thought and development. My current decision is sending json for plain text structure data and use cnpy to send numpy array. https://github.com/rogersce/cnpy. This is almost done and I am doing some testing. |
Hello,
In my opinion, it would be better to use hdf5 (http://www.h5py.org/) to export depth images, rather than exr. My rationale here is as follows:
unrealcv/client/examples/generate-images.ipynb
example notebook distributed with UnrealCV crashes when callingcv2.imread(frame['depth'], cv2.IMREAD_ANYDEPTH)
by default on OSX.The text was updated successfully, but these errors were encountered: