diff --git a/libs/perception/container.py b/libs/perception/container.py index 3f31447..f9bf2c4 100755 --- a/libs/perception/container.py +++ b/libs/perception/container.py @@ -4,7 +4,7 @@ # Authors: # - Yik Lung Pang: y.l.pang@qmul.ac.uk # - Alessio Xompero: a.xompero@qmul.ac.uk -# +# - Tommaso Apicella: t.apicella@qmul.ac.uk # MIT License # Copyright (c) 2021 CORSMAL @@ -219,6 +219,7 @@ def __init__(self, args, ncams): self.zt1 = None self.zt = None + self.visualise_LoDE = args.visualise_LoDE @@ -301,7 +302,7 @@ def computeAnglesRad(self): self.anglesrad = anglesrad - def ShapeFitting(self, _c1, _c2, _objmask1, _objmask2, h_step, r_step): + def ShapeFitting(self, _c1, _c2, _objmask1, _objmask2, h_step, r_step, rgb1, rgb2): c1 = copy.deepcopy(_c1) c2 = copy.deepcopy(_c2) @@ -382,7 +383,19 @@ def ShapeFitting(self, _c1, _c2, _objmask1, _objmask2, h_step, r_step): if (np.count_nonzero(areIn_c1) == areIn_c1.shape[0]) and (np.count_nonzero(areIn_c2) == areIn_c2.shape[0]): converged_circ = True - break + if self.visualise_LoDE: + for p, isIn in zip(p2d_c1, areIn_c1): + if isIn: + cv2.circle(rgb1, (int(p[0]), int(p[1])), 2, (255, 0, 0), -1) + else: + cv2.circle(rgb1, (int(p[0]), int(p[1])), 2, (0, 0, 255), -1) + + for p, isIn in zip(p2d_c2, areIn_c2): + if isIn: + cv2.circle(rgb2, (int(p[0]), int(p[1])), 2, (255, 0, 0), -1) + else: + cv2.circle(rgb2, (int(p[0]), int(p[1])), 2, (0, 0, 255), -1) + break if rad==minDiameter/2: break @@ -400,6 +413,12 @@ def ShapeFitting(self, _c1, _c2, _objmask1, _objmask2, h_step, r_step): self.estRadius = convRadius[round(0.1*len(convRadius)):round(0.9*len(convRadius))] self.estHeights = convHeights[round(0.1*len(convHeights)):round(0.9*len(convHeights))] + if self.visualise_LoDE: + dim = (rgb1.shape[1] // 2, rgb2.shape[0] // 2) + cv2.imshow("LoDE [blue] and object mask [green]", np.hstack([cv2.resize(rgb1, dim, interpolation=cv2.INTER_AREA), + cv2.resize(rgb2, dim, interpolation=cv2.INTER_AREA)])) + cv2.waitKey(10) + # Localisation and dimension estimation via shape reconstruction in 3D # Output: @@ -462,7 +481,7 @@ def LoDE(self, rgb1, rgb2, c1, c2, instances1, instances2, h_step, r_step): objmask2 = np.uint8(255.* (instances2['masks'][j] >= 0.5)) # print('ShapeFitting') - self.ShapeFitting(c1, c2, objmask1, objmask2, h_step, r_step) + self.ShapeFitting(c1, c2, objmask1, objmask2, h_step, r_step, rgb1, rgb2) # print('ComputeDimensions') # Compute container dimensions diff --git a/perception_pipeline.py b/perception_pipeline.py index 7ba9580..78d3ce1 100644 --- a/perception_pipeline.py +++ b/perception_pipeline.py @@ -4,11 +4,12 @@ # Author: Ricardo Sanchez Matilla # Author: Yik Lung Pang # Author: Alessio Xompero +# Author: Tommaso Apicella # Email: corsmal-benchmark@qmul.ac.uk # # # Created Date: 2020/02/13 -# Modified Date: 2020/10/05 +# Modified Date: 2022/10/24 # # Centre for Intelligent Sensing, Queen Mary University of London, UK # @@ -137,6 +138,7 @@ def PublicTestingDataParser(args): parser.add_argument('--use_LoDE', type=int, choices=[0,1], default=0) parser.add_argument('--LoDE_hstep', type=float, default=0.001) parser.add_argument('--LoDE_rstep', type=float, default=18.0) + parser.add_argument('--visualise_LoDE', type=bool, default=False) parser.add_argument('--record', type=int, choices=[0,1], default=0) parser.add_argument('--max_num_frames', type=int, default=-1) # Path to videos