예제 #1
0
 def perturb_frame(frame, params):
     dims = frame.image.get_hw()
     rand_affine = RandomPerturber.generate_random_affine(
         dims / 2, dims, params)
     perturbed_frame = Frame(frame.image_path, copy.deepcopy(frame.objects))
     perturbed_frame.image = rand_affine.apply_to_image(frame.image, dims)
     for i, obj in enumerate(frame.objects):
         perturbed_frame.objects[i].box = rand_affine.apply_to_box(obj.box)
     return perturbed_frame
예제 #2
0
 def __load_labelled_frames(self, frame_dir, labels_file):
     files = [f for f in listdir(frame_dir) if isfile(join(frame_dir, f))]
     labels = KITTILabel.labels_from_file(
         labels_file) if labels_file is not None else []
     frames = []
     for f in files:
         file_index = int(splitext(basename(f))[0])
         objects = []
         for l in labels:
             if int(l.frame_idx) == file_index:
                 objects.append(l.to_object())
         frames.append(Frame(join(frame_dir, f), objects))
     return frames
예제 #3
0
 def perturb_frame(frame,params):
     dims = frame.image.get_hw()
     rand_affine = RandomPerturber.generate_random_affine(dims/2,dims,params)
     perturbed_frame = Frame(frame.image_path)
     perturbed_frame.image = rand_affine.apply_to_image(frame.image,dims)
     for i,obj in enumerate(frame.objects):
         # filter out completely out of bound objects
         perturbed_obj_box = rand_affine.apply_to_box(obj.box)
         perturbed_polygons = rand_affine.apply_to_polygons(obj.polygons)
         if Box.intersection(perturbed_obj_box,perturbed_frame.image.get_bounding_box()) is not None:
             obj_copy = copy.deepcopy(obj)
             obj_copy.box = perturbed_obj_box
             obj_copy.polygons = perturbed_polygons
             perturbed_frame.objects.append(obj_copy)
     return perturbed_frame
예제 #4
0
def apply_affine_to_frame(frame, affine, output_size):
    perturbed_frame = Frame(frame.image_path)
    perturbed_frame.image = affine.apply_to_image(frame.image, output_size)
    for i, obj in enumerate(frame.objects):
        # filter out completely out of bound objects
        perturbed_obj_box = affine.apply_to_box(obj.box)
        perturbed_polygons = affine.apply_to_polygons(obj.polygons)
        if Box.intersection(
                perturbed_obj_box,
                perturbed_frame.image.get_bounding_box()) is not None:
            obj_copy = copy.deepcopy(obj)
            obj_copy.box = perturbed_obj_box
            obj_copy.polygons = perturbed_polygons
            perturbed_frame.objects.append(obj_copy)
    return perturbed_frame
예제 #5
0
 def __load_labelled_frames(self,frame_dir,labels_file,calib_file=None):
     files = [f for f in listdir(frame_dir) if isfile(join(frame_dir, f))]
     labels = KITTILabel.labels_from_file(labels_file) if labels_file is not None else []
     calibration_mat = None
     if os.path.isfile(calib_file):
         calibration_mat = self.__load_camera_matrix_from_calib(calib_file)
     frames = []
     sorted_files = sorted(files, key=lambda x: int(splitext(basename(x))[0]))
     for f in sorted_files:
         file_index = int(splitext(basename(f))[0])
         objects = []
         for l in labels:
             if int(l.frame_idx) == file_index:
                 objects.append(l.to_object())
         frames.append(Frame(join(frame_dir,f),objs=objects,calib_mat=calibration_mat))
     return frames
예제 #6
0
 def __load_frames(self, cars_dir, labels_mat):
     print('Loading Stanford Cars Frames')
     labels = scipy.io.loadmat(labels_mat)['annotations'][0]
     # load frames with labels
     for label in labels:
         if len(label) == 5:
             xmin, ymin, xmax, ymax, path = label
         elif len(label) == 6:
             xmin, ymin, xmax, ymax, _, path = label
         else:
             assert False, 'unable to parse label!'
         box = Box(float(xmin[0][0]), float(ymin[0][0]), float(xmax[0][0]),
                   float(ymax[0][0]))
         obj = Object(box, obj_type='car')
         image_path = os.path.join(cars_dir, path[0])
         self.frames.append(Frame(image_path, [obj]))