main.py 3.3 KB
Newer Older
1 2 3 4
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
"""
5 6
    Read the args, creates GUI and add all actions of pynovisao.
    
7 8 9 10 11 12 13 14 15 16
    This file is the main code of Pynovisao.
    To add a new action ( functionality ) to this software, you must implement the method body of action in file pynovisao.py 
    and bind the method to menu, using the call tk.add_command.
    
    To add a new Feature Extractor, Segmenter or Classifier, place it in correct directory and extend its abstract class.
    
    As PEP 20 says, "Readability counts". So, follow the current conventions adopted in this project.
    For more information access PEP 8 -- Style Guide for Python Code ( https://www.python.org/dev/peps/pep-0008/ ). 
    Use it as your guideline. Only use CamelCase in class names. DON'T USE CamelCase ou mixedCase in variable or functions.
    
17 18
    Name: main.py
    Author: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
19
"""
20
import argparse
21

22
import interface
23

24
from pynovisao import Act
25

26 27

def get_args():
28
    """Read the arguments of program."""
29 30 31 32 33 34 35 36 37 38
    ap = argparse.ArgumentParser()

    ap.add_argument("-d", "--dataset", required=False, help="Dataset path", default="../data/demo", type=str)
    
    ap.add_argument("-cl", "--classes", required=False, help="Classes names", default=None, type=str)
    ap.add_argument("-co", "--colors", required=False, help="Classes colors (X11 color)", default=None, type=str)
    
    return vars(ap.parse_args())


39
if __name__ == "__main__":
40
    # Interface of software
41
    tk = interface.TkInterface("Pynovisao")
42
    
43
    # Bind all Pynovisao actions to menu
44
    act = Act(tk, get_args())
45 46 47
    
    tk.add_menu("File")
    tk.add_command("Open a image", act.open_image, 'O') 
48
    tk.add_command("Restore image", act.restore_image, 'R')
49 50 51 52 53
    tk.add_separator()
    tk.add_command("Close image", act.close_image, 'W') 
    tk.add_separator()
    tk.add_command("Quit", tk.quit, 'Q')
    
54 55 56 57 58 59 60 61 62 63 64 65
    tk.add_menu("View")
    tk.add_check_button("Show image axes", tk.toggle_image_axes)
    tk.add_check_button("Show image toolbar", tk.toggle_image_toolbar)
    tk.add_separator()
    tk.add_check_button("Show log", tk.toggle_log)
    
    tk.add_menu("Dataset")
    tk.add_command("Add new class", act.add_class, 'A')
    tk.add_command("Set dataset path", act.set_dataset_path, 'd')
    tk.add_separator()
    tk.add_check_button("Dataset generator", act.toggle_dataset_generator, 't')
    
66
    tk.add_menu("Segmentation")
67 68
    tk.add_command("Choose segmenter", act.select_segmenter)
    tk.add_command("Configure", act.config_segmenter, 'g')
69
    tk.add_separator()
70
    tk.add_command("Execute", act.run_segmenter, 'S')
71 72
    
    tk.add_menu("Feature Extraction")
73
    tk.add_command("Select extractors", act.select_extractors, 'e')
74
    tk.add_separator()
75
    tk.add_command("Execute", act.run_extractors, 'F')
76 77
    
    tk.add_menu("Classification")
78 79
    tk.add_command("Choose classifier", act.select_classifier)
    tk.add_command("Configure", act.configure_classifier)
80
    tk.add_separator()
81
    tk.add_command("Cross Validation", act.cross_validation, 'X')
82
    tk.add_command("Experimenter All", act.experimenter_all, 'p')
83
    tk.add_separator()
84
    tk.add_command("Execute", act.run_classifier, 'C')
85
    
86
    # Render the GUI
87 88 89 90 91 92 93
    tk.render_menu()
    
    tk.add_panel_classes( act.classes )
    
    tk.open_log()
    
    tk.show()