def __init__(self, barcode, mouse_x, mouse_y, figsize=(10, 2), dpi=100):
        self.barcode = barcode

        # Initialize the window
        self.window = tkinter.Tk()
        self.window.wm_title("Display frames")
        self.window.iconbitmap(resource_path("kalmus_icon.ico"))

        # Set up the plotted figure
        self.fig = plt.figure(figsize=figsize, dpi=dpi)

        displayed_image = self.get_frames_image_for_display(mouse_x, mouse_y)
        plt.imshow(displayed_image)
        plt.axis("off")
        plt.tight_layout()

        # Set up the canvas for the figure
        self.canvas = FigureCanvasTkAgg(
            self.fig, master=self.window)  # A tk.DrawingArea.
        self.canvas.draw()
        self.canvas.get_tk_widget().pack(side=tkinter.TOP,
                                         fill=tkinter.BOTH,
                                         expand=1)

        # Initialize the plotting tool bar
        self.toolbar = NavigationToolbar2Tk(self.canvas, self.window)
        self.toolbar.update()
        self.canvas.get_tk_widget().pack(side=tkinter.TOP,
                                         fill=tkinter.BOTH,
                                         expand=1)
예제 #2
0
    def __init__(self, barcode_1, barcode_2):
        """
        Initialize the Window

        :param barcode_1: The barcode 1
        :param barcode_2: The barcode 2
        """
        self.barcode_1 = barcode_1
        self.barcode_2 = barcode_2

        # Initialize the window
        self.window = tkinter.Tk()

        self.window.configure(bg="#FFFFFF")
        self.window.wm_title("Barcodes Similarity Statistics")
        self.window.iconbitmap(resource_path("kalmus_icon.ico"))

        # Get the comparison result (in string) between two barcodes
        result_text = get_comparison_result_text(self.barcode_1,
                                                 self.barcode_2)

        # Show the result in a Label (text panel)
        self.info_label = tkinter.Label(self.window,
                                        text=result_text,
                                        width=35,
                                        bg='white',
                                        anchor='w',
                                        justify=tkinter.LEFT)
        self.info_label.grid(row=0, column=0, rowspan=8)
예제 #3
0
    def __init__(self, barcode, barcodes_stack):
        """
        Initialize

        :param barcode: The barcode to check with the meta information
        :param barcodes_stack: The dictionary that store all the barcodes on the memory
        """
        self.barcode = barcode
        self.barcodes_stack = barcodes_stack

        # Initialize the window
        self.window = tkinter.Tk()
        self.window.wm_title("Barcode Meta Information")
        self.window.iconbitmap(resource_path("kalmus_icon.ico"))

        # Label prompt for the meta information display
        self.meta_info_label = tkinter.Label(self.window, text="", width=35, bg='white', anchor='w',
                                             justify=tkinter.LEFT)
        self.meta_info_label.grid(row=0, column=0, columnspan=2, sticky=tkinter.W)

        # Update the Meta information text
        self.refresh_text()

        # Button to refresh the displayed meta information of the barcode
        self.refresh_button = tkinter.Button(master=self.window, text="Refresh",
                                             command=self.refresh_text)
        self.refresh_button.grid(row=1, column=0)

        # Button to add/update meta information to the barcode
        self.add_info_button = tkinter.Button(master=self.window, text="Update Meta Info",
                                              command=self.update_meta_info)
        self.add_info_button.grid(row=1, column=1)
예제 #4
0
    def __init__(self, barcode_1, barcode_2, barcodes_stack):
        """
        Initialize

        :param barcode_1: The barcode 1
        :param barcode_2: The barcode 2
        :param barcodes_stack: The dictionary that stored all the barcode in memory
        """
        self.barcode_1 = barcode_1
        self.barcode_2 = barcode_2
        self.barcode_stacks = barcodes_stack

        # Initialize the window
        self.window = tkinter.Tk()
        self.window.wm_title("Which Barcode to Check Meta Info")
        self.window.iconbitmap(resource_path("kalmus_icon.ico"))

        # Option variable
        self.barcode_option = tkinter.StringVar(self.window)
        self.barcode_option.set("Barcode 1")

        # Option radio button
        radio_barcode_1 = tkinter.Radiobutton(self.window, text="Barcode 1", variable=self.barcode_option,
                                              value="Barcode 1")
        radio_barcode_1.grid(row=0, column=0, padx=50)
        radio_barcode_1.select()

        radio_barcode_2 = tkinter.Radiobutton(self.window, text="Barcode 2", variable=self.barcode_option,
                                              value="Barcode 2")
        radio_barcode_2.grid(row=1, column=0, padx=50)

        # Check button
        self.button_check = tkinter.Button(master=self.window, text="Check", command=self.check_meta_info)
        self.button_check.grid(row=2, column=0, padx=50)
    def __init__(self, barcode, time_label, frame_label, mouse_x, mouse_y):
        """
        Initialize
        :param barcode: The barcode to recalibrate
        :param time_label: the text label for time
        :param frame_label: the text label for the frame index
        :param mouse_x: the x position of the clicked point
        :param mouse_y: the y position of the clicked point
        """
        self.barcode = barcode
        self.time_label = time_label
        self.frame_label = frame_label
        self.x_pos = mouse_x
        self.y_pos = mouse_y

        # Initialize the window
        self.window = tkinter.Tk()
        self.window.wm_title("At this point...")
        self.window.iconbitmap(resource_path("kalmus_icon.ico"))

        # where does the barcode start (collecting frames from the film)
        start_label = tkinter.Label(master=self.window,
                                    text="Start at (min:sec):")
        start_label.grid(row=0, column=0)

        self.start_entry = tkinter.Entry(self.window,
                                         textvariable="0",
                                         width=12)
        self.start_entry.grid(row=0, column=1, columnspan=1, padx=5, pady=1)

        # where does the barcode end (collecting frames from the film)
        end_label = tkinter.Label(master=self.window, text="End at (min:sec):")
        end_label.grid(row=1, column=0)

        self.end_entry = tkinter.Entry(self.window, textvariable="1", width=12)
        self.end_entry.grid(row=1, column=1, columnspan=1, padx=5, pady=1)

        # the fps of the corresponding film
        fps_label = tkinter.Label(master=self.window,
                                  text="Frame per second (fps):")
        fps_label.grid(row=2, column=0)

        self.fps_entry = tkinter.Entry(self.window, textvariable="2", width=12)
        self.fps_entry.grid(row=2, column=1, columnspan=1, padx=5, pady=1)

        # update these information
        self.update_button = tkinter.Button(master=self.window,
                                            text="Update",
                                            command=self.update)
        self.update_button.grid(row=3, column=0, columnspan=2)
    def __init__(self, barcode_stack):
        """
        Initialize

        :param barcode_stack: the dictionary that stored all the barcodes on the memory
        """
        self.barcode_stack = barcode_stack

        # Initialize the window
        self.window = tkinter.Tk()
        self.window.iconbitmap(resource_path("kalmus_icon.ico"))
        self.window.wm_title("Save Barcode from Memory Stack")

        # List box that lists all the barcodes stored on the memory (shows the barcode's key in the dictionary)
        self.listbox = tkinter.Listbox(self.window,
                                       selectmode=tkinter.SINGLE,
                                       width=65,
                                       height=20)
        self.listbox.grid(row=0, column=0, columnspan=4)

        # List all the barcodes in the list box using their keys
        for barcode_names in self.barcode_stack.keys():
            self.listbox.insert(tkinter.END, barcode_names)

        # Label prompt for the file name/path to the saved json file
        filename_label = tkinter.Label(self.window, text="JSON file path: ")
        filename_label.grid(row=1, column=0)

        # Text entry for user to specify the file name/path to the saved json file
        self.filename_entry = tkinter.Entry(self.window,
                                            textvariable="",
                                            width=40)
        self.filename_entry.grid(row=1,
                                 column=1,
                                 columnspan=1,
                                 sticky=tkinter.W)

        # Button to browse the location in a file manager
        self.button_browse_folder = tkinter.Button(self.window,
                                                   text="Browse",
                                                   command=self.browse_folder)
        self.button_browse_folder.grid(row=1, column=2, sticky=tkinter.W)

        # Button to save the barcode into json file
        self.button_save = tkinter.Button(master=self.window,
                                          text="Save Barcode",
                                          command=self.save_stack)
        self.button_save.grid(row=2, column=0, sticky=tkinter.W)
    def __init__(self, barcode_stack, barcode_1, barcode_2, axes, canvas):
        """
        Initialize

        :param barcode_stack: The dictionary that stores all the barcode on memory
        :param barcode_1: The barcode 1
        :param barcode_2: The barcode 2
        :param axes: The plotted figure axes in the main window
        :param canvas: The plotted figure canvas in the main window
        """
        self.barcode_stack = barcode_stack
        self.barcode_1 = barcode_1
        self.axes = axes
        self.canvas = canvas
        self.barcode_2 = barcode_2

        # Initialize the window
        self.window = tkinter.Tk()
        self.window.iconbitmap(resource_path("kalmus_icon.ico"))
        self.window.wm_title("Barcodes on Memory Stack")

        # Set up the list box that shows all the barcode on memory using their keys in the dictionary
        self.listbox = tkinter.Listbox(self.window, selectmode=tkinter.SINGLE, width=65, height=20)
        self.listbox.grid(row=0, column=0)

        # List all the barcodes with their keys
        for barcode_names in self.barcode_stack.keys():
            self.listbox.insert(tkinter.END, barcode_names)

        # Button to load the barcode from the memory
        self.button_load = tkinter.Button(master=self.window, text="Load Selected Barcode", command=self.load_stack)
        self.button_load.grid(row=3, column=0, sticky=tkinter.W)

        # Option variable that stores the position which the new barcode from json will replace with
        self.barcode_option = tkinter.StringVar(self.window)
        self.barcode_option.set("Barcode 1")

        # Radio buttons for the replaced barcode selection
        radio_barcode_1 = tkinter.Radiobutton(self.window, text="Barcode 1", variable=self.barcode_option,
                                              value="Barcode 1", anchor='w')
        radio_barcode_1.grid(row=1, column=0, sticky=tkinter.W)
        radio_barcode_1.select()

        radio_barcode_2 = tkinter.Radiobutton(self.window, text="Barcode 2", variable=self.barcode_option,
                                              value="Barcode 2", anchor='w')
        radio_barcode_2.grid(row=2, column=0, sticky=tkinter.W)
    def __init__(self, barcode_1, barcode_2, figsize=(6, 4), dpi=100):
        """
        Initialize

        :param barcode_1: The barcode 1
        :param barcode_2: The barcode 2
        :param figsize: The size of the figure plotted in the window
        :param dpi: dpi of the plotted figure
        """
        self.barcode_1 = barcode_1
        self.barcode_2 = barcode_2
        self.figsize = figsize
        self.dpi = dpi

        # Initialize the window
        self.window = tkinter.Tk()
        self.window.wm_title("Which Barcode to Inspect")
        self.window.iconbitmap(resource_path("kalmus_icon.ico"))

        # Barcode option variable
        self.barcode_option = tkinter.StringVar(self.window)
        self.barcode_option.set("Barcode 1")

        # Option radio button
        radio_barcode_1 = tkinter.Radiobutton(self.window,
                                              text="Barcode 1",
                                              variable=self.barcode_option,
                                              value="Barcode 1")
        radio_barcode_1.grid(row=0, column=0, padx=50)
        radio_barcode_1.select()

        radio_barcode_2 = tkinter.Radiobutton(self.window,
                                              text="Barcode 2",
                                              variable=self.barcode_option,
                                              value="Barcode 2")
        radio_barcode_2.grid(row=1, column=0, padx=50)

        # Inspect the barcode button
        self.button_inspect = tkinter.Button(master=self.window,
                                             text="Inspect",
                                             command=self.inspect_barcode)
        self.button_inspect.grid(row=2, column=0, padx=50)
예제 #9
0
""" Main function of the kalmus software """

from kalmus.barcodes.BarcodeGenerator import BarcodeGenerator
from kalmus.tkinter_windows.MainWindowVersion2 import MainWindow
from kalmus.tkinter_windows.gui_utils import resource_path

# Instantiate the barcode generator object
barcode_gn = BarcodeGenerator()
# Build the default barcode from the default json file
json_path = resource_path("mission_impossible_Bright_Whole_frame_Color.json")
barcode_gn.generate_barcode_from_json(json_file_path=json_path,
                                      barcode_type="Color")

# Get the default barcode
barcode_tmp = barcode_gn.get_barcode()

# Use the default barcode and the barcode generator to Instantiate the Main window of the kalmus software (GUI)
MainWindow(barcode_tmp, barcode_gn)
예제 #10
0
    def __init__(self, barcode, mouse_x, mouse_y):
        """
        Initialize

        :param barcode: The barcode with clicked point
        :param mouse_x: The x position of the clicked point
        :param mouse_y: The y position of the clicked point
        """
        self.barcode = barcode
        self.x_pos = mouse_x
        self.y_pos = mouse_y

        # Compute the frame label
        frame = (self.barcode.skip_over + self.barcode.sampled_frame_rate * \
                ((self.x_pos * self.barcode.get_barcode().shape[0]) + self.y_pos)) * self.barcode.scale_factor
        frame = int(frame)

        # If frame rate is not given, use 30 as default
        if self.barcode.fps is None:
            self.barcode.fps = 30

        # Compute the time label
        time_tot_sec = frame / self.barcode.fps
        time_sec = int(time_tot_sec % 60)
        time_min = int((time_tot_sec / 60) % 60)
        time_hr = int(time_tot_sec / 3600)

        # Initialize the window
        self.window = tkinter.Tk()
        self.window.wm_title("At this point...")
        self.window.iconbitmap(resource_path("kalmus_icon.ico"))

        # If the clicked barcode is color barcode
        if self.barcode.barcode_type == "Color":
            # Get the r, g, b value at that point
            r, g, b = barcode.get_barcode().astype("uint8")[self.y_pos,
                                                            self.x_pos]
            # Set up the label
            color_r_label = tkinter.Label(master=self.window,
                                          text="Red: {:d}".format(r),
                                          fg='#9E1A1A')
            color_r_label.grid(row=0, column=0)

            color_g_label = tkinter.Label(master=self.window,
                                          text="Green: {:d}".format(g),
                                          fg='#028A0F')
            color_g_label.grid(row=0, column=1)

            color_b_label = tkinter.Label(master=self.window,
                                          text="Blue: {:d}".format(b),
                                          fg='#1520A6')
            color_b_label.grid(row=0, column=2)

            # Show the color
            color_label = tkinter.Label(master=self.window,
                                        text="",
                                        bg=f'#{r:02x}{g:02x}{b:02x}',
                                        width=6,
                                        height=2)
            color_label.grid(row=0, column=3, rowspan=2, padx=5, pady=5)
        elif self.barcode.barcode_type == "Brightness":
            # Get the brightness value (notices that r = g = b = brightness)
            r = g = b = barcode.get_barcode().astype("uint8")[self.y_pos,
                                                              self.x_pos]
            brightness_value_label = tkinter.Label(
                master=self.window, text="Brightness: {:d}".format(r))
            brightness_value_label.grid(row=0, column=0, sticky=tkinter.E)

            # Set up the label
            brightness_label = tkinter.Label(master=self.window,
                                             text="",
                                             bg=f'#{r:02x}{g:02x}{b:02x}',
                                             width=12,
                                             height=1)
            # Show the brightness
            brightness_label.grid(row=0,
                                  column=1,
                                  columnspan=2,
                                  padx=5,
                                  pady=3)

        # Show the position
        pos_label = tkinter.Label(master=self.window,
                                  text="Position: ({:d}, {:d}) ".format(
                                      self.x_pos, self.y_pos))
        pos_label.grid(row=1, column=0)

        # Show the frame index
        self.frame_label = tkinter.Label(master=self.window,
                                         text="Frame: {:d} ".format(frame))
        self.frame_label.grid(row=1, column=1)

        # Show the time
        self.time_label = tkinter.Label(
            master=self.window,
            text="Time: {:02d}:{:02d}:{:02d} ".format(time_hr, time_min,
                                                      time_sec))
        self.time_label.grid(row=1, column=2)

        # Calibrate barcode button
        self.cali_button = tkinter.Button(master=self.window,
                                          text="Calibrate",
                                          command=self.calibrate_barcode_time)
        self.cali_button.grid(row=2, column=1)

        self.display_button = tkinter.Button(master=self.window,
                                             text="Display",
                                             command=self.display)
        self.display_button.grid(row=2, column=2)
예제 #11
0
    def __init__(self, barcode_generator, barcode_1, barcode_2, axes,
                 canvas, barcode_stack):
        """
        Initialize

        :param barcode_generator: The barcode generator
        :param barcode_1: The barcode 1
        :param barcode_2: The barcode 2
        :param axes: The axes of the plotted figure in the main window
        :param canvas: The canvas of the plotted figure in the main window
        :param barcode_stack: The dictionary that stores all the barcode on memory
        """
        self.barcode_generator = barcode_generator
        self.barcode_1 = barcode_1
        self.barcode_2 = barcode_2

        # Set up the axes and canvas
        self.axes = axes
        self.canvas = canvas

        self.barcode_stack = barcode_stack

        # Initialize the window
        self.window = tkinter.Tk()
        self.window.wm_title("Load JSON Barcode")
        self.window.iconbitmap(resource_path("kalmus_icon.ico"))

        # Label prompt for the file name/path to the json file
        filename_label = tkinter.Label(self.window, text="JSON file path: ")
        filename_label.grid(row=0, column=0, sticky=tkinter.W)

        # Text entry for user to type the file name/path to the json file
        self.filename_entry = tkinter.Entry(self.window, textvariable="", width=40)
        self.filename_entry.grid(row=0, column=1, columnspan=2, sticky=tkinter.W)

        # Label prompt for user to specify the type of the barcode they will load
        barcode_type_label = tkinter.Label(self.window, text="Specify Barcode Type: ")
        barcode_type_label.grid(row=1, column=0, sticky=tkinter.W)

        # The variable that stores the type of barcode
        self.type_variable = tkinter.StringVar(self.window)
        self.type_variable.set("Color")

        # The dropdown menu for user to select the type of the loaded barcode
        dropdown_type = tkinter.OptionMenu(self.window, self.type_variable, "Color", "Brightness")
        dropdown_type.grid(row=1, column=1, sticky=tkinter.W)

        # Button to build/load the barcode using the given json file
        self.button_build_barcode = tkinter.Button(self.window, text="Load", command=self.build_barcode)
        self.button_build_barcode.grid(row=2, column=3, columnspan=1)

        # Button to browse the folder
        self.button_browse_folder = tkinter.Button(self.window, text="Browse", command=self.browse_folder)
        self.button_browse_folder.grid(row=0, column=3)

        # Variable that stores whcih barcode in the main window to replace with
        self.barcode_option = tkinter.StringVar(self.window)
        self.barcode_option.set("Barcode 1")

        # Radio button for selecting which barcode in the main window to replace with
        radio_barcode_1 = tkinter.Radiobutton(self.window, text="Barcode 1", variable=self.barcode_option,
                                            value="Barcode 1", anchor='w')
        radio_barcode_1.grid(row=1, column=2, sticky=tkinter.W)
        radio_barcode_1.select()

        radio_barcode_2 = tkinter.Radiobutton(self.window, text="Barcode 2", variable=self.barcode_option,
                                           value="Barcode 2", anchor='w')
        radio_barcode_2.grid(row=2, column=2, sticky=tkinter.W)
    def __init__(self, barcode_generator, barcode_stack):
        """
        Initialize

        :param barcode_generator: The barcode generator
        :param barcode_stack: The dictionary that stores all the barcode on the memory
        """
        self.barcode_generator = barcode_generator
        self.barcode_stack = barcode_stack

        # Initialize the window
        self.window = tkinter.Tk()
        self.window.wm_title("Barcode Generator")
        self.window.iconbitmap(resource_path("kalmus_icon.ico"))

        # A temporary meta data dictionary that will hold the meta information given by the user
        self.meta_data_dict = {}

        # video object capture by cv2
        self.video = None

        # Label prompt for the generated barcode's barcode type
        barcode_type_label = tkinter.Label(self.window, text="Barcode Type: ")
        barcode_type_label.grid(row=0, column=0)

        # Label prompt for the frame sampling type
        frame_type_label = tkinter.Label(self.window, text="Frame Type: ")
        frame_type_label.grid(row=1, column=0)

        # Label prompt for the color/brightness metric
        color_metric_label = tkinter.Label(self.window, text="Color metric: ")
        color_metric_label.grid(row=2, column=0)

        # Variable that stores the user's choice of generated barcode type
        self.barcode_type_var = tkinter.StringVar(self.window)
        self.barcode_type_var.set("Color")

        # Dropdown menu for the barcode type selection
        dropdown_bar_type = tkinter.OptionMenu(self.window,
                                               self.barcode_type_var, "Color",
                                               "Brightness")
        dropdown_bar_type.grid(row=0, column=1)

        # Variable that stores the user's choice of frame sampling type
        self.frame_type_var = tkinter.StringVar(self.window)
        self.frame_type_var.set("Whole_frame")

        # Dropdown menu for the frame sampling type selection
        dropdown_frame_type = tkinter.OptionMenu(self.window,
                                                 self.frame_type_var,
                                                 "Whole_frame",
                                                 "Low_contrast_region",
                                                 "High_contrast_region",
                                                 "Foreground", "Background")
        dropdown_frame_type.grid(row=1, column=1)

        # Variable that stores the user's choice of color metric
        self.color_metric_var = tkinter.StringVar(self.window)
        self.color_metric_var.set("Average")

        # Dropdown menu for the color metric selection
        dropdown_color_metric = tkinter.OptionMenu(
            self.window, self.color_metric_var, "Average", "Median", "Mode",
            "Top-dominant", "Weighted-dominant", "Bright", "Brightest")
        dropdown_color_metric.grid(row=2, column=1)

        # Label prompt for the skip over specification
        self.skip_over_label = tkinter.Label(self.window,
                                             text="Start at (frames): ")
        self.skip_over_label.grid(row=0, column=2)

        # Label prompt for the sample rate specification
        self.sampled_rate_label = tkinter.Label(self.window,
                                                text="Sample every (frames): ")
        self.sampled_rate_label.grid(row=1, column=2)

        # Label prompt for the total frame included specification
        self.total_frames_label = tkinter.Label(self.window,
                                                text="Total frames: ")
        self.total_frames_label.grid(row=2, column=2)

        # Acquisition unit specification (in frames or in time)
        self.acquisition_label = tkinter.Label(self.window,
                                               text="Acquistion unit")
        self.acquisition_label.grid(row=0, column=5)

        # Variable that stores the user's choice of acquisition unit
        self.acquisition_option = tkinter.StringVar(self.window)
        self.acquisition_option.set("Frame")

        # Radio button for the Acquisition unit (Frame/Time) selection
        radio_frame = tkinter.Radiobutton(self.window,
                                          text="Frame",
                                          variable=self.acquisition_option,
                                          value="Frame",
                                          anchor='w',
                                          command=self.frame_unit)
        radio_frame.grid(row=1, column=5, sticky=tkinter.W)
        radio_frame.select()

        radio_time = tkinter.Radiobutton(self.window,
                                         text="Time",
                                         variable=self.acquisition_option,
                                         value="Time",
                                         anchor='w',
                                         command=self.time_unit)
        radio_time.grid(row=2, column=5, sticky=tkinter.W)

        # Text entry for the skip over specification
        self.skip_over_entry = tkinter.Entry(self.window,
                                             textvariable="0",
                                             width=12)
        self.skip_over_entry.grid(row=0, column=3, columnspan=2)

        # Text entry for the sampling rate specification
        self.sampled_rate_entry = tkinter.Entry(self.window,
                                                textvariable="1",
                                                width=12)
        self.sampled_rate_entry.grid(row=1, column=3, columnspan=2)

        # Text entry for the total frames specification
        self.total_frames_entry = tkinter.Entry(self.window,
                                                textvariable="1000",
                                                width=12)
        self.total_frames_entry.grid(row=2, column=3, columnspan=2)

        # Label prompt for the video file name input
        video_filename_label = tkinter.Label(self.window,
                                             text="Media file path: ")
        video_filename_label.grid(row=3, column=0, columnspan=1)

        # Text entry for the video file name specification
        self.video_filename_entry = tkinter.Entry(self.window,
                                                  textvariable="",
                                                  width=55)
        self.video_filename_entry.grid(row=3, column=1, columnspan=3)

        # Button to browse the folder
        self.browse_folder_button = tkinter.Button(self.window,
                                                   text='Browse',
                                                   command=self.browse_folder)
        self.browse_folder_button.grid(row=3, column=4)

        # Variable that stores the letter box option (automatic/user defined)
        self.letterbox_option = tkinter.StringVar(self.window)
        self.letterbox_option.set("Auto")  # initialize

        # Label prompt for the letter box remove option
        letterbox_label = tkinter.Label(self.window, text="Remove Letterbox: ")
        letterbox_label.grid(row=4, column=0, columnspan=1)

        # Radio button for the letter box remove option
        radio_auto = tkinter.Radiobutton(self.window,
                                         text="Auto",
                                         variable=self.letterbox_option,
                                         value="Auto",
                                         anchor='w',
                                         command=self.disable_setup)
        radio_auto.grid(row=5, column=0, sticky=tkinter.W)
        radio_auto.select()

        radio_manual = tkinter.Radiobutton(self.window,
                                           text="Manual",
                                           variable=self.letterbox_option,
                                           value="Manual",
                                           anchor='w',
                                           command=self.enable_setup)
        radio_manual.grid(row=6, column=0, sticky=tkinter.W)

        # User defined letter box label prompt
        high_ver_label = tkinter.Label(self.window, text="Upper vertical: ")
        high_ver_label.grid(row=5, column=1, columnspan=1)

        low_ver_label = tkinter.Label(self.window, text="Lower vertical: ")
        low_ver_label.grid(row=6, column=1, columnspan=1)

        # User defined letter box text entry
        self.high_ver_entry = tkinter.Entry(self.window,
                                            textvariable="-1",
                                            width=4,
                                            state="disabled")
        self.high_ver_entry.grid(row=5,
                                 column=2,
                                 columnspan=1,
                                 sticky=tkinter.W)

        self.low_ver_entry = tkinter.Entry(self.window,
                                           textvariable="-2",
                                           width=4,
                                           state="disabled")
        self.low_ver_entry.grid(row=6,
                                column=2,
                                columnspan=1,
                                sticky=tkinter.W)

        left_hor_label = tkinter.Label(self.window, text="Left horizontal: ")
        left_hor_label.grid(row=5, column=3, columnspan=1)

        right_hor_label = tkinter.Label(self.window, text="right horizontal: ")
        right_hor_label.grid(row=6, column=3, columnspan=1)

        self.left_hor_entry = tkinter.Entry(self.window,
                                            textvariable="-3",
                                            width=4,
                                            state="disabled")
        self.left_hor_entry.grid(row=5, column=4, columnspan=1)

        self.right_hor_entry = tkinter.Entry(self.window,
                                             textvariable="-4",
                                             width=4,
                                             state="disabled")
        self.right_hor_entry.grid(row=6, column=4, columnspan=1)

        # Variable that stores 0 for not saving frames during the generation 1 for saving frames during the generation
        self.var_saved_frame = tkinter.IntVar(self.window)

        # Checkbox for the user to choose whether save the frames or not during barcode generation
        self.checkbox_saved_frame = tkinter.Checkbutton(
            self.window,
            text="Save Frames  ",
            variable=self.var_saved_frame,
            onvalue=1,
            offvalue=0,
            command=self.update_save_frame_entry)
        self.checkbox_saved_frame.grid(row=7, column=0)

        # Label prompt for saving frame
        save_frame_label = tkinter.Label(master=self.window,
                                         text="Save every (secs):")
        save_frame_label.grid(row=7, column=1, sticky=tkinter.E)

        # Text entry for the saved frames rate specification
        self.save_frame_entry = tkinter.Entry(self.window,
                                              textvariable="-8",
                                              width=4,
                                              state="normal")
        self.save_frame_entry.grid(row=7, column=2, sticky=tkinter.W)
        self.save_frame_entry.delete(0, tkinter.END)
        self.save_frame_entry.insert(0, "4")
        self.save_frame_entry.config(state="disabled")

        # Variable that stores 0 for not saving frames during the generation 1 for rescaling frame
        # during the generation
        self.var_rescale_frame = tkinter.IntVar(self.window)

        # Checkbox for the user to choose whether to rescale the frames or not during the barcode generation
        self.checkbox_rescale_frame = tkinter.Checkbutton(
            self.window,
            text="Rescale Frames",
            width=12,
            variable=self.var_rescale_frame,
            onvalue=1,
            offvalue=0,
            command=self.update_rescale_entry)
        self.checkbox_rescale_frame.grid(row=7, column=3, sticky=tkinter.E)

        # Text entry for the rescale factor specification
        self.rescale_factor_entry = tkinter.Entry(self.window,
                                                  textvariable="-7",
                                                  width=4,
                                                  state="normal")
        self.rescale_factor_entry.grid(row=7, column=4)
        self.rescale_factor_entry.delete(0, tkinter.END)
        self.rescale_factor_entry.insert(0, "0.5")
        self.rescale_factor_entry.config(state="disabled")

        # Variable that stores 0 for single thread generation 1 for multi-thread generation
        self.var_multi_thread = tkinter.IntVar(self.window)

        # Checkbox for the user to choose whether use the multi-thread or not for barcode generation
        self.checkbox_multi_thread = tkinter.Checkbutton(
            self.window,
            text="Multi-Thread:",
            variable=self.var_multi_thread,
            onvalue=1,
            offvalue=0,
            command=self.update_thread_entry)

        self.checkbox_multi_thread.grid(row=8, column=0)

        # Text entry for the thread specification
        self.thread_entry = tkinter.Entry(self.window,
                                          textvariable="-6",
                                          width=4,
                                          state="normal")
        self.thread_entry.grid(row=8, column=1, sticky=tkinter.W)
        self.thread_entry.delete(0, tkinter.END)
        self.thread_entry.insert(0, "4")
        self.thread_entry.config(state="disabled")

        # Button to generate the barcode
        self.generate_button = tkinter.Button(
            master=self.window,
            text="Generate Barcode",
            command=self.generate_barcode_thread)
        self.generate_button.grid(row=8,
                                  column=2,
                                  sticky=tkinter.W,
                                  rowspan=1,
                                  pady=5)

        # Button to specify the meta data of the generated barcode
        self.specify_data_button = tkinter.Button(master=self.window,
                                                  text="Specify Meta Data",
                                                  command=self.specify_data)
        self.specify_data_button.grid(row=8,
                                      column=3,
                                      sticky=tkinter.W,
                                      rowspan=1,
                                      pady=5)

        self.window.protocol("WM_DELETE_WINDOW", self.quit)

        # Start the window
        self.window.mainloop()
예제 #13
0
def test_resource_path():
    path = gui_utils.resource_path("kalmus_icon.ico")
    assert "../data" in path
    assert "kalmus_icon" in path
    def __init__(self, meta_data_dict, barcode=None, barcode_stacks=None):
        """
        Initialize

        :param meta_data_dict: The meta information dictionary of the barcode
        :param barcode: The barcode
        :param barcode_stacks: The dictionary that stored all the barcode on memory
        """
        self.meta_data_dict = meta_data_dict
        self.barcode = barcode
        self.barcodes_stack = barcode_stacks

        # Initialize the window
        self.window = tkinter.Tk()
        self.window.wm_title("Specify Meta Data")
        self.window.iconbitmap(resource_path("kalmus_icon.ico"))

        # Set up the label prompt for the film title specification
        self.title_label = tkinter.Label(self.window, text="Film Title:")
        self.title_label.grid(row=0, column=0, sticky=tkinter.W)

        # Set up the the entry for user to specify the barcode's film title
        self.title_entry = tkinter.Entry(self.window,
                                         textvariable="1",
                                         width=30)
        self.title_entry.grid(row=0, column=1, sticky=tkinter.W)

        # Set up the label prompt for the film director specification
        self.directory_label = tkinter.Label(self.window, text="Directors:")
        self.directory_label.grid(row=1, column=0, sticky=tkinter.W)

        # Set up the entry user to specify the film director
        self.directory_entry = tkinter.Entry(self.window,
                                             textvariable="2",
                                             width=30)
        self.directory_entry.grid(row=1, column=1, sticky=tkinter.W)

        # Set up the label prompt for the film's country of origin specification
        self.country_origin_label = tkinter.Label(self.window,
                                                  text="Country of Origin:")
        self.country_origin_label.grid(row=2, column=0, sticky=tkinter.W)

        # Set up the entry for user to specify the film's country of origin
        self.country_origin_entry = tkinter.Entry(self.window,
                                                  textvariable="3",
                                                  width=30)
        self.country_origin_entry.grid(row=2, column=1, sticky=tkinter.W)

        # Set up the label prompt for the produced year specification
        self.year_label = tkinter.Label(self.window, text="Produced Year:")
        self.year_label.grid(row=3, column=0, sticky=tkinter.W)

        # Set up the entry for user to specify the produced year of the film
        self.year_entry = tkinter.Entry(self.window,
                                        textvariable="4",
                                        width=30)
        self.year_entry.grid(row=3, column=1, sticky=tkinter.W)

        # Set up the label prompt for the film genre specification
        self.genre_label = tkinter.Label(self.window, text="Genre:")
        self.genre_label.grid(row=4, column=0, sticky=tkinter.W)

        # Genre variable
        self.genre_var = tkinter.StringVar(self.window)
        self.genre_var.set("Comedy")
        self.genre_var.trace("w", callback=self.update_other_entry)

        # Genre dropdown list
        self.genre_dropdown = tkinter.OptionMenu(self.window, self.genre_var,
                                                 *genres)
        self.genre_dropdown.grid(row=4, column=1, sticky=tkinter.W)

        # Other genre entry for user to specify a non-specified (custom) genre
        self.other_entry = tkinter.Entry(self.window,
                                         textvariable="5",
                                         width=8,
                                         state="disabled")
        self.other_entry.grid(row=4, column=2, sticky=tkinter.W)

        # Update the meta data button
        self.update_meta_button = tkinter.Button(master=self.window,
                                                 text="Update Meta Info",
                                                 command=self.update_meta_info)
        self.update_meta_button.grid(row=5, column=1)
    def __init__(self, barcode_tmp, barcode_gn, figsize=(12, 5), dpi=100):
        """
        Initialize

        :param barcode_tmp: The temporary barcode object for software initialization
        :param barcode_gn: The barcode generator object
        :param figsize: The size of the plotted figure
        :param dpi: The dpi of the plotted figure
        """
        # Initialize the barcode memory stack
        self.barcodes_stack = {"default": copy.deepcopy(barcode_tmp)}

        # Copy over the barcodes
        self.barcode_1 = copy.deepcopy(barcode_tmp)
        self.barcode_2 = copy.deepcopy(barcode_tmp)

        # Initialize the barcode's meta data to none
        self.barcode_1.meta_data = {}
        self.barcode_2.meta_data = {}

        # Get the barcode generator
        self.barcode_gn = barcode_gn

        # Initialize the window
        self.root = tkinter.Tk()

        self.root.configure(bg='#85C1FA')
        self.root.wm_title("KALMUS Version 1.3.9")
        self.root.iconbitmap(resource_path("kalmus_icon.ico"))

        # Initialize the figure
        self.fig, self.ax = plt.subplots(
            2,
            2,
            figsize=figsize,
            dpi=dpi,
            gridspec_kw={'width_ratios': [2.8, 1]},
            sharex='col',
            sharey='col')

        update_axes_title(self.ax, self.barcode_1, self.barcode_2)

        # Plot the barcodes into the figure
        self.barcode_display_1 = self.ax[0][0].imshow(
            self.barcode_1.get_barcode().astype("uint8"))
        self.barcode_display_2 = self.ax[1][0].imshow(
            self.barcode_2.get_barcode().astype("uint8"))

        # Normalize the barcode before converting the color map
        normalized_barcode_1 = self.barcode_1.get_barcode().astype(
            "float") / 255

        hsv_colors_1 = rgb2hsv(normalized_barcode_1.reshape(-1, 1, 3))
        hue_1 = hsv_colors_1[..., 0] * 360

        # The step of the histogram
        bin_step = 5
        N, bins, patches = self.ax[0][1].hist(hue_1[:, 0],
                                              bins=(np.arange(
                                                  0, 361, bin_step)))

        paint_hue_hist(bin_step, patches)

        # Update the hue histogram
        self.ax[0][1].set_xticks(np.arange(0, 361, 30))
        self.ax[0][1].set_xlabel("Color Hue (0 - 360)")
        self.ax[0][1].set_ylabel("Number of frames")

        normalized_barcode_2 = self.barcode_2.get_barcode().astype(
            "float") / 255

        hsv_colors_2 = rgb2hsv(normalized_barcode_2.reshape(-1, 1, 3))
        hue_2 = hsv_colors_2[..., 0] * 360

        N, bins, patches = self.ax[1][1].hist(hue_2[:, 0],
                                              bins=(np.arange(
                                                  0, 361, bin_step)))

        # Paint the hue histogram where each bin of the histogram is in the color of the corresponding hue
        paint_hue_hist(bin_step, patches)

        self.ax[1][1].set_xticks(np.arange(0, 361, 30))
        self.ax[1][1].set_xlabel("Color Hue (0 - 360)")
        self.ax[1][1].set_ylabel("Number of frames")

        # Use tight layout
        plt.tight_layout()

        update_axes_ticks(self.barcode_1, self.barcode_2, self.ax)

        # Draw the canvas
        self.canvas = FigureCanvasTkAgg(self.fig,
                                        master=self.root)  # A tk.DrawingArea.
        self.canvas.draw()

        self.canvas.mpl_connect('button_press_event', self.time_pick)

        # Use tkinter Frame to organize the figure widget
        toolbarFrame = tkinter.Frame(master=self.root)
        toolbarFrame.grid(row=8, column=2)

        # Set up the tool bar of the plotted figure
        self.toolbar = NavigationToolbar2Tk(self.canvas, toolbarFrame)
        self.toolbar.update()

        # Position the canvas/plotted figure into the window
        self.canvas.get_tk_widget().grid(row=0,
                                         column=1,
                                         rowspan=8,
                                         columnspan=3)

        self.generate_window_opened = False

        # Button to generate the barcode
        button_generate = tkinter.Button(master=self.root,
                                         text="Generate Barcode",
                                         command=self.generate_barcode)
        button_generate.grid(row=0, column=0, padx=3)

        # Button to load the barcode from existed json files
        button_load = tkinter.Button(master=self.root,
                                     text="Load JSON",
                                     command=self.load_json_barcode)
        button_load.grid(row=1, column=0)

        # Button to load the barcode from the memory stack
        button_load_stack = tkinter.Button(master=self.root,
                                           text="Load Memory",
                                           command=self.load_stack_barcode)
        button_load_stack.grid(row=2, column=0)

        # Button to reshape the barcode displayed in the main window
        button_reshape_barcode = tkinter.Button(master=self.root,
                                                text="Reshape Barcode",
                                                command=self.reshape_barcode)
        button_reshape_barcode.grid(row=3, column=0)

        # Button to save the barcode into json files
        button_save_json = tkinter.Button(master=self.root,
                                          text="Save JSON",
                                          command=self.save_barcode_on_stack)
        button_save_json.grid(row=4, column=0)

        # Button to save the barcode displayed into the image
        button_save_image = tkinter.Button(
            master=self.root,
            text="Save Image",
            command=self.save_image_from_display)
        button_save_image.grid(row=5, column=0)

        # Button to inspect the barcode in details
        button_barcode = tkinter.Button(master=self.root,
                                        text="Inspect Barcode",
                                        command=self.show_barcode)
        button_barcode.grid(row=6, column=0)

        # Button to show the statistics of the barcode
        button_stats_info = tkinter.Button(master=self.root,
                                           text="Stats Info",
                                           command=self.stats_info)
        button_stats_info.grid(row=7, column=0)

        # Button to quit the main window
        button_quit = tkinter.Button(master=self.root,
                                     text="Quit",
                                     command=self.close_window)
        button_quit.grid(row=8, column=0)

        # Button to check the meta data of the displayed barcodes
        button_check_meta = tkinter.Button(master=self.root,
                                           text="Check Meta Info",
                                           command=self.check_meta_info)
        button_check_meta.grid(row=8, column=3)

        # Close the window mainloop if user try to close the window
        self.root.protocol("WM_DELETE_WINDOW", self.close_window)

        # Start the main window
        self.root.mainloop()
예제 #16
0
    def __init__(self, barcode_1, barcode_2):
        """
        Initialize
        :param barcode_1: The barcode 1
        :param barcode_2: The barcode 2
        """
        # Initialize the window
        self.window = tkinter.Tk()
        self.window.iconbitmap(resource_path("kalmus_icon.ico"))
        self.window.wm_title("Save Image")

        self.barcode_1 = barcode_1
        self.barcode_2 = barcode_2

        # Label prompt for which barcode to save
        which_barcode_label = tkinter.Label(self.window, text="Barcode: ")
        which_barcode_label.grid(row=0, column=0, columnspan=1)

        # Barcode option variable
        self.barcode_option = tkinter.StringVar(self.window)
        self.barcode_option.set("Barcode 1")

        # Radio button for which barcode to save
        radio_barcode_1 = tkinter.Radiobutton(self.window,
                                              text="Barcode 1",
                                              variable=self.barcode_option,
                                              value="Barcode 1",
                                              command=self.update_size_entry)
        radio_barcode_1.grid(row=1, column=0)
        radio_barcode_1.select()

        radio_barcode_2 = tkinter.Radiobutton(self.window,
                                              text="Barcode 2",
                                              variable=self.barcode_option,
                                              value="Barcode 2",
                                              command=self.update_size_entry)
        radio_barcode_2.grid(row=2, column=0)

        # The width and height (in pixels) of the selected barcode
        width = self.barcode_1.get_barcode().shape[1]
        height = self.barcode_1.get_barcode().shape[0]

        # Resize the barcode into desirable size before saving
        self.resize_x_label = tkinter.Label(self.window,
                                            text="Saved Width (pixels): ")
        self.resize_x_label.grid(row=1, column=1, sticky=tkinter.E)

        self.resize_x_entry = tkinter.Entry(self.window,
                                            textvariable=-2,
                                            width=5)
        self.resize_x_entry.grid(row=1, column=2, padx=15, sticky=tkinter.W)
        self.resize_x_entry.insert(0, str(width))

        self.resize_y_label = tkinter.Label(self.window,
                                            text="Saved Height (pixels): ")
        self.resize_y_label.grid(row=2, column=1, sticky=tkinter.E)

        self.resize_y_entry = tkinter.Entry(self.window,
                                            textvariable=-3,
                                            width=5)
        self.resize_y_entry.grid(row=2, column=2, padx=15, sticky=tkinter.W)
        self.resize_y_entry.insert(0, str(height))

        # Label prompt for the file name (path) of the saved image
        filename_label = tkinter.Label(self.window, text="Image file path: ")
        filename_label.grid(row=3, column=0)

        # Text entry for user to specify the path of the saved image
        self.filename_entry = tkinter.Entry(self.window,
                                            textvariable="",
                                            width=40)
        self.filename_entry.grid(row=3,
                                 column=1,
                                 columnspan=1,
                                 sticky=tkinter.W)

        # Button to browse the location in a file manager window
        self.button_browse_folder = tkinter.Button(self.window,
                                                   text="Browse",
                                                   command=self.browse_folder)
        self.button_browse_folder.grid(row=3, column=2, sticky=tkinter.W)

        # Button to save the image into the given path using the given size
        self.button_save_image = tkinter.Button(master=self.window,
                                                text="Save Barcode",
                                                command=self.save_image)
        self.button_save_image.grid(row=4, column=0)