コード例 #1
0
ファイル: calibrator.py プロジェクト: OustanDing/NESTrisOCR
    def setupTab3(self):
        f = tk.Frame(self.calibrationTabs)
        self.previewPiece = CompactRectChooser(
            f,
            "Next Piece (imagePerc)",
            config["calibration.pct.preview"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.preview"),
        )
        self.previewPiece.grid()

        canvasSize = [UPSCALE * 2 * i for i in PreviewImageSize]
        self.previewImage = ImageCanvas(f, canvasSize[0], canvasSize[1])
        self.previewImage.grid()

        self.samplePreviewImage = ImageCanvas(f, canvasSize[0], canvasSize[1])
        img = LoadSamplePreview()
        img = img.resize(canvasSize)
        self.samplePreviewImage.updateImage(img)
        self.samplePreviewImage.grid()
        self.samplePreviewLabel = tk.Label(
            f, text="Crop to a 2x4 block area with no black pixel borders")
        self.samplePreviewLabel.grid()

        self.wsamplePreviewImage = ImageCanvas(f, canvasSize[0], canvasSize[1])
        img = LoadSamplePreview2()
        img = img.resize(canvasSize)
        self.wsamplePreviewImage.updateImage(img)
        self.wsamplePreviewImage.grid()
        self.wsamplePreviewLabel = tk.Label(
            f, text="Example of bad calibration (extra pixel borders)")
        self.wsamplePreviewLabel.grid()

        self.calibrationTabs.add(f, text="PreviewPiece")
コード例 #2
0
ファイル: calibrator.py プロジェクト: OustanDing/NESTrisOCR
    def setupTab1(self):
        f = tk.Frame(self.calibrationTabs)
        canvasSize = [UPSCALE * i for i in finalImageSize(3)]
        Button(
            f,
            text="Auto Adjust Lines \nNeeds Lines = 000",
            command=self.autoLines,
            bg="red",
        ).grid(row=0, column=0)

        self.linesPerc = CompactRectChooser(
            f,
            "lines (imagePerc)",
            config["calibration.pct.lines"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.lines"),
        )
        self.linesPerc.grid(row=0, column=1, rowspan=2)
        self.linesImage = ImageCanvas(f, canvasSize[0], canvasSize[1])
        self.linesImage.grid(row=1, column=0)

        canvasSize = [UPSCALE * i for i in finalImageSize(6)]
        Button(
            f,
            text="Auto Adjust Score \n Needs Score = 000000",
            command=self.autoScore,
            bg="red",
        ).grid(row=2, column=0)
        self.scorePerc = CompactRectChooser(
            f,
            "score (imagePerc)",
            config["calibration.pct.score"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.score"),
        )
        self.scorePerc.grid(row=2, column=1, rowspan=2)
        self.scoreImage = ImageCanvas(f, canvasSize[0], canvasSize[1])
        self.scoreImage.grid(row=3, column=0)

        canvasSize = [UPSCALE * i for i in finalImageSize(2)]
        Button(
            f,
            text="Auto Adjust Level \n Needs Level = 00",
            command=self.autoLevel,
            bg="red",
        ).grid(row=4, column=0)
        self.levelPerc = CompactRectChooser(
            f,
            "level (imagePerc)",
            config["calibration.pct.level"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.level"),
        )
        self.levelPerc.grid(row=4, column=1, rowspan=2)
        self.levelImage = ImageCanvas(f, canvasSize[0], canvasSize[1])
        self.levelImage.grid(row=5, column=0)
        self.calibrationTabs.add(f, text="NumberOCR")
コード例 #3
0
ファイル: calibrator.py プロジェクト: OustanDing/NESTrisOCR
    def setupTab2(self):
        f = tk.Frame(self.calibrationTabs)

        self.fieldCapture = tk.Frame(f)
        self.fieldCapture.grid(row=0, columnspan=2)

        self.fieldChooser = CompactRectChooser(
            self.fieldCapture,
            "field (imagePerc)",
            config["calibration.pct.field"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.field"),
        )
        self.fieldChooser.grid(row=0)

        self.colorCapture = tk.Frame(self.fieldCapture)
        self.colorCapture.grid(row=1)

        self.color1Chooser = CompactRectChooser(
            self.colorCapture,
            "Color1 (imagePerc)\nSelect whole block without black border",
            config["calibration.pct.color1"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.color1"),
        )
        self.color1Chooser.grid(row=0, column=0)
        self.color1Image = ImageCanvas(self.colorCapture, colorsImageSize[0],
                                       colorsImageSize[1])
        self.color1Image.grid(row=0, column=1)

        self.color2Chooser = CompactRectChooser(
            self.colorCapture,
            "Color2 (imagePerc)\nSelect whole block without black border",
            config["calibration.pct.color2"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.color2"),
        )
        self.color2Chooser.grid(row=1, column=0)
        self.color2Image = ImageCanvas(self.colorCapture, colorsImageSize[0],
                                       colorsImageSize[1])
        self.color2Image.grid(row=1, column=1)

        self.calibrationTabs.add(f, text="FieldStats")
コード例 #4
0
ファイル: calibrator.py プロジェクト: OustanDing/NESTrisOCR
    def setupPlaybackTabs(self):
        self.playbackTabs = ttk.Notebook(self)

        # capture device output
        f = tk.Frame(self.playbackTabs)
        border = tk.Frame(f)
        border.grid(row=4, column=0, sticky="nsew")
        border.config(relief=tk.FLAT, bd=5, background="orange")
        self.boardImage = ImageCanvas(border, 512, 224 * 2)
        self.boardImage.pack()

        self.playbackTabs.add(f, text="Capture Device")

        # game output
        f = tk.Frame(self.playbackTabs)
        self.boardImage2 = ImageCanvas(f, 240, 224)
        self.boardImage2.grid(row=0, column=0, sticky="E")
        self.stateVisualizer = StateVisualizer(f)
        self.stateVisualizer.grid(row=0, column=1, sticky="W")
        self.playbackTabs.add(f, text="OCR Output")
コード例 #5
0
ファイル: calibrator.py プロジェクト: OustanDing/NESTrisOCR
    def setupTab4(self):
        f = tk.Frame(self.calibrationTabs)
        self.flashChooser = CompactRectChooser(
            f,
            "Flash (imagePerc)",
            config["calibration.pct.flash"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.flash"),
        )
        self.flashChooser.grid(row=1, columnspan=2)

        self.blackWhiteCapture = tk.Frame(f)
        self.blackWhiteCapture.grid(row=2, columnspan=2)

        self.blackWhiteChooser = CompactRectChooser(
            self.blackWhiteCapture,
            "Black and White\nSelect an area with both pure white and pure black",
            config["calibration.pct.black_n_white"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.black_n_white"),
        )
        self.blackWhiteChooser.grid(row=0, column=0)
        self.blackWhiteImage = ImageCanvas(self.blackWhiteCapture,
                                           blackWhiteImageSize[0],
                                           blackWhiteImageSize[1])
        self.blackWhiteImage.grid(row=0, column=1)

        self.pieceStatsChooser = CompactRectChooser(
            f,
            "pieceStats (imagePerc)",
            config["calibration.pct.stats"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.stats"),
        )
        self.pieceStatsChooser.grid(row=3, columnspan=2)

        self.setDynamicBWVisible()
        self.setStatsTextVisible()
        self.calibrationTabs.add(f, text="Misc.")
コード例 #6
0
ファイル: calibrator.py プロジェクト: OustanDing/NESTrisOCR
    def setupTab5(self):
        f = tk.Frame(self.calibrationTabs)

        self.dasEnabledChooser = BoolChooser(
            f,
            "Enable DAS Trainer specific capturing",
            config["calibration.capture_das"],
            self.gen_set_config_and_redraw("calibration.capture_das"),
        )
        self.dasEnabledChooser.grid(row=0, columnspan=2)

        # Current Piece
        canvasSize = [UPSCALE * 2 * i for i in CurPieceImageSize]
        self.dasCurrentPieceImage = ImageCanvas(f, canvasSize[0],
                                                canvasSize[1])
        self.dasCurrentPieceImage.grid(row=1, column=0)

        self.dasCurrentPieceChooser = CompactRectChooser(
            f,
            "Current Piece (imagePerc)",
            config["calibration.pct.das.current_piece"],
            True,
            self.gen_set_config_and_redraw(
                "calibration.pct.das.current_piece"),
        )
        self.dasCurrentPieceChooser.grid(row=1, column=1)

        # Instant DAS
        canvasSize = [UPSCALE * i for i in finalImageSize(2)]

        Button(
            f,
            text="Auto Adjust Instant DAS \n Needs CURRENT DAS = 00",
            command=self.autoInstantDas,
            bg="red",
        ).grid(row=2, column=0)
        self.instantDasPercChooser = CompactRectChooser(
            f,
            "instantDas (imagePerc)",
            config["calibration.pct.das.instant_das"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.das.instant_das"),
        )
        self.instantDasPercChooser.grid(row=2, column=1, rowspan=2)
        self.instantDasImage = ImageCanvas(f, canvasSize[0], canvasSize[1])
        self.instantDasImage.grid(row=3, column=0)

        # Current piece DAS
        Button(
            f,
            text="Auto Adjust Current Piece DAS \n Needs START DAS = 00",
            command=self.autoCurrentPieceDas,
            bg="red",
        ).grid(row=4, column=0)

        self.currentPieceDasPercChooser = CompactRectChooser(
            f,
            "currentPieceDas (imagePerc)",
            config["calibration.pct.das.current_piece_das"],
            True,
            self.gen_set_config_and_redraw(
                "calibration.pct.das.current_piece_das"),
        )
        self.currentPieceDasPercChooser.grid(row=4, column=1, rowspan=2)
        self.currentPieceDasImage = ImageCanvas(f, canvasSize[0],
                                                canvasSize[1])
        self.currentPieceDasImage.grid(row=5, column=0)

        self.calibrationTabs.add(f, text="DasTrainer")
コード例 #7
0
    def __init__(self, config):
        self.config = config
        root = tk.Tk()
        super().__init__(root)
        root.protocol("WM_DELETE_WINDOW", self.on_exit)
        root.focus_force()
        root.wm_title("NESTrisOCR calibrator")
        self.pack()
        self.root = root
        self.destroying = False
        root.config(background="black")
        StringChooser(
            self,
            "capture window starts with:",
            config["calibration.source_id"],
            self.gen_set_config_and_redraw("calibration.source_id"),
            100,  # source ids can be local file or openCV stream URLs
        ).grid(row=0, sticky="nsew")
        StringChooser(
            self,
            "player name",
            config["player.name"],
            partial(config.__setitem__, "player.name"),
            20,
        ).grid(row=1, sticky="nsew")
        if ENABLE_OTHER_OPTIONS:
            Button(
                self,
                text="Other options",
                command=lambda: create_window(root, self.config, self.
                                              otherOptionsClosed),
            ).grid(row=0, column=1)

        # window coords
        f = tk.Frame(self)
        r = RectChooser(
            f,
            "capture window coords (pixels)",
            config["calibration.game_coords"],
            False,
            self.update_game_coords,
        )
        r.config(relief=tk.FLAT, bd=5, background="orange")
        r.pack(side=tk.LEFT)
        self.winCoords = r
        # auto calibrate
        border = tk.Frame(f)
        border.config(relief=tk.FLAT, bd=5, background="orange")
        border.pack(side=tk.RIGHT, fill="both")
        autoCalibrate = Button(
            border,
            text="Automatically detect field",
            command=self.autoDetectField,
            bg="red",
        )
        autoCalibrate.pack(fill="both", expand=True)
        f.grid(row=2, column=0)

        # refresh
        Button(self, text="Refresh Image",
               command=self.redrawImages).grid(row=2, column=1, sticky="nsew")

        border = tk.Frame(self)
        border.grid(row=3, column=0, sticky="nsew")
        border.config(relief=tk.FLAT, bd=5, background="orange")
        self.boardImage = ImageCanvas(border, 512, 224 * 2)
        self.boardImage.pack()

        self.tabManager = ttk.Notebook(self)
        self.tabManager.grid(row=3, column=1, sticky="nsew")
        self.tabManager.bind("<<NotebookTabChanged>>", self.redrawImages)

        self.setupTab1()
        self.setupTab2()
        self.setupTab3()
        self.setupTab4()
        self.setPreviewTextVisible()

        self.redrawImages()
        self.lastUpdate = time.time()
コード例 #8
0
    def setupTab2(self):
        f = tk.Frame(self.tabManager)

        self.fieldCapture = tk.Frame(f)
        self.fieldCapture.grid(row=0, columnspan=2)

        self.fieldChooser = CompactRectChooser(
            self.fieldCapture,
            "field (imagePerc)",
            config["calibration.pct.field"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.field"),
        )
        self.fieldChooser.grid(row=0)

        self.colorCapture = tk.Frame(self.fieldCapture)
        self.colorCapture.grid(row=1)

        self.color1Chooser = CompactRectChooser(
            self.colorCapture,
            "Color1 (imagePerc)\nSelect whole block without black border",
            config["calibration.pct.color1"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.color1"),
        )
        self.color1Chooser.grid(row=0, column=0)
        self.color1Image = ImageCanvas(self.colorCapture, colorsImageSize[0],
                                       colorsImageSize[1])
        self.color1Image.grid(row=0, column=1)

        self.color2Chooser = CompactRectChooser(
            self.colorCapture,
            "Color2 (imagePerc)\nSelect whole block without black border",
            config["calibration.pct.color2"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.color2"),
        )
        self.color2Chooser.grid(row=1, column=0)
        self.color2Image = ImageCanvas(self.colorCapture, colorsImageSize[0],
                                       colorsImageSize[1])
        self.color2Image.grid(row=1, column=1)

        self.flashChooser = CompactRectChooser(
            f,
            "Flash (imagePerc)",
            config["calibration.pct.flash"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.flash"),
        )
        self.flashChooser.grid(row=1, columnspan=2)

        self.blackWhiteCapture = tk.Frame(self.fieldCapture)
        self.blackWhiteCapture.grid(row=2, columnspan=2)

        self.blackWhiteChooser = CompactRectChooser(
            self.blackWhiteCapture,
            "Black and White\nSelect an area with both pure white and pure black",
            config["calibration.pct.black_n_white"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.black_n_white"),
        )
        self.blackWhiteChooser.grid(row=0, column=0)
        self.blackWhiteImage = ImageCanvas(self.blackWhiteCapture,
                                           blackWhiteImageSize[0],
                                           blackWhiteImageSize[1])
        self.blackWhiteImage.grid(row=0, column=1)

        self.pieceStatsChooser = CompactRectChooser(
            f,
            "pieceStats (imagePerc)",
            config["calibration.pct.stats"],
            True,
            self.gen_set_config_and_redraw("calibration.pct.stats"),
        )
        self.pieceStatsChooser.grid(row=3, columnspan=2)

        self.setFieldTextVisible()
        self.setStatsTextVisible()
        self.tabManager.add(f, text="FieldStats")