From 3092299cb2bfe9939ae811b2ce1338ed0caecd2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Cartier-Michaud?= <gael.cartierm@hes-so.ch> Date: Mon, 4 Sep 2023 10:26:06 +0200 Subject: [PATCH] simplify harvest callback --- config/config_detect_only.yaml | 23 +++++++++++++++++++++++ config/config_laptop.yaml | 2 +- demo/detector.py | 30 +++++++++++++++--------------- 3 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 config/config_detect_only.yaml diff --git a/config/config_detect_only.yaml b/config/config_detect_only.yaml new file mode 100644 index 00000000..f5e46984 --- /dev/null +++ b/config/config_detect_only.yaml @@ -0,0 +1,23 @@ +# Configuration pour le laptop + +detector: + harvest : False + frame_before_exit : 30 + homography_path : './demo/homography_matrix.csv' + +cam : + dev_num : 2 + img_sz : [1280, 720] + pix_format : 'GREY' + brightness : 15 + +model : + path : './demo/model/model_demo.pt' + img_sz : [1280,1280] + show : True + verbose : False + +ip : + detectorIP : '192.168.125.42' + armIP : '192.168.125.1' + port : 50000 diff --git a/config/config_laptop.yaml b/config/config_laptop.yaml index 8eda96e1..3401c430 100644 --- a/config/config_laptop.yaml +++ b/config/config_laptop.yaml @@ -2,7 +2,7 @@ detector: harvest : True - frame_before_exit : 30 + frame_before_exit : 25 homography_path : './demo/homography_matrix.csv' cam : diff --git a/demo/detector.py b/demo/detector.py index e06d4150..c65e824b 100644 --- a/demo/detector.py +++ b/demo/detector.py @@ -27,25 +27,25 @@ class Detector : return config def __harvestCallback( self, predictor ) : - nothing = True - classes, coordinates = predictor.results[0].boxes.cls.cpu().numpy(), predictor.results[0].cpu().boxes.xywh.numpy() - for cl, coord in zip( classes, coordinates ) : - arm_coord = self.myArm.point_projection( (coord[0], coord[1]) ) - if not self.myArm.coordReachable( arm_coord ) or self.myModel.labelNum2Str( cl ) == 'hand' : pass - else : - nothing = False - if not self.harvest_job.is_alive() : + if not self.harvest_job.is_alive() : + nothing = True + classes, coordinates = predictor.results[0].boxes.cls.cpu().numpy(), predictor.results[0].cpu().boxes.xywh.numpy() + for cl, coord in zip( classes, coordinates ) : + arm_coord = self.myArm.point_projection( (coord[0], coord[1]) ) + if not self.myArm.coordReachable( arm_coord ) or self.myModel.labelNum2Str( cl ) == 'hand' : pass + else : + nothing = False print( "\n{} : x: {}, y: {}".format( self.myModel.labelNum2Str(cl), arm_coord[0], arm_coord[1] ) ) self.myArm.target = ( arm_coord[0], arm_coord[1], cl ) self.startHarvestJob() break - if nothing : self.nothing_counter += 1 - if self.isHarvestEnd() : - if not self.harvest_job.is_alive() : - print( "\n##### THE END #####\n") - self.myArm.target = ( 0, 0, self.myArm.end_value ) - self.startHarvestJob() - self.exit_status = True + if nothing : self.nothing_counter += 1 + if self.isHarvestEnd() : + if not self.harvest_job.is_alive() : + print( "\n##### THE END #####\n") + self.myArm.target = ( 0, 0, self.myArm.end_value ) + self.startHarvestJob() + self.exit_status = True def startHarvestJob( self ) : self.harvest_job = Thread( target = self.myArm.harvest, args = ( self.myArm.target, ) ) -- GitLab