Open wizholy opened 5 years ago
def __parse_annotation(self, annotation): line = annotation.split() image_path = line[0] image = np.array(cv2.imread(image_path)) bboxes = np.array([map(int, box.split(',')) for box in line[1:]]) image, bboxes = data_aug.random_horizontal_flip(np.copy(image), np.copy(bboxes)) image, bboxes = data_aug.random_crop(np.copy(image), np.copy(bboxes)) image, bboxes = data_aug.random_translate(np.copy(image), np.copy(bboxes)) image, bboxes = utils.img_preprocess2(np.copy(image), np.copy(bboxes), (self.train_input_size, self.train_input_size), True) bboxes_temp=[] bboxes[:,0:4]=np.maximum(bboxes[:,0:4],0) bboxes[:,0:4]=np.minimum(bboxes[:,0:4],image.shape[0]) for bbox in bboxes: if bbox[0]>=bbox[2] or bbox[1]>=bbox[3]: continue if bbox[0]>image.shape[0] or bbox[1]>image.shape[1]: continue bboxes_temp.append(bbox) return image, np.array(bboxes_temp)
def __parse_annotation(self, annotation): line = annotation.split() image_path = line[0] image = np.array(cv2.imread(image_path)) bboxes = np.array([map(int, box.split(',')) for box in line[1:]]) image, bboxes = data_aug.random_horizontal_flip(np.copy(image), np.copy(bboxes)) image, bboxes = data_aug.random_crop(np.copy(image), np.copy(bboxes)) image, bboxes = data_aug.random_translate(np.copy(image), np.copy(bboxes)) image, bboxes = utils.img_preprocess2(np.copy(image), np.copy(bboxes), (self.train_input_size, self.train_input_size), True) bboxes_temp=[] bboxes[:,0:4]=np.maximum(bboxes[:,0:4],0) bboxes[:,0:4]=np.minimum(bboxes[:,0:4],image.shape[0]) for bbox in bboxes: if bbox[0]>=bbox[2] or bbox[1]>=bbox[3]: continue if bbox[0]>image.shape[0] or bbox[1]>image.shape[1]: continue bboxes_temp.append(bbox) return image, np.array(bboxes_temp)