Exemple #1
0
 def set_obj_at_50(self):
     # Get number of occluders in frame 50
     frame_num = 50
     scene_num = 1
     mask = MaskInfo(self.dataDir / self.test_num_string / str(scene_num))
     mask.get_objects_for_frame(frame_num)
     self.obj = mask.clean_up_O3_50()
Exemple #2
0
    def compare_masks(self):
        block_num = 1
        test_num = 36
        scene_num = 2
        frame_num = 33
        data_dir = data_dir_base + "/O" + str(block_num) + "/"

        mask1 = MaskInfo(Path(data_dir + str(test_num).zfill(4) + "/" + str(scene_num)), frame_num)
        frame_num = 92
        mask2 = MaskInfo(Path(data_dir + str(test_num).zfill(4) + "/" + str(scene_num)), frame_num)
        result = MaskInfo.are_masks_same(mask1, mask2)
        print(" Same:  {}".format(result))
Exemple #3
0
 def is_scene_static(self, masks_list):
     """ Go through all the masks and see if they are the same;  if any are different, then not static"""
     # print("length of masks:  {}".format(len(masks_list)))
     for frame_num in range(2, 100):
         same_obj = MaskInfo.are_masks_same(masks_list[1], masks_list[frame_num])
         if not same_obj:
             return False
     return True
Exemple #4
0
    def write_out_status_for_scene(self, scene_num):

        # Crate the json object
        status_json = {}
        header = {}
        header["test"] = self.test_num
        # header["scene"] = scene_num
        status_json["header"] = header

        # Make sure there are the same number of occluders in the scene over all frames
        num = -1
        frames = []
        for frame_num in range(1, 101):
            frame_info = {}
            frame_info["frame"] = frame_num
            mask_info = {}

            mask = MaskInfo(self.dataDir / self.test_num_string / str(scene_num), frame_num)
            obj = mask.get_obj()
            if num == -1:
                num = len(obj)
            elif len(obj) != num:
                print("Problem in test {} scene {} frame {}. Wrong num ".format(self.test_num, scene_num, frame_num))
                print("expected {} but got {}".format(str(num), len(obj)))
                return

            occluder_counter = 1
            # this will sort the occluders by the left-most pixel
            listofTuples = sorted(obj.items(), key=lambda x: x[1].minx)
            for elem in listofTuples:
                # print(elem[0], " ::", elem[1])
                occluder_name = "occluder" + str(occluder_counter)
                mask_info[occluder_name] = elem[0]
                occluder_counter = occluder_counter + 1
            frame_info["masks"] = mask_info
            frames.append(frame_info)
        status_json["frames"] = frames

        # This one includes the scene num
        #         status_path = Path(("status/status_" + str(self.test_num) + "_" + str(scene_num) + ".json"))
        status_path = Path(("status/status_" + str(self.test_num).zfill(4) + ".json"))
        with status_path.open("w") as outfile:
            json.dump(status_json, outfile, indent=4)

        print("wrote out data for test {}".format(self.test_num))
Exemple #5
0
    def update_slider(self, val):
        # Change the frame
        frame_num = int(self.frame_slider.val)
        # self.process_mask(self.dataDir / self.test_num_string, frame_num)

        # match occluders
        mask = MaskInfo(self.dataDir / self.test_num_string / str(1))
        all_obj = mask.get_objects_for_frame(frame_num)
        new_obj = self.get_matched_obj(self.obj, all_obj)

        # Draw the images
        for scene_num in range(0, 4):
            img_src = self.get_overlaid_image(frame_num, scene_num)
            self.axs[scene_num].imshow(img_src)

        self.obj = new_obj

        self.fig.canvas.draw_idle()
Exemple #6
0
    def get_max_count_objects(self, block_num, test_num):
        data_dir = data_dir_base + "/O" + str(block_num) + "/"
        max_count = -1

        # Number of occluders is determined for frame 50
        scene_num = 1
        frame_num = 50
        mask = MaskInfo(Path(data_dir + str(test_num).zfill(4) + "/" + str(scene_num)), frame_num)
        if block_num == 3:
            mask.clean_up_O3()
        else:
            mask.clean_up_occluders()
        num_occluders = mask.get_num_occluders()

        num_static_scene = 0
        for scene_num in range(1, 5):
            masks_list = []
            for frame_num in range(1, 101):

                mask = MaskInfo(Path(data_dir + str(test_num).zfill(4) + "/" + str(scene_num)), frame_num)
                masks_list.append(mask)
                count = mask.get_num_obj()
                max_count = count if count > max_count else max_count
                # print("num obj: {}  occluders: {}".format(count, current_occluders))

            # see if the objects in the mask have same min/max x/y over all of them, in which case it is static
            if self.is_scene_static(masks_list):
                num_static_scene += 1

        # ground and sky are always there
        num_obj = max_count - num_occluders - 2
        if num_obj < 1:
            print("Problem with {} {}".format(block_num, test_num))

        static_scene = False
        if num_static_scene == 2:
            static_scene = True

        return (num_occluders, num_obj, static_scene)
Exemple #7
0
    def write_to_occ_or_not(self):
        # which scene and frame
        scene_num = 1
        frame_num = 50

        # The image
        frame_num_string = str(frame_num).zfill(3)
        image_name = self.dataDir / self.test_num_string / str(1) / "scene" / (
            "scene_" + frame_num_string + ".png")
        img_src = Image.open(image_name)

        mask = MaskInfo(self.dataDir / self.test_num_string / str(scene_num))
        mask.get_objects_for_frame(frame_num)
        obj = mask.clean_up_O3_50()
        if len(obj) == 0:
            img_src.save("./has_no_occluder/test_" + self.test_num_string +
                         ".png")
            print("Test {} has no occ".format(self.test_num_string))
        else:
            img_src.save("./has_occluder/test_" + str(len(obj)) + "_" +
                         self.test_num_string + ".png")
            print("Test {} has occ {}".format(self.test_num_string, len(obj)))
Exemple #8
0
    def count_objects(self):
        block_num = 1
        test_num = 1
        scene_num = 2
        frame_num = 33
        data_dir = data_dir_base + "/O" + str(block_num) + "/"
        mask = MaskInfo(Path(data_dir + str(test_num).zfill(4) + "/" + str(scene_num)), frame_num)

        # should be 2, ground and sky
        print("Num objects: {}".format(mask.get_num_orig_objects()))

        # should be 4
        frame_num = 53
        mask = MaskInfo(Path(data_dir + str(test_num).zfill(4) + "/" + str(scene_num)), frame_num)
        print("Num objects: {}".format(mask.get_num_orig_objects()))

        block_num = 3
        test_num = 69
        scene_num = 1
        frame_num = 95
        data_dir = data_dir_base + "/O" + str(block_num) + "/"
        # should be 5
        mask = MaskInfo(Path(data_dir + str(test_num).zfill(4) + "/" + str(scene_num)), frame_num)
        print("Num objects: {}".format(mask.get_num_orig_objects()))
Exemple #9
0
 def process_mask(self, mask_path, frame_num):
     self.masks.clear()
     for scene in range(4):
         self.masks.append(MaskInfo(mask_path / str(scene + 1), frame_num))
Exemple #10
0
    def write_out_status_for_scene(self, scene_num):
        # Create the json object
        status_json = {}
        header = {}
        header["test"] = self.test_num
        # header["scene"] = scene_num
        status_json["header"] = header

        # Get number of occluders in frame 50
        frame_num = 50
        mask = MaskInfo(self.dataDir / self.test_num_string / str(scene_num))
        mask.get_objects_for_frame(frame_num)
        obj_50 = mask.clean_up_O3_50()

        # If no occluders in frame 50, write out and return
        if len(obj_50) == 0:
            frames = []
            for frame_num in range(1, 101):
                frame_info = {}
                frame_info["frame"] = frame_num
                mask_info = {}
                frame_info["masks"] = mask_info
                frames.append(frame_info)
            status_json["frames"] = frames
            status_path = Path(
                ("status/status_" + str(self.test_num).zfill(4) + ".json"))
            with status_path.open("w") as outfile:
                json.dump(status_json, outfile, indent=4)
            print("Wrote no occluders for {}".format(self.test_num_string))
            return

        # Dictionary to hold the frame information, since not sequential
        frame_dict = {}

        # Get the info for frame 50
        print("found {} occluders in test {}".format(len(obj_50),
                                                     self.test_num_string))

        frame_info = {}
        frame_info["frame"] = frame_num
        mask_info = {}
        listofTuples = sorted(obj_50.items(), key=lambda x: x[1].minx)
        occluder_counter = 1
        for elem in listofTuples:
            occluder_name = "occluder" + str(occluder_counter)
            mask_info[occluder_name] = elem[0]
            occluder_counter = occluder_counter + 1
        frame_info["masks"] = mask_info
        frame_dict[50] = frame_info

        # go forward in time
        last_obj = obj_50
        for frame_num in range(51, 101):
            frame_info = {}
            frame_info["frame"] = frame_num
            mask_info = {}

            mask = MaskInfo(self.dataDir / self.test_num_string /
                            str(scene_num))
            current_obj = mask.get_objects_for_frame(frame_num)
            match_obj = self.get_matched_obj(last_obj, current_obj)

            if len(match_obj) != len(last_obj):
                print(
                    "Problem in test {} scene {} frame {}. Wrong num ".format(
                        self.test_num, scene_num, frame_num))
                print("expected {} but got {}".format(str(len(last_obj)),
                                                      str(len(match_obj))))
                return

            occluder_counter = 1
            # this will sort the occluders by the left-most pixel
            listofTuples = sorted(match_obj.items(), key=lambda x: x[1].minx)
            for elem in listofTuples:
                # print(elem[0], " ::", elem[1])
                occluder_name = "occluder" + str(occluder_counter)
                mask_info[occluder_name] = elem[0]
                occluder_counter = occluder_counter + 1
            frame_info["masks"] = mask_info
            frame_dict[frame_num] = frame_info

            last_obj = match_obj

        # go backward in time
        last_obj = obj_50
        for frame_num in range(49, 0, -1):
            frame_info = {}
            frame_info["frame"] = frame_num
            mask_info = {}

            mask = MaskInfo(self.dataDir / self.test_num_string /
                            str(scene_num))
            current_obj = mask.get_objects_for_frame(frame_num)
            match_obj = self.get_matched_obj(last_obj, current_obj)

            if len(match_obj) != len(last_obj):
                print(
                    "Problem in test {} scene {} frame {}. Wrong num ".format(
                        self.test_num, scene_num, frame_num))
                print("expected {} but got {}".format(str(len(last_obj)),
                                                      str(len(match_obj))))
                return

            occluder_counter = 1
            # this will sort the occluders by the left-most pixel
            listofTuples = sorted(match_obj.items(), key=lambda x: x[1].minx)
            for elem in listofTuples:
                # print(elem[0], " ::", elem[1])
                occluder_name = "occluder" + str(occluder_counter)
                mask_info[occluder_name] = elem[0]
                occluder_counter = occluder_counter + 1
            frame_info["masks"] = mask_info
            frame_dict[frame_num] = frame_info

            last_obj = match_obj

        # convert from frame_dict to frames
        frames = []
        for frame_num in range(1, 101):
            frames.append(frame_dict[frame_num])
        status_json["frames"] = frames

        # This one includes the scene num
        #         status_path = Path(("status/status_" + str(self.test_num) + "_" + str(scene_num) + ".json"))
        status_path = Path(
            ("status/status_" + str(self.test_num).zfill(4) + ".json"))
        with status_path.open("w") as outfile:
            json.dump(status_json, outfile, indent=4)

        print("wrote out data for test {}".format(self.test_num))