From b54b1aba1f601968f2784d6f5f451214afe59a2e Mon Sep 17 00:00:00 2001 From: Mathieu Beligon <mathieu.beligon@gmail.com> Date: Sun, 22 Mar 2020 14:58:57 -0400 Subject: [PATCH] WIP --- .../common/pipeline/debug_pipeline.py | 4 +++- .../common/view/cv2_results_viewer.py | 5 +++++ robots-at-robots/config/settings.toml | 2 +- .../research/demos/demo_pipeline_camera.py | 21 ++++++++----------- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/common/polystar/common/pipeline/debug_pipeline.py b/common/polystar/common/pipeline/debug_pipeline.py index c5822a5..869e171 100644 --- a/common/polystar/common/pipeline/debug_pipeline.py +++ b/common/polystar/common/pipeline/debug_pipeline.py @@ -11,6 +11,7 @@ from polystar.common.pipeline.pipeline import Pipeline @dataclass class DebugInfo: + success: bool = False detected_objects: List[Object] = field(init=False) validated_objects: List[Object] = field(init=False) selected_object: Object = field(init=False) @@ -24,9 +25,10 @@ class DebugPipeline(Pipeline): debug_info_: DebugInfo = field(init=False, default_factory=DebugInfo) def predict_target(self, image: Image) -> TargetABC: - self.debug_info_ = DebugInfo() + #self.debug_info_ = DebugInfo() target = super().predict_target(image) self.debug_info_.target = target + self.debug_info_.success = True def predict_best_object(self, image: Image) -> Object: best_object = super().predict_best_object(image) diff --git a/common/polystar/common/view/cv2_results_viewer.py b/common/polystar/common/view/cv2_results_viewer.py index 3894982..30218d2 100644 --- a/common/polystar/common/view/cv2_results_viewer.py +++ b/common/polystar/common/view/cv2_results_viewer.py @@ -33,6 +33,11 @@ class CV2ResultViewer(ResultViewerABC): self.finished = False super().__init__(COLORS) + def __enter__(self): + cv2.namedWindow(self.name, cv2.WINDOW_NORMAL) + cv2.resizeWindow(self.name, 720, 480) + return self + def __exit__(self, exc_type, exc_val, exc_tb): cv2.destroyWindow(self.name) diff --git a/robots-at-robots/config/settings.toml b/robots-at-robots/config/settings.toml index fe532b0..ec0e563 100644 --- a/robots-at-robots/config/settings.toml +++ b/robots-at-robots/config/settings.toml @@ -1,5 +1,5 @@ [default] -MODEL_NAME = 'robots/TRT_ssd_mobilenet_v2_roco.bin' +MODEL_NAME = 'robots/TRT_ssd_mobilenet_v2_roco_2018_03_29_20200314_015411_TWITCH_TEMP_733_IMGS_29595steps.bin' [development] diff --git a/robots-at-robots/research/demos/demo_pipeline_camera.py b/robots-at-robots/research/demos/demo_pipeline_camera.py index b340ec2..8e0abd4 100644 --- a/robots-at-robots/research/demos/demo_pipeline_camera.py +++ b/robots-at-robots/research/demos/demo_pipeline_camera.py @@ -38,7 +38,7 @@ if __name__ == "__main__": objects_validators=[ConfidenceObjectValidator(0.6), TypeObjectValidator(ObjectType.Armor)], object_selector=ClosestObjectSelector(), target_factory=RatioSimpleTargetFactory(injector.get(Camera), 300, 100), - target_sender=FileDescriptorTargetSender(int(sys.argv[1])), + target_sender=PrintTargetSender(), # FileDescriptorTargetSender(int(sys.argv[1])), ) fps = 0 @@ -48,18 +48,15 @@ if __name__ == "__main__": viewer.new(image) previous_time = time() try: - # inference pipeline.predict_target(image) - - # display + except NoTargetFound: + pass + if pipeline.debug_info_.success: viewer.add_objects(pipeline.debug_info_.validated_objects, forced_color=(0.6, 0.6, 0.6)) viewer.add_object(pipeline.debug_info_.selected_object) + fps = 0.9 * fps + 0.1 / (time() - previous_time) + viewer.add_text(f"FPS: {fps:.1f}", 10, 10, (0, 0, 0)) + viewer.display() - if viewer.finished: - break - except NoTargetFound: - pass - finally: - fps = 0.9 * fps + 0.1 / (time() - previous_time) - viewer.add_text(f"FPS: {fps:.1f}", 10, 10, (0, 0, 0)) - viewer.display() + if viewer.finished: + break -- GitLab