test_images.py
Go to the documentation of this file.
1 import unittest
2 import numpy as np
3 import ros_numpy
4 from sensor_msgs.msg import PointCloud2, PointField, Image
5 
6 class TestImages(unittest.TestCase):
7  def test_roundtrip_rgb8(self):
8  arr = np.random.randint(0, 256, size=(240, 360, 3)).astype(np.uint8)
9  msg = ros_numpy.msgify(Image, arr, encoding='rgb8')
10  arr2 = ros_numpy.numpify(msg)
11 
12  np.testing.assert_equal(arr, arr2)
13 
15  arr = np.random.randint(0, 256, size=(240, 360)).astype(np.uint8)
16  msg = ros_numpy.msgify(Image, arr, encoding='mono8')
17  arr2 = ros_numpy.numpify(msg)
18 
19  np.testing.assert_equal(arr, arr2)
20 
22  arr = np.random.randint(0, 256, size=(240, 360)).astype('>u2')
23  msg = ros_numpy.msgify(Image, arr, encoding='mono16')
24  self.assertEqual(msg.is_bigendian, True)
25  arr2 = ros_numpy.numpify(msg)
26 
27  np.testing.assert_equal(arr, arr2)
28 
30  arr = np.random.randint(0, 256, size=(240, 360)).astype('<u2')
31  msg = ros_numpy.msgify(Image, arr, encoding='mono16')
32  self.assertEqual(msg.is_bigendian, False)
33  arr2 = ros_numpy.numpify(msg)
34 
35  np.testing.assert_equal(arr, arr2)
36 
37 
38  def test_bad_encodings(self):
39  mono_arr = np.random.randint(0, 256, size=(240, 360)).astype(np.uint8)
40  mono_arrf = np.random.randint(0, 256, size=(240, 360)).astype(np.float32)
41  rgb_arr = np.random.randint(0, 256, size=(240, 360, 3)).astype(np.uint8)
42  rgb_arrf = np.random.randint(0, 256, size=(240, 360, 3)).astype(np.float32)
43 
44  with self.assertRaises(TypeError):
45  msg = ros_numpy.msgify(Image, rgb_arr, encoding='mono8')
46  with self.assertRaises(TypeError):
47  msg = ros_numpy.msgify(Image, mono_arrf, encoding='mono8')
48 
49  with self.assertRaises(TypeError):
50  msg = ros_numpy.msgify(Image, rgb_arrf, encoding='rgb8')
51  with self.assertRaises(TypeError):
52  msg = ros_numpy.msgify(Image, mono_arr, encoding='rgb8')
53 
54 
55 if __name__ == '__main__':
56  unittest.main()
def test_roundtrip_little_endian(self)
Definition: test_images.py:29
def test_roundtrip_mono(self)
Definition: test_images.py:14
def test_roundtrip_big_endian(self)
Definition: test_images.py:21
def test_bad_encodings(self)
Definition: test_images.py:38
def test_roundtrip_rgb8(self)
Definition: test_images.py:7


ros_numpy
Author(s): Eric Wieser
autogenerated on Sat Oct 3 2020 03:25:57