Skip to content

Instantly share code, notes, and snippets.

@ando-takahiro
Created May 21, 2018 03:47
Show Gist options
  • Select an option

  • Save ando-takahiro/cca9c864ba4b54c51479a6da2dcdb093 to your computer and use it in GitHub Desktop.

Select an option

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)
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