def test_cwipc_synthetic_tiled(self): """Is a synthetic pointcloud generator providing the correct tiling interface?""" pcs = cwipc.cwipc_synthetic() self.assertEqual(pcs.maxtile(), 3) self.assertEqual( pcs.get_tileinfo_dict(0), { 'normal': { 'x': 0, 'y': 0, 'z': 0 }, 'camera': b'synthetic', 'ncamera': 3 }) self.assertEqual( pcs.get_tileinfo_dict(1), { 'normal': { 'x': 0, 'y': 0, 'z': 1 }, 'camera': b'synthetic', 'ncamera': 1 }) self.assertEqual( pcs.get_tileinfo_dict(2), { 'normal': { 'x': 0, 'y': 0, 'z': -1 }, 'camera': b'synthetic', 'ncamera': 2 }) pcs.free()
def test_cwipc_synthetic_args(self): """Can we create a synthetic pointcloud with fps and npoints arguments?""" pcs = cwipc.cwipc_synthetic(10, 1000) self.assertTrue(pcs.available(True)) self.assertTrue(pcs.available(False)) self.assertFalse(pcs.eof()) pc = pcs.get() self._verify_pointcloud(pc) pc.free() pcs.free()
def test_cwipc_synthetic(self): """Can we create a synthetic pointcloud?""" pcs = cwipc.cwipc_synthetic() self.assertTrue(pcs.available(True)) self.assertTrue(pcs.available(False)) self.assertFalse(pcs.eof()) pc = pcs.get() self._verify_pointcloud(pc) pc.free() pcs.free()
def test_tilefilter(self): """Check that the tilefilter returns the same number of points if not filtering, and correct number if filtering""" gen = cwipc.cwipc_synthetic() pc_orig = gen.get() pc_filtered = cwipc.cwipc_tilefilter(pc_orig, 0) self.assertEqual(len(pc_orig.get_points()), len(pc_filtered.get_points())) pc_filtered_1 = cwipc.cwipc_tilefilter(pc_orig, 1) pc_filtered_2 = cwipc.cwipc_tilefilter(pc_orig, 2) self.assertEqual( len(pc_orig.get_points()), len(pc_filtered_1.get_points()) + len(pc_filtered_2.get_points())) self.assertEqual(pc_orig.timestamp(), pc_filtered_1.timestamp()) self.assertEqual(pc_orig.timestamp(), pc_filtered_2.timestamp()) gen.free() pc_orig.free() pc_filtered.free() pc_filtered_1.free() pc_filtered_2.free()
def test_cwipc_multiencoder_octree_depth(self): """Test that a multiencoder setup for 2 octree depths returns sensible pointclouds""" gen = cwipc.cwipc_synthetic() pc_orig = gen.get() count_orig = len(pc_orig.get_points()) group = _cwipc_codec.cwipc_new_encodergroup() enc_high = group.addencoder(octree_bits=9) enc_low = group.addencoder(octree_bits=5) group.feed(pc_orig) self.assertTrue(enc_high.available(False)) self.assertTrue(enc_low.available(False)) data_high = enc_high.get_bytes() data_low = enc_low.get_bytes() self.assertLess(len(data_low), len(data_high)) # xxxjack todo: decompress both and compare group.free() pc_orig.free()
def test_downsample(self): """Check that the downsampler returns at most the same number of points and eventually returns 1""" gen = cwipc.cwipc_synthetic() pc_orig = gen.get() count_orig = len(pc_orig.get_points()) count_prev = count_orig factor = 1024 while factor > 0.0001: pc_filtered = cwipc.cwipc_downsample(pc_orig, factor) count_filtered = len(pc_filtered.get_points()) self.assertGreaterEqual(count_filtered, 1) self.assertLessEqual(count_filtered, count_orig) self.assertEqual(pc_orig.timestamp(), pc_filtered.timestamp()) count_prev = count_filtered pc_filtered.free() if count_filtered > count_orig / 2: break factor = factor / 2 gen.free() pc_orig.free()
def main(): global ISSUE_20 if hasattr(signal, 'SIGQUIT'): signal.signal(signal.SIGQUIT, _dump_app_stacks) parser = argparse.ArgumentParser(description="View pointcloud streams", epilog="Interactive commands:\n" + Visualizer.HELP, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument("--kinect", action="store_true", help="View Azure Kinect camera in stead of realsense2 camera") parser.add_argument("--synthetic", action="store_true", help="View synthetic pointcloud in stead of realsense2 camera") parser.add_argument("--certh", action="store", metavar="URL", help="View Certh pointcloud in stead of realsense2 camera, captured from Rabbitmq server URL") parser.add_argument("--data", action="store", metavar="NAME", help="Use NAME for certh data exchange (default: VolumetricData)", default="VolumetricData") parser.add_argument("--metadata", action="store", metavar="NAME", help="Use NAME for certh metadata exchange (default: VolumetricMetaData)", default="VolumetricMetaData") parser.add_argument("--file", action="store", metavar="FILE", help="Continually show pointcloud from ply file FILE ") parser.add_argument("--dir", action="store", metavar="DIR", help="Continually show pointclouds from ply files in DIR in alphabetical order") parser.add_argument("--dump", action="store_true", help="Playback .cwipcdump files in stead of .ply files with --file or --dump") parser.add_argument("--fps", action="store", type=int, help="Limit playback rate to FPS") parser.add_argument("--count", type=int, action="store", metavar="N", help="Stop after receiving N pointclouds") parser.add_argument("--nodisplay", action="store_true", help="Don't display pointclouds, only prints statistics at the end") parser.add_argument("--savecwicpc", action="store", metavar="DIR", help="Save compressed pointclouds to DIR") parser.add_argument("--verbose", action="store_true", help="Print information about each pointcloud after it has been received") args = parser.parse_args() # # Create source # if args.kinect: if cwipc.kinect == None: print(f"{sys.argv[0]}: No support for Kinect grabber on this platform") sys.exit(-1) source = cwipc.kinect.cwipc_kinect() elif args.synthetic: source = cwipc.cwipc_synthetic() elif args.certh: if cwipc.certh == None: print(f"{sys.argv[0]}: No support for CERTH grabber on this platform") sys.exit(-1) source = cwipc.certh.cwipc_certh(args.certh, args.data, args.metadata) elif args.file: source = cwipc.playback.cwipc_playback([args.file], ply=not args.dump, fps=args.fps, loop=True) elif args.dir: source = cwipc.playback.cwipc_playback(args.dir, ply=not args.dump, fps=args.fps, loop=True) else: if cwipc.realsense2 == None: print(f"{sys.argv[0]}: No support for realsense grabber on this platform") sys.exit(-1) source = cwipc.realsense2.cwipc_realsense2() if not args.nodisplay: visualizer = Visualizer(args.verbose) else: visualizer = None sourceServer = SourceServer(source, visualizer, count=args.count, verbose=args.verbose) sourceThread = threading.Thread(target=sourceServer.run, args=()) if visualizer: visualizer.set_producer(sourceThread) # # Run everything # try: sourceThread.start() if visualizer: visualizer.run() sourceServer.stop() sourceThread.join() except KeyboardInterrupt: print("Interrupted.") sourceServer.stop() except: traceback.print_exc() # # It is safe to call join (or stop) multiple times, so we ensure to cleanup # sourceServer.stop() sourceThread.join() sourceServer.statistics()