def test_cwipc_encoder_plyfile_multiple_different(self): """Test that we can encode a ply file multiple times and the results are the same, and different for different timestamps""" pc = cwipc.cwipc_read(PLY_FILENAME, 1234) encoder = _cwipc_codec.cwipc_new_encoder() encoder.feed(pc) data_one = encoder.get_bytes() pc3 = cwipc.cwipc_read(PLY_FILENAME, 4567) encoder.feed(pc3) data_three = encoder.get_bytes() self.assertNotEqual(data_one, data_three) encoder.free() pc.free() pc3.free()
def test_cwipc_write(self): """Can we write a cwipc to a ply file and read it back?""" pc = self._build_pointcloud() filename = os.path.join(TEST_OUTPUT_DIR, 'test_cwipc_write.ply') cwipc.cwipc_write(filename, pc) pc2 = cwipc.cwipc_read(filename, 0) self.assertEqual(list(pc.get_points()), list(pc2.get_points()))
def test_cwipc_encoder_octree_depth(self): """Test that octree_bits encoder param makes a significant difference""" pc = cwipc.cwipc_read(PLY_FILENAME, 1234) decoder = _cwipc_codec.cwipc_new_decoder() depth = 11 decoded_npoints_per_depth = {} cellsize_per_depth = {} while depth >= 0: encoder = _cwipc_codec.cwipc_new_encoder(octree_bits=depth) encoder.feed(pc) encoded_data = encoder.get_bytes() encoded_size = len(encoded_data) decoder.feed(encoded_data) assert decoder.available(True) decoded_pc = decoder.get() points = decoded_pc.get_points() decoded_npoints = len(points) decoded_npoints_per_depth[depth] = decoded_npoints cellsize_per_depth[depth] = decoded_pc.cellsize() encoder.free() decoded_pc.free() depth = depth - 1 # Some sanity checks for i in range(11): self.assertLessEqual(decoded_npoints_per_depth[i], decoded_npoints_per_depth[i + 1]) for i in range(11): self.assertGreater(cellsize_per_depth[i], cellsize_per_depth[i + 1]) if decoded_npoints_per_depth[11] < 80000: self.assertLessEqual(decoded_npoints_per_depth[0], 16) else: self.assertLessEqual(decoded_npoints_per_depth[0], decoded_npoints_per_depth[11] / 10000) pc.free()
def test_cwipc_encoder_plyfile_multiple_same(self): """Test that we can encode a ply file multiple times and the results are the same""" pc = cwipc.cwipc_read(PLY_FILENAME, 1234) encoder = _cwipc_codec.cwipc_new_encoder() encoder.feed(pc) data_one = encoder.get_bytes() encoder.feed(pc) data_two = encoder.get_bytes() self.assertEqual(data_one, data_two) encoder.free() pc.free()
def test_cwipc_encoder_plyfile(self): """Test that we can encode a PLY file and the available flags behaves correct""" pc = cwipc.cwipc_read(PLY_FILENAME, 1234) self._verify_pointcloud(pc) encoder = _cwipc_codec.cwipc_new_encoder() self.assertFalse(encoder.available(False)) encoder.feed(pc) self.assertTrue(encoder.available(False)) self.assertTrue(encoder.at_gop_boundary()) data = encoder.get_bytes() self.assertNotEqual(len(data), 0) self.assertFalse(encoder.available(False)) encoder.free() pc.free()
def test_cwipc_encoder_jpeg_quality(self): """Test that jpeg_quality encoder param makes a difference""" pc = cwipc.cwipc_read(PLY_FILENAME, 1234) quality = 90 prev_size = None while quality >= 10: params = _cwipc_codec.cwipc_new_encoder_params( jpeg_quality=quality) encoder = _cwipc_codec.cwipc_new_encoder(params=params) encoder.feed(pc) encoded_data = encoder.get_bytes() encoded_size = len(encoded_data) if prev_size != None: self.assertLess(encoded_size, prev_size) prev_size = encoded_size encoder.free() quality = quality - 10 pc.free()
def test_cwipc_codec_roundtrip(self): """Check that we can roundtrip encoder-decoder and get at most as many points back""" timestamp = 0x1122334455667788 pc = cwipc.cwipc_read(PLY_FILENAME, timestamp) encoder = _cwipc_codec.cwipc_new_encoder() decoder = _cwipc_codec.cwipc_new_decoder() encoder.feed(pc) data = encoder.get_bytes() decoder.feed(data) pc2 = decoder.get() self._verify_pointcloud(pc2) points = pc.get_points() points2 = pc2.get_points() self.assertGreaterEqual(len(points), len(points2)) self.assertEqual(pc2.timestamp(), timestamp) encoder.free() decoder.free() pc.free() pc2.free()
def _get(self, fn): return cwipc.cwipc_read(fn, int(time.time()))
def getpointcloud(self): pc = cwipc.cwipc_read(self.pcFilename, 0) return Pointcloud.from_cwipc(pc)
def test_cwipc_read_nonexistent(self): """When we read a cwipc from a nonexistent ply file do we get an exception?""" with self.assertRaises(cwipc.CwipcError): pc = cwipc.cwipc_read(PLY_FILENAME + '.nonexistent', 1234)
def test_cwipc_read(self): """Can we read a cwipc from a ply file?""" pc = cwipc.cwipc_read(PLY_FILENAME, 1234) self.assertEqual(pc.timestamp(), 1234) self._verify_pointcloud(pc) pc.free()
def from_file(klass, filename): """Create Pointcloud from ply file""" self = klass() pc = cwipc.cwipc_read(filename) self.cwipc = pc return self