4 from sensor_msgs.msg
import PointCloud2, PointField, Image
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)
12 np.testing.assert_equal(arr, arr2)
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)
19 np.testing.assert_equal(arr, arr2)
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)
27 np.testing.assert_equal(arr, arr2)
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)
35 np.testing.assert_equal(arr, arr2)
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)
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')
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')
55 if __name__ ==
'__main__':
def test_roundtrip_little_endian(self)
def test_roundtrip_mono(self)
def test_roundtrip_big_endian(self)
def test_bad_encodings(self)
def test_roundtrip_rgb8(self)