main.py 4.02 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
    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 
9
    and bind the method to menu, using the call tk.add_command or tk.add_check_button.
10 11 12 13 14
    
    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/ ). 
15 16 17
    Use it as your guideline. Only use CamelCase in class names. DON'T USE CamelCase ou mixedCase in variables or functions.
    
    All declarations and comments in this project must be made in English.
18
    
19 20
    Name: main.py
    Author: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
21
"""
22
import argparse
Gabriel Kirsten's avatar
 
Gabriel Kirsten committed
23
import thread
24

25
import interface
26

27
from pynovisao import Act
28

29 30

def get_args():
31
    """Read the arguments of program."""
32 33 34 35 36 37 38 39 40 41
    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())


42
if __name__ == "__main__":
43
    # Interface of software
44
    tk = interface.TkInterface("Pynovisao")
45
    
46
    # Bind all Pynovisao actions to menu
Gabriel Kirsten's avatar
 
Gabriel Kirsten committed
47
    act = Act(tk, thread, get_args())
48 49 50
    
    tk.add_menu("File")
    tk.add_command("Open a image", act.open_image, 'O') 
51
    tk.add_command("Restore image", act.restore_image, 'R')
52 53 54 55 56
    tk.add_separator()
    tk.add_command("Close image", act.close_image, 'W') 
    tk.add_separator()
    tk.add_command("Quit", tk.quit, 'Q')
    
57 58 59 60 61 62 63 64 65 66
    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()
67
    tk.add_check_button("Dataset generator", act.toggle_dataset_generator)
68
    
69
    tk.add_menu("Segmentation")
70 71
    tk.add_command("Choose segmenter", act.select_segmenter)
    tk.add_command("Configure", act.config_segmenter, 'g')
72
    tk.add_separator()
73
    tk.add_command("Execute", act.run_segmenter, 'S')
74 75 76
    tk.add_separator()
    tk.add_command("Assign using labeled image", act.assign_using_labeled_image, 'l')
    tk.add_command("Execute folder", act.run_segmenter_folder)
77 78
    
    tk.add_menu("Feature Extraction")
79
    tk.add_command("Select extractors", act.select_extractors, 'e')
80
    tk.add_separator()
81
    tk.add_command("Execute", act.run_extractors, 'F')
82
    
83
    tk.add_menu("Training")
84 85
    tk.add_command("Choose classifier", act.select_classifier)
    tk.add_command("Configure", act.configure_classifier)
86
    tk.add_separator()
Gabriel Kirsten's avatar
 
Gabriel Kirsten committed
87 88 89 90 91
    tk.add_command("Execute", act.run_training, 'T')
    
    tk.add_menu("Classification")
    tk.add_command("Load h5 weight (only for CNNs)", act.open_weight)
    tk.add_command("Execute", act.run_classifier, 'C')
92
    tk.add_command("Execute folder", act.run_classifier_folder)
Gabriel Kirsten's avatar
 
Gabriel Kirsten committed
93 94

    tk.add_menu("Experimenter")
95 96
    tk.add_check_button("Ground Truth", act.toggle_ground_truth, default_state = False)
    tk.add_separator()
97
    tk.add_command("Cross Validation", act.cross_validation, 'X')
98
    tk.add_command("Experimenter All", act.experimenter_all, 'p')
Gabriel Kirsten's avatar
 
Gabriel Kirsten committed
99

100 101 102 103
    tk.add_menu("Help")
    tk.add_command("About Pynovisao", act.about, 'b')
    
    
104
    # Render the GUI
105 106 107 108 109 110
    tk.render_menu()
    
    tk.add_panel_classes( act.classes )
    
    tk.open_log()
    
111
    # Open the GUI
112
    tk.show()