def get_slingshot_center(self): ground_truth = self.ar.get_ground_truth_without_screenshot() ground_truth_reader = GroundTruthReader(ground_truth, self.look_up_matrix, self.look_up_obj_type) sling = ground_truth_reader.find_slingshot_mbr()[0] sling.width, sling.height = sling.height, sling.width self.sling_center = self.tp.get_reference_point(sling)
def _updateReader(self, dtype): ''' update the ground truth reader with 4 different types of ground truth if the ground truth is vaild otherwise, return the state. str type : groundTruth_screenshot , groundTruth, NoisygroundTruth_screenshot,NoisygroundTruth ''' self.showGroundTruth = False if dtype == 'groundTruth_screenshot': image, ground_truth = self.ar.get_ground_truth_with_screenshot() vision = GroundTruthReader(ground_truth, self.look_up_matrix, self.look_up_obj_type) vision.set_screenshot(image) self.showGroundTruth = True # draw the ground truth with screenshot or not elif dtype == 'groundTruth': ground_truth = self.ar.get_ground_truth_without_screenshot() vision = GroundTruthReader(ground_truth, self.look_up_matrix, self.look_up_obj_type) elif dtype == 'NoisygroundTruth_screenshot': image, ground_truth = self.ar.get_noisy_ground_truth_with_screenshot( ) vision = GroundTruthReader(ground_truth, self.look_up_matrix, self.look_up_obj_type) vision.set_screenshot(image) self.showGroundTruth = True # draw the ground truth with screenshot or not elif dtype == 'NoisygroundTruth': ground_truth = self.ar.get_noisy_ground_truth_without_screenshot() vision = GroundTruthReader(ground_truth, self.look_up_matrix, self.look_up_obj_type) return vision
def sample_state(self, request=RequestCodes.GetNoisyGroundTruthWithScreenshot, frequency=0.5): """ sample a state from the observer agent this method allows to be run in a different thread NOTE: Setting the frequency too high, i.e. <0.01 may cause lag in science birds game due to the calculation of the groundtruth """ while (True): vision = None if request == RequestCodes.GetGroundTruthWithScreenshot: image, ground_truth = self.observer_ar.get_ground_truth_with_screenshot( ) # set to true to ignore invalid state and return the vision object regardless # of #birds and #pigs vision = GroundTruthReader(ground_truth, self.look_up_matrix, self.look_up_obj_type) vision.set_screenshot(image) elif request == RequestCodes.GetGroundTruthWithoutScreenshot: ground_truth = self.observer_ar.get_ground_truth_without_screenshot( ) vision = GroundTruthReader(ground_truth, self.look_up_matrix, self.look_up_obj_type) elif request == RequestCodes.GetNoisyGroundTruthWithScreenshot: image, ground_truth = self.observer_ar.get_noisy_ground_truth_with_screenshot( ) vision = GroundTruthReader(ground_truth, self.look_up_matrix, self.look_up_obj_type) vision.set_screenshot(image) elif request == RequestCodes.GetNoisyGroundTruthWithoutScreenshot: ground_truth = self.observer_ar.get_noisy_ground_truth_without_screenshot( ) vision = GroundTruthReader(ground_truth, self.look_up_matrix, self.look_up_obj_type) time.sleep(frequency)