Exemplo n.º 1
0
 def __init__(self):
     self.gui = GUI()
     self.camera = Camera()
     self.camera.startVideo()
     self.detectCanny = False
     self.detectFace = False
     self.detectEye = False
Exemplo n.º 2
0
    def __init__(self, path=""):
        self.configpath = path
        self.root = Tk()
        self.cameras = Camera()
        self.parser = Parser()
        self.gui = GUI(root=self.root)
        self.callback = Callback(self.root)

        self.isImage_active = False
        self.isVideo_active = False
        self.isCamera_active = False
        self.isObject_active = False
Exemplo n.º 3
0
 def openwithvideo_callback(self, event=None):
     filetypes = self.extensions["video"]
     openfile = askopenfilename(filetypes=filetypes)
     if openfile != "" and len(openfile) >= 1:
         basename = getBasename(openfile)
         for extension in self.extensions["video"]:
             if extension[1] == "*": continue
             else:
                 ext = extension[1].replace("*", "")
                 if basename[1] == ext:
                     return openfile
         if self.path == "":
             GUI().message("Unable extension", type=0)
             return None
         else:
             return openfile
     else:
         GUI().message("Failed to open file", type=2)
         return None
Exemplo n.º 4
0
 def readCapture(self, islopp=False, gui=None):
     if self.camera is None:
         GUI().message("Failed to capture video, please start a capture", 1)
         return False
     else:
         ret, frame = self.camera.read()
         if ret:
             self.frame = frame
             return frame
         else:
             if islopp:
                 self.camera.set(CAP_PROP_POS_FRAMES, 0)
                 return True
             else:
                 if gui is None:
                     GUI().message("Camera has been stopped", 3)
                 else:
                     gui.message("Camera has been stopped", 3)
                     gui.panel.destroy()
                 return None
Exemplo n.º 5
0
def main():
    try:
        open("settings.ini", "r").close()
        first_time = False
    except FileNotFoundError:
        first_time = True

    update_exit = check_version(version)
    if update_exit:
        return

    setup_completed = not first_time or first_time_setup()

    if setup_completed:
        generate_default_bases()
        log_settings(version)
        settings = ConfigParser()
        settings.read("settings.ini")
        editor = WaypointEditor(settings)

        gui = GUI(editor, version)

        try:
            gui.run()
        except Exception:
            gui.close()
            raise
Exemplo n.º 6
0
def main(project_parameters):
    result = None
    if project_parameters.mode == 'train':
        result = train(project_parameters=project_parameters)
    elif project_parameters.mode == 'evaluate':
        if project_parameters.predefined_dataset is not None:
            print('temporarily does not support predefined dataset.')
        else:
            evaluate(project_parameters=project_parameters)
    elif project_parameters.mode == 'predict':
        if project_parameters.use_gui:
            gui = GUI(project_parameters=project_parameters)
            gui.run()
        else:
            result = Predict(project_parameters=project_parameters)(
                data_path=project_parameters.data_path)
            print(('{},' * project_parameters.num_classes).format(
                *project_parameters.classes)[:-1])
            print(result)
    elif project_parameters.mode == 'tune':
        result = tune(project_parameters=project_parameters)
    return result
Exemplo n.º 7
0
class ThreadedClient:
    """
    Launch the main part of the GUI and the worker thread.
    """
    def __init__(self, master, read_data):
        """
        Start the GUI and the asynchronous threads.
        """

        self.master = master

        # Create the queue
        self.queue = Queue.Queue()

        # Set up the GUI part
        self.gui = GUI(master, self.queue)

        # Set up data read
        self._data = read_data

        # Set up the thread to do asynchronous I/O
        self.running = 1
        self.thread = threading.Thread(target=self.worker_thread)
        self.thread.start()

        # Start the periodic call in the GUI to check queue
        self.periodic_call()

    def periodic_call(self):
        """
        Check every 100 ms if there is something new in the queue.
        """
        self.gui.process_incoming()
        if not self.running:
            # Hard stop of application if running is not set
            import sys
            sys.exit(1)
        self.master.after(100, self.periodic_call)

    def worker_thread(self):
        """
        Handle the asynchronous I/O.
        """
        while self.running:
            time.sleep(5)
            msg = "Poll"
            _data = self._data._read_current_weather()
            self._data.create_data_chunks(_data)
            self.gui.set_weather_data(self._data.location,
                                      self._data.current,
                                      self._data.condition)
            self.gui.update_labels()
            self.master.update_idletasks()
            self.queue.put(msg)
Exemplo n.º 8
0
    def __init__(self, master, read_data):
        """
        Start the GUI and the asynchronous threads.
        """

        self.master = master

        # Create the queue
        self.queue = Queue.Queue()

        # Set up the GUI part
        self.gui = GUI(master, self.queue)

        # Set up data read
        self._data = read_data

        # Set up the thread to do asynchronous I/O
        self.running = 1
        self.thread = threading.Thread(target=self.worker_thread)
        self.thread.start()

        # Start the periodic call in the GUI to check queue
        self.periodic_call()
Exemplo n.º 9
0
 def __init__(self, root):
     self.root = root
     self.gui = GUI(self.root)
     self.parser = Parser()
     self.extensions = self.parser.parseExtensions()
     self.path = ""
Exemplo n.º 10
0
from src.gui import GUI
import tkinter as tk

if __name__ == "__main__":
    root = tk.Tk()
    menu = GUI(root)
    root.mainloop()
Exemplo n.º 11
0
def main():
    """Generates UI for the user"""

    gui = GUI()  # Creates graphics object . . .
    gui.add_features()  # Adds search bar, etc . . .
    gui.mainloop()  # Starts GUI . . .
Exemplo n.º 12
0
def main(args):
    b = Board(mine=args.mine, height=args.height, width=args.width)
    gui = GUI(b)
    gui.loop()
Exemplo n.º 13
0
class Main(object):
    def __init__(self):
        self.gui = GUI()
        self.camera = Camera()
        self.camera.startVideo()
        self.detectCanny = False
        self.detectFace = False
        self.detectEye = False

    def funcDetectCanny(self):
        if self.detectCanny:
            self.detectCanny = False
            self.gui.btnCan.configure(text="Turn on canny detection")
        else:
            self.detectCanny = True
            self.gui.btnCan.configure(text="Turn off canny detection")
            self.camera.closeWindow()

    def funcDetectFace(self):
        if self.detectFace:
            self.detectFace = False
            self.gui.btnFace.configure(text="Turn on face detection")
        else:
            self.detectFace = True
            self.gui.btnFace.configure(text="Turn off face detection")
            self.camera.closeWindow()

    def funcDetectEye(self):
        if self.detectEye:
            self.detectEye = False
            self.gui.btnEye.configure(text="Turn on face detectoe")
        else:
            self.detectEye = True
            self.gui.btnEye.config(text="Turn off face detector")
            self.camera.closeWindow()

    def video_stream(self):
        ret, frame = self.camera.readVideo(color=True)

        if ret:
            if self.detectCanny:
                can = self.camera.convertToCanny(frame)
                self.camera.show("Canny Result: ", can)
            elif self.detectFace:
                rect = self.camera.detectFace()
                self.camera.show("Face", rect)
            elif self.detectEye:
                rect = self.camera.detectEye()
                self.camera.show("Eye", rect)
            else:
                self.camera.closeWindow()
            photo = self.camera.convertToTk(
                self.camera.convertFromArray(frame))
            self.gui.set_frame(photo)
            self.gui.update()
        self.gui.after(15, self.video_stream)

    def run(self):
        self.gui.createButton(command=self.camera.snapshot)
        self.gui.createButtonCanny(command=self.funcDetectCanny)
        self.gui.createButtonFace(command=self.funcDetectFace)
        self.gui.createButtonEye(command=self.funcDetectEye)
        self.video_stream()
        self.gui.run()
Exemplo n.º 14
0
from src.gui import GUI

if __name__ == "__main__":
    gui = GUI()
    gui.run()
Exemplo n.º 15
0
class Main:
    def __init__(self, path=""):
        self.configpath = path
        self.root = Tk()
        self.cameras = Camera()
        self.parser = Parser()
        self.gui = GUI(root=self.root)
        self.callback = Callback(self.root)

        self.isImage_active = False
        self.isVideo_active = False
        self.isCamera_active = False
        self.isObject_active = False

    #---------- Local callback ----------#
    def openwithimage_callback(self, event=None):
        if self.gui.panel != None:
            self.gui.destroyPanel()
        path = self.callback.openwithimage_callback()
        if path != None:
            self.cameras.readImage(path, flag=None)
            self.cameras.frame = self.cameras.resize(self.cameras.getFrame,
                                                     (400, 400))
            width, height = self.cameras.getSize()
            image = self.cameras.convert2tk(self.cameras.getFrame)
            self.gui.createPanel(image, width=width, height=height)
            self.isImage_active = True
            self.isVideo_active = False
            self.isCamera_active = False

    def openwithvideo_callback(self, event=None):
        if self.gui.panel != None:
            self.gui.destroyPanel()
        path = self.callback.openwithvideo_callback(event=event)
        if path != None:
            self.cameras.startVideo(path)
            startCapture = self.cameras.readCapture()
            startCapture = self.cameras.BGR2RGBA(startCapture)
            startCapture = self.cameras.convert2tk(startCapture)
            width, height = self.cameras.getSize()
            self.gui.createPanel(startCapture, width=width, height=height)
            self.captureVideo(loop=True)
            self.isImage_active = False
            self.isVideo_active = True
            self.isCamera_active = False

    def openwithcamera_callback(self, event=None):
        if self.gui.panel != None:
            self.gui.destroyPanel()
        settings = self.parser.parseCameraSettings()
        src = settings["src"]
        try:
            self.cameras.startVideo(src=src)
            startCapture = self.cameras.readCapture()
            startCapture = self.cameras.BGR2RGB(startCapture)
            startCapture = self.cameras.convert2tk(startCapture)
            width, height = self.cameras.getSize()
            self.gui.createPanel(startCapture, width=width, height=height)
            self.captureVideo(loop=False)
            self.isImage_active = False
            self.isVideo_active = False
            self.isCamera_active = True
        except error:
            self.gui.message("Failed to open camera with device " + str(src),
                             2)
            # self.gui.destroyPanel()

    def detectBarcode_callback(self, event=None):
        self.isObject_active = True
        if self.isObject_active:
            if self.cameras.getFrame is None:
                self.gui.message("No object")
            else:
                if self.isCamera_active is None:
                    newframe = self.detectBarcode()
                    newframe = self.cameras.convert2tk(newframe)
                    self.gui.update(newframe)

    #---------- Edit menu ----------#
    def clearframe_callback(self, event=None):
        self.callback.clearframe_callback(self.gui)

    #---------- Capture Video ----------#
    def captureVideo(self, loop=False):

        try:
            captured = self.cameras.readCapture(islopp=loop, gui=self.gui)

            captured = self.cameras.BGR2RGB(captured)
            self.cameras.frame = captured
            if captured is None:
                pass
            else:
                if self.isObject_active:
                    frame = self.detectBarcode(
                        customFrame=self.cameras.getFrame)
                    if frame is None:
                        frame = self.cameras.getFrame
                else:
                    frame = self.cameras.getFrame
                newframe = self.cameras.convert2tk(frame)
                self.gui.update(newframe)
            self.gui.delay(15, self.captureVideo)
        except error:
            self.gui.message("Asserting failed, please check your camera!")
            self.gui.destroyPanel()

    #---------- Detect barcode ----------#
    def detectBarcode(self, customFrame=None):
        if customFrame is None:
            customFrame = self.cameras.getFrame

        image = self.cameras.BGR2Gray(self.cameras.getFrame)
        barcode = pyzbar.decode(image)
        if len(barcode) == 0: return None
        for data in barcode:
            points = data.polygon
            x, y, w, h = data.rect
            pts = self.cameras.cv2array(points)
            pts = pts.reshape((-1, 1, 2))
            newframe = self.cameras.createpolygon(self.cameras.frame, pts)
            code = data.data.decode("utf-8")
            newframe = self.cameras.setText(newframe,
                                            text=code,
                                            position=(x, y))
            return newframe

    #---------- Setup menbubars function ----------#
    def setupMenubars(self):
        menubars = Menu(self.root)

        #---------- File bars ----------#
        fileBars = Menu(menubars, tearoff=0)
        menubars.add_cascade(label="File", menu=fileBars)
        fileBars.add_command(label="Open with image file",
                             command=self.openwithimage_callback)
        fileBars.add_command(label="Open with video file",
                             command=self.openwithvideo_callback)
        fileBars.add_command(label="Open with camera",
                             command=self.openwithcamera_callback)
        fileBars.add_separator()
        fileBars.add_command(label="Save barcode", command=print)
        fileBars.add_separator()
        fileBars.add_command(label="Quit", command=self.callback.quit_callback)
        #---------- CTRL + O (Open with image file) ----------#
        self.root.bind("<Control-o>", self.openwithimage_callback)
        self.root.bind("<Control-O>", self.openwithimage_callback)
        #---------- CTRL + Shift + O (Open with video file) ----------#
        self.root.bind("<Control-Shift-o>", self.openwithvideo_callback)
        self.root.bind("<Control-Shift-O>", self.openwithvideo_callback)
        #---------- CTRL + Q (Quit) ----------#
        self.root.bind("<Control-Q>", self.callback.quit_callback)
        self.root.bind("<Control-q>", self.callback.quit_callback)

        #---------- Edit bars ----------#
        editbars = Menu(menubars, tearoff=0)
        menubars.add_cascade(label="Edit", menu=editbars)
        editbars.add_command(label="Clear frame",
                             command=self.clearframe_callback)
        editbars.add_command(label="Detect barcode",
                             command=self.detectBarcode_callback)
        #---------- CTRL + Shift + C (Clear Frame) ----------#
        self.root.bind("<Control-Shift-c>", self.clearframe_callback)
        self.root.bind("<Control-Shift-C>", self.clearframe_callback)

        #---------- Settings bar ----------
        settingbars = Menu(menubars, tearoff=0)
        menubars.add_cascade(label="Settings", menu=settingbars)
        settingbars.add_command(label="Settings camera",
                                command=self.callback.setCameraDevice_callback)

        self.root.config(menu=menubars)

    #---------- Setup function ----------#
    def setup(self):
        callback = [
            self.openwithimage_callback, self.openwithvideo_callback,
            self.openwithcamera_callback, self.clearframe_callback,
            self.detectBarcode_callback
        ]
        w, h = self.gui.getWindowSize()  # get window size
        self.gui.setTitle("QrScanner")
        self.gui.setScreensize(size=convert2geometry(w=w, h=h))
        self.setupMenubars()
        self.gui.createButton(command=callback)

    def run(self):
        self.root.mainloop()
Exemplo n.º 16
0
# report-ng
# Copyright (c) 2014-2017 Marcin Woloszyn (@hvqzao)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


if __name__ == '__main__':
    import sys
    if len(sys.argv) > 1:
        from src.cli import CLI
        CLI()
    else:
        from src.gui import GUI
        GUI()
Exemplo n.º 17
0
        print(datetime.now().strftime("%H:%M:%S") + ": cache not found")

        # file is not created, scores will be calculated, create a file/cache
        workbook = openpyxl.Workbook()

        # returns a sheet with doc-vectors with doc-tf-idf, df, idf and bag-of-words
        doc_sheet = vsm.create_doc_sheet(workbook.active)

        # saves the cache file on disk
        workbook.save("../out/tf-idf.xlsx")

        print(datetime.now().strftime("%H:%M:%S") + ": cache saved to disk")

    # an object of GUI class is created
    # doc_sheet which have doc-vectors and bag-of-words is passed to the constructor and vsm object
    gui = GUI(vsm, doc_sheet)

    # setGUI creates the GUI and returns a window through which we run the GUI
    window = gui.setGUI()

    # this opens the GUI
    window.mainloop()

    # when GUI window is closed the control comes here

    # closes the workbook that ahs doc-sheet
    workbook.close()

    print(datetime.now().strftime("%H:%M:%S") + ": cache-file closed")
    print(datetime.now().strftime("%H:%M:%S") + ": exit")