def btn_auto_check_click(self, button):
        status = ImageInfo.GetAllStatuses(self.image_info)

        false_status = [(2 if val > 0 else 0) for val in status]
        panel_info = self.image_info.panels[self.selected_panel]

        self.unsaved_changes = True
        panel_info.properties["auto_check_passed"] = 0

        # class ...
        if status[1] >= 1:
            try:
                tempo_json = ChartJSON_Exporter.prepare_chart_image_json(
                    panel_info, false_status, 1, False)
                print("Task 1: Annotation Seems Okay!")
                self.save_json_file(tempo_json, "TEMPO_VALID_JSON.json")
            except Exception as e:
                print("Errors on Task 1 data (Chart Image Classification): " +
                      str(e))
                return

        # text detection, classification and recognition ...
        if status[2] >= 1:
            try:
                tempo_json = ChartJSON_Exporter.prepare_chart_image_json(
                    panel_info, false_status, 3, False)
                print("Tasks 2 and 3: Annotation Seems Okay!")
                self.save_json_file(tempo_json, "TEMPO_VALID_JSON.json")
            except Exception as e:
                print(
                    "Errors on Task 2 or 3 (Text Detection, Recognition, and Classification): "
                    + str(e))
                return

        if status[3] >= 1 and status[4] >= 1:
            try:
                tempo_json = ChartJSON_Exporter.prepare_chart_image_json(
                    panel_info, false_status, 5, False)
                print("Tasks 4 and 5: Annotation Seems Okay!")
                self.save_json_file(tempo_json, "TEMPO_VALID_JSON.json")
            except Exception as e:
                print(
                    "Errors on Task 4 and/or 5 (Axes and Legend Recognition): "
                    + str(e))
                return

        if status[5] >= 1:
            try:
                tempo_json = ChartJSON_Exporter.prepare_chart_image_json(
                    panel_info, false_status, 7, False)
                print("Tasks 6a/6b: Annotation Seems Okay!")
                self.save_json_file(tempo_json, "TEMPO_VALID_JSON.json")
            except Exception as e:
                print("Errors on Task 6a/6b (Data Extraction): " + str(e))
                return

        panel_info.properties["auto_check_passed"] = 1
        print("Chart meets all annotation requirements!")
Esempio n. 2
0
    def load_page(self, paginator, new_page, refresh=False):
        if new_page == self.current_page and not refresh:
            # page not changed ...
            return

        self.current_page = new_page

        page_size = len(self.thumbnails_images)

        current_elements = self.chart_image_list[self.current_page *
                                                 page_size:(self.current_page +
                                                            1) * page_size]

        for idx in range(page_size):
            row = int(idx / self.tb_grid_cols)
            col = idx % self.tb_grid_cols

            if idx < len(current_elements):
                # update image ...
                chart_path = current_elements[idx]
                current_img = cv2.imread(self.chart_dir + chart_path)
                current_img = cv2.cvtColor(current_img, cv2.COLOR_BGR2RGB)
                self.thumbnails_images[idx].set_image(current_img,
                                                      self.tb_width,
                                                      self.tb_height,
                                                      keep_aspect=True)

                # center new image
                corner_x = self.tb_outer_margin + self.tb_col_width * col
                corner_y = self.tb_outer_margin + self.tb_row_height * row
                self.center_image_in_box(self.thumbnails_images[idx], corner_x,
                                         corner_y, self.tb_width,
                                         self.tb_height)

                # find annotation path ...
                relative_dir, img_filename = os.path.split(chart_path)
                img_base, ext = os.path.splitext(img_filename)
                # output dir
                output_dir = self.annotation_dir + relative_dir
                annotation_filename = output_dir + "/" + img_base + ".xml"

                # default : No annotations ...
                if os.path.exists(annotation_filename):
                    # read the annotation ...
                    print(annotation_filename)
                    image_info = ImageInfo.FromXML(annotation_filename,
                                                   current_img)

                    status_ints = ImageInfo.GetAllStatuses(image_info)
                else:
                    status_ints = ImageInfo.GetAllStatuses(None)

                status = self.gen_status_image(status_ints, self.tb_width,
                                               self.tb_progress_h,
                                               self.tb_progress_border)
                self.thumbnails_status[idx].set_image(status, self.tb_width,
                                                      self.tb_progress_h)

                self.thumbnails_labels[idx].set_text(chart_path[1:])

                self.thumbnails_images[idx].visible = True
                self.thumbnails_status[idx].visible = True
                self.thumbnails_labels[idx].visible = True
            else:
                # special case for the last page ...
                self.thumbnails_images[idx].visible = False
                self.thumbnails_status[idx].visible = False
                self.thumbnails_labels[idx].visible = False

        msg = "Page {0:d} of {1:d} ({2:d} elements)".format(
            self.current_page + 1, self.paginator.total_pages,
            len(self.chart_image_list))
        self.lbl_page_descriptor.set_text(msg)

        if not refresh:
            self.selected_element = None
            self.update_selected_image(0)
    def __load_data(self, cache_all_annotations):
        # Load image list from dir ...
        self.img_list = ImageInfo.ListChartDirectory(self.img_dir, "")
        self.auto_check_stats = {
            "total_no_annotation": 0,
            "total_multi_panel": 0,
            "total_no_test": 0,
            "total_passed": 0,
            "total_failed": 0,
        }

        for idx, chart_path in enumerate(self.img_list):
            current_img = None

            # find annotation path ...
            relative_dir, img_filename = os.path.split(chart_path)

            img_base, ext = os.path.splitext(img_filename)
            # output dir
            output_dir = self.annotation_dir + relative_dir
            annotation_filename = output_dir + "/" + img_base + ".xml"

            if os.path.exists(annotation_filename):
                self.img_annotations.append(annotation_filename)
                self.total_annotation_files += 1

                image_info = ImageInfo.FromXML(annotation_filename,
                                               current_img)
                if len(image_info.panels) == 1:
                    # add to single panel index
                    self.all_single_panel.append(idx)

                    type_desc, orientation = image_info.panels[
                        0].get_description()
                    if orientation == "":
                        current_type = type_desc
                    else:
                        current_type = "{0:s} ({1:s})".format(
                            type_desc, orientation)
                    # if type_desc in ["non-chart"]:
                    #     print(annotation_filename)

                    status_ints = ImageInfo.GetAllStatuses(image_info)
                    self.img_statuses.append(status_ints)

                    if current_type in self.single_per_type:
                        self.single_per_type[current_type].append(
                            (idx, status_ints))
                    else:
                        self.single_per_type[current_type] = [(idx,
                                                               status_ints)]

                    if not "auto_check_passed" in image_info.panels[
                            0].properties:
                        self.auto_check_stats["total_no_test"] += 1
                    else:
                        if int(image_info.panels[0].
                               properties["auto_check_passed"]) > 0:
                            self.auto_check_stats["total_passed"] += 1
                        else:
                            self.auto_check_stats["total_failed"] += 1
                else:
                    # add to multi-panel index
                    self.all_multi_panel.append(idx)
                    # TODO: multi-panel case is not handled yet ...

                    self.img_statuses.append(None)
                    self.auto_check_stats["total_multi_panel"] += 1

                # keep or discard the current annotation ...
                if cache_all_annotations:
                    self.cache_annotations.append(image_info)
                else:
                    self.cache_annotations.append(None)
            else:
                self.img_annotations.append(None)
                self.cache_annotations.append(None)
                self.img_statuses.append(ImageInfo.GetNullStatuses())
                self.auto_check_stats["total_no_annotation"] += 1
Esempio n. 4
0
    def __init__(self, img_dir, annotation_dir, cache_all_annotations=False):

        self.img_dir = img_dir
        self.annotation_dir = annotation_dir

        # Load image list from dir ...
        self.img_list = ImageInfo.ListChartDirectory(img_dir, "")

        self.total_annotation_files = 0

        self.img_annotations = []
        self.cache_annotations = []
        self.img_statuses = []

        self.all_single_panel = []
        self.all_multi_panel = []
        self.single_per_type = {}

        for idx, chart_path in enumerate(self.img_list):
            current_img = None

            # find annotation path ...
            relative_dir, img_filename = os.path.split(chart_path)

            img_base, ext = os.path.splitext(img_filename)
            # output dir
            output_dir = self.annotation_dir + relative_dir
            annotation_filename = output_dir + "/" + img_base + ".xml"

            if os.path.exists(annotation_filename):
                self.img_annotations.append(annotation_filename)
                self.total_annotation_files += 1

                image_info = ImageInfo.FromXML(annotation_filename,
                                               current_img)
                if len(image_info.panels) == 1:
                    # add to single panel index
                    self.all_single_panel.append(idx)

                    type_desc, orientation = image_info.panels[
                        0].get_description()
                    if orientation == "":
                        current_type = type_desc
                    else:
                        current_type = "{0:s} ({1:s})".format(
                            type_desc, orientation)

                    status_ints = ImageInfo.GetAllStatuses(image_info)
                    self.img_statuses.append(status_ints)

                    if current_type in self.single_per_type:
                        self.single_per_type[current_type].append(
                            (idx, status_ints))
                    else:
                        self.single_per_type[current_type] = [(idx,
                                                               status_ints)]

                else:
                    # add to multi-panel index
                    self.all_multi_panel.append(idx)
                    # TODO: multi-panel case is not handled yet ...

                    self.img_statuses.append(None)
                # keep or discard the current annotation ...
                if cache_all_annotations:
                    self.cache_annotations.append(image_info)
                else:
                    self.cache_annotations.append(None)
            else:
                self.img_annotations.append(None)
                self.cache_annotations.append(None)
                self.img_statuses.append(ImageInfo.GetNullStatuses())