Exemplo n.º 1
0
    def __init__(self, root):
        self.root = root
        self.root.protocol("WM_DELETE_WINDOW", self.onExit)

        self.videothread = Video()
        self.videothread.setFile('')
        # self.videothread.setFile(0)
        self.videothread.start()

        BUTTONWIDTH = 15
        SPINBOXWIDTH = 6
        ########################################################
        frame = Frame(self.root, padx=5)
        frame.grid(row=0, column=0, rowspan=2)

        self.butpick = Button(frame,
                              text="Open File",
                              fg='#991111',
                              width=BUTTONWIDTH,
                              command=self.pick)
        self.butpick.pack(side=TOP)
        self.butwebcam = Button(frame,
                                text='Camera',
                                fg='#991111',
                                width=BUTTONWIDTH,
                                command=self.webcam)
        self.butwebcam.pack(side=TOP)

        ########################################################
        Frame(self.root)
        ########################################################

        frame = Frame(self.root)
        frame.grid(row=0, column=1, columnspan=4, rowspan=2)

        self.filestr = StringVar()
        self.filestr.set("Open a video file or open your camera.")
        self.labfile = Label(frame, textvariable=self.filestr)
        self.labfile.pack(pady=4)

        self.butplay = Button(frame,
                              text="Play",
                              fg='#116611',
                              width=BUTTONWIDTH,
                              command=self.run)
        self.butplay.pack(side=LEFT, padx=5)

        self.butstop = Button(frame,
                              text="Stop",
                              fg='#116611',
                              width=BUTTONWIDTH,
                              command=self.stop)
        self.butstop.pack(side=LEFT, padx=5)

        self.butrew = Button(frame,
                             text="Rewind",
                             fg='#116611',
                             width=BUTTONWIDTH,
                             command=self.rewind)
        self.butrew.pack(side=LEFT, padx=5)
        #######################################################
        Frame(self.root, height=10).grid(row=4, column=0, columnspan=3)
        #######################################################
        self.butfilgrayscale = Button(self.root,
                                      text="Grayscale",
                                      fg='#111166',
                                      width=BUTTONWIDTH,
                                      command=self.grayscale)
        self.butfilgrayscale.grid(row=5, column=0)

        self.butfilinvert = Button(self.root,
                                   text="Invert",
                                   fg='#111166',
                                   width=BUTTONWIDTH,
                                   command=self.invert)
        self.butfilinvert.grid(row=5, column=1)

        self.butfilhisteql = Button(self.root,
                                    text="Histogram equal",
                                    fg='#111166',
                                    width=BUTTONWIDTH,
                                    command=self.histeql)
        self.butfilhisteql.grid(row=5, column=2)

        self.butfiledges = Button(self.root,
                                  text="Edges",
                                  fg='#111166',
                                  width=BUTTONWIDTH,
                                  command=self.edges)
        self.butfiledges.grid(row=5, column=3)

        self.butcardColor = Button(self.root,
                                   text="CardColor",
                                   fg='#111166',
                                   width=BUTTONWIDTH,
                                   command=self.card)
        self.butcardColor.grid(row=6, column=0)

        ##        self.butdiff = Button(self.root, text="Diff", fg='#111166', width=BUTTONWIDTH, command=self.diff)
        ##        self.butdiff.grid(row=6, column=1)

        self.butgaussian = Button(self.root,
                                  text="Gaussian Blur",
                                  fg='#111166',
                                  width=BUTTONWIDTH,
                                  command=self.gaussian)
        self.butgaussian.grid(row=15, column=0)
        frame = Frame(self.root)
        frame.grid(row=15, column=1, columnspan=4, sticky=W, padx=20)
        self.spingaussianblurx = Spinbox(frame,
                                         from_=3,
                                         to=17,
                                         increment=2,
                                         width=SPINBOXWIDTH,
                                         state="readonly",
                                         command=self.gaussianblurspin)
        self.spingaussianblurx.pack(side=LEFT)
        Label(frame, text="width of kernel").pack(side=LEFT, ipadx=10)
        self.spingaussianblury = Spinbox(frame,
                                         from_=3,
                                         to=17,
                                         increment=2,
                                         width=SPINBOXWIDTH,
                                         state="readonly",
                                         command=self.gaussianblurspin)
        self.spingaussianblury.pack(side=LEFT)
        Label(frame, text="height of kernel").pack(side=LEFT, ipadx=10)

        self.butmedianBlur = Button(self.root,
                                    text="Median Blur",
                                    fg='#111166',
                                    width=BUTTONWIDTH,
                                    command=self.medianBlur)
        self.butmedianBlur.grid(row=14, column=0)
        frame = Frame(self.root)
        frame.grid(row=14, column=1, columnspan=4, sticky=W, padx=20)
        self.spinmedianBlur = Spinbox(frame,
                                      from_=3,
                                      to=17,
                                      increment=2,
                                      width=SPINBOXWIDTH,
                                      state="readonly",
                                      command=self.medianblurspin)
        self.spinmedianBlur.pack(side=LEFT)
        Label(frame, text="size of kernel").pack(side=LEFT, ipadx=10)

        self.butaverage = Button(self.root,
                                 text="Average Blur",
                                 fg='#111166',
                                 width=BUTTONWIDTH,
                                 command=self.average)
        self.butaverage.grid(row=16, column=0)
        frame = Frame(self.root)
        frame.grid(row=16, column=1, columnspan=4, sticky=W, padx=20)
        self.spinaverageblurx = Spinbox(frame,
                                        from_=2,
                                        to=20,
                                        increment=1,
                                        width=SPINBOXWIDTH,
                                        state="readonly",
                                        command=self.averageblurspin)
        self.spinaverageblurx.pack(side=LEFT)
        Label(frame, text="width of kernel").pack(side=LEFT, ipadx=10)
        self.spinaverageblury = Spinbox(frame,
                                        from_=2,
                                        to=20,
                                        increment=1,
                                        width=SPINBOXWIDTH,
                                        state="readonly",
                                        command=self.averageblurspin)
        self.spinaverageblury.pack(side=LEFT)
        Label(frame, text="height of kernel").pack(side=LEFT, ipadx=10)

        self.butnorm = Button(self.root,
                              text="Normalize",
                              fg='#111166',
                              width=BUTTONWIDTH,
                              command=self.normalize)
        self.butnorm.grid(row=6, column=1)

        self.butmap = Button(self.root,
                             text="Map Color",
                             fg='#111166',
                             width=BUTTONWIDTH,
                             command=self.mapColor)
        self.butmap.grid(row=7, column=0)
        frame = Frame(self.root)
        frame.grid(row=7, column=1, columnspan=4, sticky=W, padx=20)
        self.combomap = ttk.Combobox(frame)
        self.combomap["state"] = "readonly"
        self.combomap.bind("<<ComboboxSelected>>", self.mapcombo)
        self.combomap['values'] = ("AUTUMN", "BONE", "JET", "WINTER",
                                   "RAINBOW", "OCEAN", "SUMMER", "SPRING",
                                   "COOL", "HSV", "PINK", "HOT")
        self.combomap.current(0)
        self.combomap.pack(side=LEFT)

        self.butfilthresh = Button(self.root,
                                   text="Thresholding",
                                   fg='#111166',
                                   width=BUTTONWIDTH,
                                   command=self.thresholding)
        self.butfilthresh.grid(row=8, column=0)
        frame = Frame(self.root)
        frame.grid(row=8, column=1, columnspan=4, sticky=W, padx=20)
        var = StringVar()
        var.set(125)
        self.spinfilthresh = Spinbox(frame,
                                     from_=0,
                                     to=255,
                                     increment=1,
                                     textvariable=var,
                                     width=SPINBOXWIDTH,
                                     state="readonly",
                                     command=self.thresholdingspin)
        self.spinfilthresh.pack(side=LEFT)
        Label(frame, text="threshold value").pack(side=LEFT, ipadx=10)

        self.butfilreducecolor = Button(self.root,
                                        text="Reduce colors",
                                        fg='#111166',
                                        width=BUTTONWIDTH,
                                        command=self.reducecolors)
        self.butfilreducecolor.grid(row=9, column=0)
        frame = Frame(self.root)
        frame.grid(row=9, column=1, columnspan=4, sticky=W, padx=20)
        self.spinfilreducecolor = Spinbox(frame,
                                          from_=2,
                                          to=255,
                                          increment=1,
                                          width=SPINBOXWIDTH,
                                          state="readonly",
                                          command=self.reducecolorsspin)
        self.spinfilreducecolor.pack(side=LEFT)
        Label(frame, text="total levels on channel").pack(side=LEFT, ipadx=10)

        ##        self.butfilmedian = Button(self.root, text="Median", fg = '#111166', width=BUTTONWIDTH, command=self.median)
        ##        self.butfilmedian.grid(row=10, column=0)
        ##        frame = Frame(self.root)
        ##        frame.grid(row=10, column=1,columnspan=4, sticky = W, padx=20)
        ##        self.spinfilmedian = Spinbox(frame, from_=3, to=31, increment=2, width=SPINBOXWIDTH, state="readonly", command=self.medianspin)
        ##        self.spinfilmedian.pack(side=LEFT)
        ##        Label(frame, text="size of the window").pack(side=LEFT, ipadx=10)
        ##
        ##        self.butfilblur = Button(self.root, text="Blur", fg = '#111166', width=BUTTONWIDTH, command=self.blur)
        ##        self.butfilblur.grid(row=11, column=0)
        ##        frame = Frame(self.root)
        ##        frame.grid(row=11, column=1,columnspan=4, sticky = W, padx=20)
        ##        self.spinfilblur = Spinbox(frame, from_=3, to=31, increment=2, width=SPINBOXWIDTH, state="readonly", command=self.blurspin)
        ##        self.spinfilblur.pack(side=LEFT)
        ##        Label(frame, text="kernel size").pack(side=LEFT, ipadx=10)

        self.butfilsharp = Button(self.root,
                                  text="Sharpen",
                                  fg='#111166',
                                  width=BUTTONWIDTH,
                                  command=self.sharpen)
        self.butfilsharp.grid(row=12, column=0)
        frame = Frame(self.root)
        frame.grid(row=12, column=1, columnspan=4, sticky=W, padx=20)
        self.spinfilsharp = Spinbox(frame,
                                    from_=3,
                                    to=31,
                                    increment=2,
                                    width=SPINBOXWIDTH,
                                    state="readonly",
                                    command=self.sharpenspin)
        self.spinfilsharp.pack(side=LEFT)
        Label(frame, text="kernel size").pack(side=LEFT, ipadx=10)

        self.butfilcanny = Button(self.root,
                                  text="Canny",
                                  fg='#111166',
                                  width=BUTTONWIDTH,
                                  command=self.canny)
        self.butfilcanny.grid(row=13, column=0)
        frame = Frame(self.root)
        frame.grid(row=13, column=1, columnspan=4, sticky=W, padx=20)
        self.spinfilcanny = Spinbox(frame,
                                    from_=10,
                                    to=500,
                                    increment=10,
                                    width=SPINBOXWIDTH,
                                    state="readonly",
                                    command=self.cannyspin)
        self.spinfilcanny.pack(side=LEFT)
        Label(frame, text="threshold1").pack(side=LEFT, ipadx=10)
        self.spinfilcanny2 = Spinbox(frame,
                                     from_=50,
                                     to=500,
                                     increment=10,
                                     width=SPINBOXWIDTH,
                                     state="readonly",
                                     command=self.cannyspin)
        self.spinfilcanny2.pack(side=LEFT)
        Label(frame, text="threshold2").pack(side=LEFT, ipadx=10)
Exemplo n.º 2
0
    def __init__(self, root):
        self.root = root
        self.root.protocol("WM_DELETE_WINDOW", self.onExit)

        self.videothread = Video()
        self.videothread.setFile('')
        # self.videothread.setFile(0)
        self.videothread.start()

        BUTTONWIDTH = 15
        SPINBOXWIDTH = 6
        ########################################################
        self.butpick = Button(self.root,
                              text="Pick file",
                              fg='#991111',
                              width=BUTTONWIDTH,
                              command=self.pick)
        self.butpick.grid(row=0, column=0)

        self.filestr = StringVar()
        self.filestr.set("")
        self.labfile = Label(self.root, textvariable=self.filestr)
        self.labfile.grid(row=0, column=1, columnspan=5, rowspan=2)

        self.butwebcam = Button(self.root,
                                text="Webcam",
                                fg='#991111',
                                width=BUTTONWIDTH,
                                command=self.webcam)
        self.butwebcam.grid(row=1, column=0)
        ########################################################
        Frame(self.root, height=10).grid(row=2, column=0, columnspan=3)
        ########################################################
        self.butplay = Button(self.root,
                              text="Play",
                              fg='#116611',
                              width=BUTTONWIDTH,
                              command=self.run)
        self.butplay.grid(row=3, column=0)

        frame = Frame(self.root)
        frame.grid(row=3, column=1, columnspan=2, sticky=W)

        self.butstop = Button(frame,
                              text="Stop",
                              fg='#116611',
                              width=BUTTONWIDTH,
                              command=self.stop)
        self.butstop.pack(side=LEFT)

        self.butrew = Button(frame,
                             text="Rewind",
                             fg='#116611',
                             width=BUTTONWIDTH,
                             command=self.rewind)
        self.butrew.pack(side=LEFT)
        #######################################################
        Frame(self.root, height=10).grid(row=4, column=0, columnspan=3)
        #######################################################
        self.butfilgrayscale = Button(self.root,
                                      text="Grayscale",
                                      fg='#111166',
                                      width=BUTTONWIDTH,
                                      command=self.grayscale)
        self.butfilgrayscale.grid(row=5, column=0)

        self.butfilinvert = Button(self.root,
                                   text="Invert",
                                   fg='#111166',
                                   width=BUTTONWIDTH,
                                   command=self.invert)
        self.butfilinvert.grid(row=6, column=0)

        self.butfilhisteql = Button(self.root,
                                    text="Histogram equal.",
                                    fg='#111166',
                                    width=BUTTONWIDTH,
                                    command=self.histeql)
        self.butfilhisteql.grid(row=7, column=0)

        self.butfilthresh = Button(self.root,
                                   text="Thresholding",
                                   fg='#111166',
                                   width=BUTTONWIDTH,
                                   command=self.thresholding)
        self.butfilthresh.grid(row=8, column=0)
        frame = Frame(self.root)
        frame.grid(row=8, column=1, columnspan=2, sticky=W, padx=20)
        var = StringVar()
        var.set(125)
        self.spinfilthresh = Spinbox(frame,
                                     from_=0,
                                     to=255,
                                     increment=1,
                                     textvariable=var,
                                     width=SPINBOXWIDTH,
                                     state="readonly",
                                     command=self.thresholdingspin)
        self.spinfilthresh.pack(side=LEFT)
        Label(frame, text="threshold value").pack(side=LEFT, ipadx=10)

        self.butfilreducecolor = Button(self.root,
                                        text="Reduce colors",
                                        fg='#111166',
                                        width=BUTTONWIDTH,
                                        command=self.reducecolors)
        self.butfilreducecolor.grid(row=9, column=0)
        frame = Frame(self.root)
        frame.grid(row=9, column=1, columnspan=2, sticky=W, padx=20)
        self.spinfilreducecolor = Spinbox(frame,
                                          from_=2,
                                          to=255,
                                          increment=1,
                                          width=SPINBOXWIDTH,
                                          state="readonly",
                                          command=self.reducecolorsspin)
        self.spinfilreducecolor.pack(side=LEFT)
        Label(frame, text="total levels on channel").pack(side=LEFT, ipadx=10)

        self.butfilmedian = Button(self.root,
                                   text="Median",
                                   fg='#111166',
                                   width=BUTTONWIDTH,
                                   command=self.median)
        self.butfilmedian.grid(row=10, column=0)
        frame = Frame(self.root)
        frame.grid(row=10, column=1, columnspan=2, sticky=W, padx=20)
        self.spinfilmedian = Spinbox(frame,
                                     from_=3,
                                     to=31,
                                     increment=2,
                                     width=SPINBOXWIDTH,
                                     state="readonly",
                                     command=self.medianspin)
        self.spinfilmedian.pack(side=LEFT)
        Label(frame, text="size of the window").pack(side=LEFT, ipadx=10)

        self.butfilblur = Button(self.root,
                                 text="Blur",
                                 fg='#111166',
                                 width=BUTTONWIDTH,
                                 command=self.blur)
        self.butfilblur.grid(row=11, column=0)
        frame = Frame(self.root)
        frame.grid(row=11, column=1, columnspan=2, sticky=W, padx=20)
        self.spinfilblur = Spinbox(frame,
                                   from_=3,
                                   to=31,
                                   increment=2,
                                   width=SPINBOXWIDTH,
                                   state="readonly",
                                   command=self.blurspin)
        self.spinfilblur.pack(side=LEFT)
        Label(frame, text="kernel size").pack(side=LEFT, ipadx=10)

        self.butfilsharp = Button(self.root,
                                  text="Sharpen",
                                  fg='#111166',
                                  width=BUTTONWIDTH,
                                  command=self.sharpen)
        self.butfilsharp.grid(row=12, column=0)
        frame = Frame(self.root)
        frame.grid(row=12, column=1, columnspan=2, sticky=W, padx=20)
        self.spinfilsharp = Spinbox(frame,
                                    from_=3,
                                    to=31,
                                    increment=2,
                                    width=SPINBOXWIDTH,
                                    state="readonly",
                                    command=self.sharpenspin)
        self.spinfilsharp.pack(side=LEFT)
        Label(frame, text="kernel size").pack(side=LEFT, ipadx=10)

        self.butfiledges = Button(self.root,
                                  text="Edges",
                                  fg='#111166',
                                  width=BUTTONWIDTH,
                                  command=self.edges)
        self.butfiledges.grid(row=13, column=0)

        self.butfilcanny = Button(self.root,
                                  text="Canny",
                                  fg='#111166',
                                  width=BUTTONWIDTH,
                                  command=self.canny)
        self.butfilcanny.grid(row=14, column=0)
        frame = Frame(self.root)
        frame.grid(row=14, column=1, columnspan=2, sticky=W, padx=20)
        self.spinfilcanny = Spinbox(frame,
                                    from_=10,
                                    to=500,
                                    increment=10,
                                    width=SPINBOXWIDTH,
                                    state="readonly",
                                    command=self.cannyspin)
        self.spinfilcanny.pack(side=LEFT)
        Label(frame, text="threshold1").pack(side=LEFT, ipadx=10)
        self.spinfilcanny2 = Spinbox(frame,
                                     from_=10,
                                     to=500,
                                     increment=10,
                                     width=SPINBOXWIDTH,
                                     state="readonly",
                                     command=self.cannyspin)
        self.spinfilcanny2.pack(side=LEFT)
        Label(frame, text="threshold2").pack(side=LEFT, ipadx=10)