Created
May 21, 2018 03:47
-
-
Save ando-takahiro/cca9c864ba4b54c51479a6da2dcdb093 to your computer and use it in GitHub Desktop.
I'd like to share how we can exchange data between open3d.Image and numpy. I think this would be helpful for python beginners like me X)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from unittest import TestCase | |
| from functools import reduce | |
| import numpy as np | |
| import numpy.testing as npt | |
| from open3d.py3d import Image | |
| class TestNumpyImage(TestCase): | |
| def test_new_image(self): | |
| shape = (2, 1, 3) | |
| array = np.arange(reduce(lambda x, y: x * y, shape), dtype=np.float32).reshape(shape) | |
| img = Image(array) | |
| actual = np.array(img) | |
| self.assertTupleEqual(actual.shape, shape) | |
| npt.assert_array_equal(actual, array) | |
| img_view = memoryview(img) | |
| self.assertTupleEqual(img_view.shape, shape) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment