Пример #1
0
    def __init__(self, app):
        Window.__init__(self, app, title="Test")
        self.tk.attributes("-fullscreen", True)
        self.hide()

        # Components
        Text(self, text="Test")
        Text(self, text="Horizontal")
        self.s1 = Slider(self, start=0, end=1736)
        self.s1.width = 500
        Text(self, text="Vertical")
        self.cb1 = CheckBox(self, text="Servo On")
        self.s2 = Slider(self, start=1200, end=1950)
        self.s2.width = 500
        self.s2.value = 1950
        self.cb2 = CheckBox(self, text="Vacuum On")

        def close_window():
            self.hide()
            self.cancel(update)
            self.s1.value = 0
            self.s2.value = 1950
            self.cb1.value = 0
            self.cb2.value = 0
            arm.set_vacuum(0)
            arm.reset()
            arm.set_servo(0)

        PushButton(self, command=close_window, text="Exit")
        global w
        w = self
Пример #2
0
    def __init__(self, app, text, cd, test_window, scanner_window):
        Window.__init__(self, app, title="MTG Sorter", layout="grid")
        self.tk.attributes("-fullscreen", True)

        # Top MenuBar
        def open_test():
            test_window.open_window()
        def open_scanner():
            scanner_window.show()

        def update_database():
            app.show()
            app.focus()
            cd.di = None
            cd.download(app_output=app, text_output=text)
        def toggle_fullscreen():
            global fullscreen
            fullscreen = not fullscreen
            self.tk.attributes("-fullscreen", fullscreen)
            test_window.tk.attributes("-fullscreen", fullscreen)
        def end_program():
            app.destroy()
        MenuBar(self,
                toplevel=["Windows", "Options"],
                options=[
                    [["Test", open_test], ["Scanner", open_scanner]],
                    [["Update Database", update_database], ["Toggle Fullscreen", toggle_fullscreen], ["End Program", end_program]]
                ])

        # Middle Card Type CheckBoxes
        Text(self, text="MTG Sorter", grid=[0, 0, 2, 1])
        Text(self, text="Slot 1 Types", grid=[0, 1])
        Text(self, text="Slot 2 Types", grid=[1, 1])
        types = ["Artifact", "Creature", "Enchantment", "Instant", "Land",
                 "Legendary", "Planeswalker", "Sorcery", "Tribal"]
        checkboxes1 = []
        for n in range(9):
            checkboxes1.append(CheckBox(self, text=types[n], grid=[0, n + 2]))
            checkboxes1[n].width = 22
            checkboxes1[n].text_size = 20
        checkboxes2 = []
        for n in range(9):
            checkboxes2.append(CheckBox(self, text=types[n], grid=[1, n + 2]))
            checkboxes2[n].width = 22
            checkboxes2[n].text_size = 20

        # Bottom Sort Cards Button
        def sort():

            # if nothing is selected in any column, do not sort
            nothing_selected1 = True
            for c in checkboxes1:
                if c.value:
                    nothing_selected1 = False
                    break
            nothing_selected2 = True
            for c in checkboxes2:
                if c.value:
                    nothing_selected2 = False
                    break
            if nothing_selected1 and nothing_selected2:
                print("nothing selected")
                return

            # reset arm to begin sorting
            arm.reset()
            print("Sorting cards...")

            # scan each card
            while True:
                img = scanner.scan_card()[3]
                if img is not None:
                    card = cd.get_card(img)
                    # if card isn't recognized, move it to bin 4
                    if card is None:
                        print("0")
                        arm.move_card(1, 4)
                    else:
                        card_type = card.type
                        print(card_type)
                        moved = False
                        # if card is any of the card types selected for the first bin, move it to bin 2
                        for c in checkboxes1:
                            if c.value:
                                if c.text in card_type:
                                    print("1")
                                    arm.move_card(1, 2)
                                    moved = True
                                    break
                        if moved:
                            continue
                        # if card is any of the card types selected for the second bin, move it to bin 3
                        for c in checkboxes2:
                            if c.value:
                                if c.text in card_type:
                                    print("2")
                                    arm.move_card(1, 3)
                                    break
                        if moved:
                            continue
                        # if card doesn't fit any of the selected types, move it to bin 4
                        print("0")
                        arm.move_card(1, 4)
                # if the tray is empty, end the sorting algorithm
                elif cd.is_empty():
                    print("tray is empty")
                    break
                # if the tray isn't empty but the card art can't be found, move the card to bin 4
                else:
                    print("0")
                    arm.move_card(1, 4)
            
            arm.set_servo(0)
        PushButton(self, command=sort, text="Sort Cards", grid=[0, 11, 2, 1])
Пример #3
0
    def __init__(self, app, text, cd, test_window, scanner_window):
        Window.__init__(self, app, title="MTG Sorter", layout="grid")
        self.tk.attributes("-fullscreen", True)

        # Components
        def open_test():
            test_window.open_window()

        def open_scanner():
            scanner_window.show()

        def update_database():
            app.show()
            app.focus()
            cd.di = None
            cd.download(app_output=app, text_output=text)

        def toggle_fullscreen():
            global fullscreen
            fullscreen = not fullscreen
            self.tk.attributes("-fullscreen", fullscreen)
            test_window.tk.attributes("-fullscreen", fullscreen)

        def end_program():
            app.destroy()

        MenuBar(self,
                toplevel=["Windows", "Program"],
                options=[[["Test", open_test], ["Scanner", open_scanner]],
                         [["Update Database", update_database],
                          ["Toggle Fullscreen", toggle_fullscreen],
                          ["End Program", end_program]]])
        Text(self, text="MTG Sorter", grid=[0, 0, 2, 1])
        Text(self, text="Slot 1 Types", grid=[0, 1])
        Text(self, text="Slot 2 Types", grid=[1, 1])
        types = [
            "Artifact", "Creature", "Enchantment", "Instant", "Land",
            "Legendary", "Planeswalker", "Sorcery", "Tribal"
        ]
        checkboxes1 = []
        for n in range(9):
            checkboxes1.append(CheckBox(self, text=types[n], grid=[0, n + 2]))
            checkboxes1[n].width = 22
            checkboxes1[n].text_size = 20
        checkboxes2 = []
        for n in range(9):
            checkboxes2.append(CheckBox(self, text=types[n], grid=[1, n + 2]))
            checkboxes2[n].width = 22
            checkboxes2[n].text_size = 20

        def sort():
            nothing_selected1 = True
            for c in checkboxes1:
                if c.value:
                    nothing_selected1 = False
                    break
            nothing_selected2 = True
            for c in checkboxes2:
                if c.value:
                    nothing_selected2 = False
                    break
            if nothing_selected1 and nothing_selected2:
                print("nothing selected")
                return
            arm.reset()
            print("Sorting cards...")
            while True:
                img = scanner.scan_card()[3]
                if img is not None:
                    card = cd.get_card(img)
                    if card is None:
                        print("0")
                        arm.move_card(1, 2)
                    else:
                        card_type = card.type
                        print(card_type)
                        moved = False
                        for c in checkboxes1:
                            if c.value:
                                if c.text in card_type:
                                    print("1")
                                    arm.move_card(1, 3)
                                    moved = True
                                    break
                        if moved:
                            continue
                        for c in checkboxes2:
                            if c.value:
                                if c.text in card_type:
                                    print("2")
                                    arm.move_card(1, 4)
                                    break
                        if moved:
                            continue
                        print("0")
                        arm.move_card(1, 2)
                elif cd.is_empty():
                    print("tray is empty")
                    break
                else:
                    print("0")
                    arm.move_card(1, 2)
            arm.set_servo(0)

        PushButton(self, command=sort, text="Sort Cards", grid=[0, 11, 2, 1])
Пример #4
0
    def __init__(self, app):
        Window.__init__(self, app, title="Scanner", layout="grid")
        self.tk.attributes("-fullscreen", True)
        self.hide()

        # Components
        Text(self, text="Scanner", grid=[0, 0, 3, 1])

        Text(self, text="Empty", grid=[0, 1])
        p1 = Picture(self, image="data/empty.jpg", grid=[0, 2])
        p1.height = 194
        p1.width = 259

        def update_empty():
            database.save_empty()
            p1.value = "data/empty.jpg"

        PushButton(self,
                   command=update_empty,
                   text="Retake Empty",
                   grid=[0, 7])

        Text(self, text="Scan", grid=[1, 1, 2, 1])
        p2 = Picture(self, image="data/testpic.jpg", grid=[1, 2])
        p2.height = 194
        p2.width = 259
        p3 = Picture(self, image="data/testscan.jpg", grid=[2, 2])
        p3.height = 135
        p3.width = 184
        m1 = Text(self, text="Card:", grid=[1, 6])

        def update_scan():
            global last_scan
            out = scanner.scan_card(img=last_scan)
            last_scan = out[0]
            if out[1] is not None:
                if len(out[1]) > 0:
                    cv2.drawContours(last_scan, out[1], -1, (0, 255, 0), 2)
            if out[2] is not None:
                cv2.drawContours(last_scan, [out[2]], -1, (255, 0, 0), 2)
            cv2.imwrite("data/testpic.jpg", last_scan)
            p2.value = "data/testpic.jpg"
            if out[3] is not None:
                cv2.imwrite("data/testscan.jpg", out[3])
                p3.value = "data/testscan.jpg"
                card = database.get_card(out[3])
                if card is None:
                    m1.value = "Card: Not Found"
                else:
                    m1.value = "Card: " + card.name

        def update_lower():
            scanner.lower = s1.value
            update_scan()

        s1 = Slider(self, command=update_lower, start=0, end=255, grid=[1, 3])
        s1.value = scanner.lower
        s1.width = 259

        def update_upper():
            scanner.upper = s2.value
            update_scan()

        s2 = Slider(self, command=update_upper, start=0, end=255, grid=[2, 3])
        s2.value = scanner.upper
        s2.width = 259

        def update_width_min():
            scanner.width_min = s3.value
            update_scan()

        s3 = Slider(self,
                    command=update_width_min,
                    start=0,
                    end=1500,
                    grid=[1, 4])
        s3.value = scanner.width_min
        s3.width = 259

        def update_width_max():
            scanner.width_max = s4.value
            update_scan()

        s4 = Slider(self,
                    command=update_width_max,
                    start=0,
                    end=1500,
                    grid=[2, 4])
        s4.value = scanner.width_max
        s4.width = 259

        def update_height_min():
            scanner.height_min = s5.value
            update_scan()

        s5 = Slider(self,
                    command=update_height_min,
                    start=0,
                    end=1500,
                    grid=[1, 5])
        s5.value = scanner.height_min
        s5.width = 259

        def test_scanner():
            out = scanner.scan_card()
            global last_scan
            last_scan = out[0]
            if out[1] is not None:
                if len(out[1]) > 0:
                    cv2.drawContours(last_scan, out[1], -1, (0, 255, 0), 2)
            if out[2] is not None:
                cv2.drawContours(last_scan, [out[2]], -1, (255, 0, 0), 2)
            cv2.imwrite("data/testpic.jpg", last_scan)
            p2.value = "data/testpic.jpg"
            if out[3] is not None:
                cv2.imwrite("data/testscan.jpg", out[3])
                p3.value = "data/testscan.jpg"
                card = database.get_card(out[3])
                if card is None:
                    m1.value = "Card: Not Found"
                else:
                    m1.value = "Card: " + card.name

        PushButton(self, command=test_scanner, text="Scan", grid=[1, 7])

        def close_scanner():
            self.hide()

        PushButton(self, command=close_scanner, text="Exit", grid=[0, 8, 2, 1])
Пример #5
0
    def __init__(self, app, cd):
        Window.__init__(self, app, title="Scanner", layout="grid")
        CD = cd
        self.tk.attributes("-fullscreen", True)
        self.hide()

        # Scanner page title
        Text(self, text="Scanner", grid=[0, 0, 3, 1])

        # Empty column 0
        Text(self, text="Empty", grid=[0, 1])
        p1 = Picture(self, image="data/empty.jpg", grid=[0, 2])
        p1.height = 194
        p1.width = 259

        def update_empty():
            cd.save_empty()
            p1.value = "data/empty.jpg"

        PushButton(self,
                   command=update_empty,
                   text="Retake Empty",
                   grid=[0, 7])

        # Scan columns 1 & 2
        Text(self, text="Scan", grid=[1, 1, 2, 1])
        p2 = Picture(self, image="data/testpic.jpg", grid=[1, 2])
        p2.height = 194
        p2.width = 259
        p3 = Picture(self, image="data/testscan.jpg", grid=[2, 2])
        p3.height = 135
        p3.width = 184
        m1 = Text(self, text="Card: Tragic Arrogance", grid=[1, 3, 2, 1])

        # Scan parameter sliders
        def update_width_min():
            scanner.width_min = s1.value

        s1 = Slider(self,
                    command=update_width_min,
                    start=0,
                    end=1500,
                    grid=[1, 4, 2, 1])
        s1.value = scanner.width_min

        def update_width_max():
            scanner.width_max = s2.value

        s2 = Slider(self,
                    command=update_width_max,
                    start=0,
                    end=1500,
                    grid=[1, 5, 2, 1])
        s2.value = scanner.width_max

        def update_height_min():
            scanner.height_min = s3.value

        s3 = Slider(self,
                    command=update_height_min,
                    start=0,
                    end=1500,
                    grid=[1, 6, 2, 1])
        s3.value = scanner.height_min

        # Scan button
        def test_scanner():
            # use scanner to scan card and set last_scan as image taken
            out = scanner.scan_card()
            global last_scan
            last_scan = out[0]

            # draw contours of left boundary and min-max width x min height box
            # in red within image dimensions 2592 x 1944
            lb = scanner.left_boundary

            hb = (1944 - scanner.height_min) / 2
            ht = 1944 - hb
            wnb = (2592 - scanner.width_min) / 2
            wnt = 2592 - wnb
            wxb = (2592 - scanner.width_max) / 2
            wxt = 2592 - wxb

            red = [
                np.array([[[lb, 0]], [[lb, 0]], [[lb, 1943]], [[lb, 1943]]],
                         dtype=np.int32),
                np.array([[[wnb, hb]], [[wnt, hb]], [[wnt, ht]], [[wnb, ht]]],
                         dtype=np.int32),
                np.array([[[wxb, hb]], [[wxt, hb]], [[wxt, ht]], [[wxb, ht]]],
                         dtype=np.int32)
            ]

            cv2.drawContours(last_scan, red, -1, (0, 0, 255), 2)

            # if any contours were detected, draw them in green
            if out[1] is not None:
                if len(out[1]) > 0:
                    cv2.drawContours(last_scan, out[1], -1, (0, 255, 0), 3)

            # if artwork contour was detected, draw it in blue
            if out[2] is not None:
                cv2.drawContours(last_scan, [out[2]], -1, (255, 0, 0), 4)

            # save last_scan
            cv2.imwrite("data/testpic.jpg", last_scan)
            p2.value = "data/testpic.jpg"

            # if artwork image was detected, save it and display the
            # corresponding card name if one is found
            if out[3] is not None:
                cv2.imwrite("data/testscan.jpg", out[3])
                p3.value = "data/testscan.jpg"
                card = CD.get_card(out[3])
                if card is None:
                    m1.value = "Card: Not Found"
                else:
                    m1.value = "Card: " + card.name

        PushButton(self, command=test_scanner, text="Scan", grid=[1, 7, 2, 1])

        # Exit button
        def close_scanner():
            self.hide()

        PushButton(self, command=close_scanner, text="Exit", grid=[0, 8, 3, 1])