Ejemplo n.º 1
0
    def load_image(self, fn):
        # Load the image
        GrLog.clear()
        try:
            params_loaded = self.board.load_image(fn, f_with_params=True)
            self.origImgPanel.set_image(self.board.image)
            self.imgMask.scaled_mask = self.board.area_mask
            self.imgButtons['reset'].disabled = not self.board.can_reset_image

            # Reset button state to default
            for key in self.imgButtons.keys():
                self.imgButtons[key].state = False
            self.imgButtons['black'].state = True
            self.imgButtons['white'].state = True

            # Process image
            self.update_board(reprocess=False)

            # Update status
            if GrLog.numErrors() > 0:
                self.statusInfo.set("Errors during file loading, see the log")
            else:
                ftitle = ": "
                if params_loaded: ftitle = " (with params): "
                self.statusInfo.set_file("File loaded" + ftitle,
                                         self.board.image_file)

        except:
            logging.exception("Error")
            self.statusInfo.set("Error when loading image, see the log")
Ejemplo n.º 2
0
    def load_annotation(self, file):
        """Load annotation from file"""

        GrLog.clear()
        try:
            # Load annotation file
            fn, src, shape, bboxes = self.dataset.load_annotation(file)

            # Load image
            img = cv2.imread(fn)
            if img is None:
                raise Exception('File not found {}'.format(fn))

            # Resize the image
            self.boardImgName = fn
            self.annoName = file
            self.srcName = src
            self.imgFrame.pack_propagate(False)

            self.imgPanel.image = img  # this adopts image to frame max_size
            img2 = self.imgPanel.image  # image to draw upon

            # Process objects
            for bb in bboxes:
                # Get coordinates
                p1 = self.imgPanel.image2frame((bb[0][0], bb[0][1]))
                p2 = self.imgPanel.image2frame((bb[1][0], bb[1][1]))
                cls = bb[2]

                # Draw a bounding box
                clr = (0, 0, 255)
                if cls == "black": clr = (255, 0, 0)

                if self.f_rect:
                    cv2.rectangle(img2, p1, p2, clr, 1)
                else:
                    d = max(p2[0] - p1[0], p2[1] - p1[1])
                    x = int(p1[0] + d / 2)
                    y = int(p1[1] + d / 2)
                    cv2.circle(img2, (x, y), int(d / 2), clr, 1)

            self.imgPanel.image = img2  # display image with drawing on the panel

            # Update status
            stage = self.dataset.get_stage(self.boardImgName)
            img_info = "Size: ({}, {}), stage: {}".format(
                img.shape[1], img.shape[0], stage)
            self.imgInfo.set(img_info)

            if GrLog.numErrors() > 0:
                self.statusInfo.set("Errors during processing, see the log")
            else:
                self.statusInfo.set_file('File loaded: ', self.annoName)
        except:
            logging.exception('Error')
            self.statusInfo.set("Errors during processing, see the log")
Ejemplo n.º 3
0
    def update_all_callback(self):
        self.update_img_size()

        GrLog.clear()
        try:
            self.dataset.generate_dataset()
            if GrLog.numErrors() > 0:
                self.statusInfo.set("Errors during processing, see the log")
            else:
                self.statusInfo.set("Dataset updated")
        except:
            logging.exception('Error')
            self.statusInfo.set("Errors during processing, see the log")
            return
Ejemplo n.º 4
0
    def update_anotation(self):
        """Updates annotation for currently loaded file"""
        GrLog.clear()

        # Check whether JGF exists
        # If not - image goes to test dataset, stones should not be stored in annotation
        jgf_file = Path(self.dataset.src_path).joinpath(
            Path(self.boardImgName).name).with_suffix('.jgf')
        f_process = jgf_file.is_file()
        logging.info('Board file {} exists: {}'.format(jgf_file, f_process))

        try:
            # Load board from annotation file
            # This will find the image and load it to the board
            board = GrBoard()
            board.load_annotation(self.annoName,
                                  self.dataset,
                                  f_process=f_process)

            # Determine stage to store image to
            stage = self.dataset.get_stage(self.boardImgName)
            logging.info('Current stage {}'.format(stage))
            if stage is None:
                stage = 'test'
                if not board.results is None: stage = 'train'

            # Save annortation
            board.save_annotation(self.annoName,
                                  self.dataset,
                                  anno_only=False,
                                  stage=stage)

            # Update status
            stage = self.dataset.get_stage(self.boardImgName)
            img_info = "Size: ({}, {}), stage: {}".format(self.imgPanel.image.shape[1], \
                                                          self.imgPanel.image.shape[0], \
                                                          stage)
            self.imgInfo.set(img_info)

            if GrLog.numErrors() > 0:
                self.statusInfo.set("Errors during processing, see the log")
            else:
                self.statusInfo.set("Dataset updated")
        except:
            logging.exception('Error')
            self.statusInfo.set("Errors during processing, see the log")
            return
Ejemplo n.º 5
0
def main():
    window = tk.Tk()
    window.title("View annotaitons")

    log = GrLog.init()
    gui = ViewAnnoGui(window)

    window.mainloop()
Ejemplo n.º 6
0
def main():
    window = tk.Tk()
    window.title("Go board tagging")

    log = GrLog.init()
    gui = GrTagGui(window)

    window.mainloop()

    cv2.destroyAllWindows()
Ejemplo n.º 7
0
    def apply_def_callback(self):
        """Apply defaults button handler"""
        if self.board.is_gen_board:
            return

        p = DEF_GR_PARAMS.copy()
        self.board.params = p
        for key in self.tkVars.keys():
            self.tkVars[key].set(p[key])
        self.update_board(reprocess=True)
        if GrLog.numErrors() == 0:
            self.statusInfo.set("No errors")
Ejemplo n.º 8
0
    def apply_callback(self):
        """Apply param changes button handler"""
        if self.board.is_gen_board:
            return

        p = dict()
        for key in self.tkVars.keys():
            p[key] = self.tkVars[key].get()
        self.board.params = p
        self.update_board(reprocess=True)
        if GrLog.numErrors() == 0:
            self.statusInfo.set("No errors")
Ejemplo n.º 9
0
    def update_board(self, reprocess=True):
        # Process original image
        if self.board.results is None or reprocess:
            GrLog.clear()
            try:
                self.board.process()
                if GrLog.numErrors() > 0:
                    self.statusInfo.set(
                        "Errors during processing, see the log")
            except:
                logging.exception("Error")
                self.statusInfo.set("Error during processing, see the log")
                return

        # Generate board using analysis results
        btn_state = dict()
        for key in self.imgButtons.keys():
            btn_state[key] = self.imgButtons[key].state
        self.genImgPanel.set_image(self.board.show_board(show_state=btn_state))

        if self.board.results is None:
            self.boardInfo.set("")
        else:
            board_size = self.board.board_size
            black_stones = self.board.black_stones
            white_stones = self.board.white_stones

            self.boardInfo.set(
                "Board size: {}, black stones: {}, white stones: {}".format(
                    board_size, black_stones.shape[0], white_stones.shape[0]))

        # Update params
        p = self.board.params
        for key in p.keys():
            if key in self.tkVars.keys():
                self.tkVars[key].set(p[key])

        # Update debug info
        self.add_debug_info(self.dbgFrame, self.board.board_shape,
                            self.board.debug_images, self.board.debug_info)
Ejemplo n.º 10
0
def main():
    # Construct interface
    window = tk.Tk()
    window.title("Go board")

    log = GrLog.init()
    gui = GbrGUI(window)

    # Main loop
    window.mainloop()

    # Clean up
    cv2.destroyAllWindows()
Ejemplo n.º 11
0
 def show_log_callback(self):
     """Show log button handler"""
     GrLog.show(self.root)
Ejemplo n.º 12
0
 def show_log_callback(self):
     GrLog.show(self.root)