Пример #1
0
 def upload(event=None):
     global image_preview, image_preview01, image_preview02, image_preview03
     print('Uploads image')
     path = "/home/pi/DC-Box/leaf_upload.png"
     path_canny = "/home/pi/DC-Box/leaf_canny.png"
     path_gray = "/home/pi/DC-Box/leaf_gray.png"
     path_background = "/home/pi/DC-Box/leaf_background.png"
     
     filename = filedialog.askopenfilename(initialdir = "/home/pi/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("png files","*.png"),("all files","*.*")))
     image_upload = filename
     upload(image_upload, path)
     canny(image_upload, path_canny)
     gray(image_upload, path_gray)
     background(image_upload, path_background)
     
     image_preview = ImageTk.PhotoImage(Image.open("leaf_upload.png"))
     image_panel01 = tk.Label(previewimageframe, image = image_preview)
     image_panel01.grid(column=0, row=2, sticky="W")
     
     image_preview01 = ImageTk.PhotoImage(Image.open("/home/pi/DC-Box/leaf_canny.png"))
     image_panel01 = tk.Label(section04, image = image_preview01)
     image_panel01.grid(column=0, row=1, sticky="W")
     
     image_preview02 = ImageTk.PhotoImage(Image.open("/home/pi/DC-Box/leaf_gray.png"))
     image_panel02 = tk.Label(section04, image = image_preview02)
     image_panel02.grid(column=1, row=1, sticky="W")
     
     image_preview03 = ImageTk.PhotoImage(Image.open("/home/pi/DC-Box/leaf_background.png"))
     image_panel03 = tk.Label(section04, image = image_preview03)
     image_panel03.grid(column=2, row=1, sticky="W")   
Пример #2
0
 def preview(self):
     global image_preview, image_preview01, image_preview02, image_preview03
     print('Save Preview Image')
     path = "leaf_preview.png"
     path_canny = "/home/pi/DC-Box/leaf_canny.png"
     path_gray = "/home/pi/DC-Box/leaf_gray.png"
     path_background = "/home/pi/DC-Box/leaf_background.png"
     
     preview_image(path)
     
     image_preview = ImageTk.PhotoImage(Image.open("leaf_preview.png"))
     image_panel01 = tk.Label(previewimageframe, image = image_preview)
     image_panel01.grid(column=0, row=2, sticky="W")
     
     canny(path, path_canny)
     gray(path, path_gray)
     background(path, path_background)
     
     image_preview01 = ImageTk.PhotoImage(Image.open("/home/pi/DC-Box/leaf_canny.png"))
     image_panel01 = tk.Label(section04, image = image_preview01)
     image_panel01.grid(column=0, row=1, sticky="W")
     
     image_preview02 = ImageTk.PhotoImage(Image.open("/home/pi/DC-Box/leaf_gray.png"))
     image_panel02 = tk.Label(section04, image = image_preview02)
     image_panel02.grid(column=1, row=1, sticky="W")
     
     image_preview03 = ImageTk.PhotoImage(Image.open("/home/pi/DC-Box/leaf_background.png"))
     image_panel03 = tk.Label(section04, image = image_preview03)
     image_panel03.grid(column=2, row=1, sticky="W")
    def update_images(self, image):
        self.image_preview = ImageTk.PhotoImage(Image.fromarray(image))
        self.image_panel01.configure(image=self.image_preview)

        self.image_livepreview = ImageTk.PhotoImage(Image.fromarray(image))
        self.image_panel02.configure(image=self.image_livepreview)

        self.image_canny = ImageTk.PhotoImage(
            Image.fromarray(canny(self.current_image_path, "./canny.png")))
        self.image_panel03.configure(image=self.image_canny)

        self.image_gray = ImageTk.PhotoImage(
            Image.fromarray(gray(self.current_image_path, "./gray.png")))
        self.image_panel04.configure(image=self.image_gray)

        self.image_bg = ImageTk.PhotoImage(
            Image.fromarray(
                background(self.current_image_path, "./background.png")))
        self.image_panel05.configure(image=self.image_bg)

        self.image_detection = ImageTk.PhotoImage(Image.fromarray(image))
        self.image_panel06.configure(image=self.image_detection)

        self.image_classification = ImageTk.PhotoImage(Image.fromarray(image))
        self.image_panel07.configure(image=self.image_classification)

        self.image_segmentation = ImageTk.PhotoImage(Image.fromarray(image))
        self.image_panel08.configure(image=self.image_segmentation)

        self.image_bb = ImageTk.PhotoImage(
            Image.fromarray(
                boundingbox(self.current_image_path, "./boundingbox.png")))
        self.image_panel09.configure(image=self.image_bb)
    def __init__(self, classifier, SegmentationDetector, imagepath):
        #Tktiner
        root = tk.Tk()
        root.geometry('1200x1000+0+0')
        root.title("DC-Box")

        self.root = root
        self.classification_text = tk.StringVar(root)
        self.classification_text.set('\nClassification:\n\n')
        self.classifier = classifier

        self.segmentation_text = tk.StringVar(root)
        self.segmentation_text.set('\nSegmentation:\n\n')
        self.segmentationDetector = segmentationDetector

        self.detection_text = tk.StringVar(root)
        self.detection_text.set('\nDetection:\nBounding Box: xyz')

        self.livepreview_text = tk.StringVar(root)
        self.livepreview_text.set('Live-Preview')
        #local variables for data exchange
        self.current_image_path = imagepath
        self.thread = None
        self.thread_stop = True

        #Frames für die GUI
        topframe = tk.Frame(root, width=1600, height=50, bg="blue")
        topframe.grid(row=0, column=0, padx=10, pady=2)

        section01 = tk.Frame(root)
        section01.grid(row=1, column=0, padx=10, pady=2, sticky="W")

        previewframe = tk.Frame(root)
        previewframe.grid(row=2, column=0, padx=10, pady=2, sticky="W")
        previewimageframe = tk.Frame(root)
        previewimageframe.grid(row=3, column=0, padx=10, pady=2, sticky="W")

        section04 = tk.Frame(root)
        section04.grid(row=4, column=0, padx=10, pady=2, sticky="W")

        dcframe = tk.Frame(root)
        dcframe.grid(row=6, column=0, padx=10, pady=2, sticky="W")
        dcimageframe = tk.Frame(root)
        dcimageframe.grid(row=7, column=0, padx=10, pady=2, sticky="W")
        #Head
        head_text = tk.Label(topframe, font=('arial', 28), text='DC-Box').grid(
            row=0,
            column=1,
        )

        # Section 1
        section01_heading = tk.Label(section01,
                                     font=('arial', 16),
                                     text='Settings').grid(column=0,
                                                           row=0,
                                                           sticky="W")
        project_text = tk.Label(section01,
                                font=('arial', 12),
                                text='Project:  ').grid(column=0,
                                                        row=1,
                                                        sticky="W")
        #project =["Leafs"]

        f = open("program/project.txt", "r")
        project = []
        for line in f:
            project.append(line.strip())
        f.close()

        bt_new_project = tk.Button(section01,
                                   padx=1,
                                   bd=1,
                                   text="New",
                                   fg="blue",
                                   command=self.newproject)
        bt_new_project.grid(row=1, column=2, padx=5, sticky="W")

        self.project_input = ttk.Combobox(section01, values=project, width=40)
        #new
        #self.project_input.current(0)
        self.project_input.grid(column=1, row=1, pady=5)

        imagesize_text = tk.Label(section01,
                                  font=('arial', 12),
                                  text='Image Size:  ').grid(column=0,
                                                             row=2,
                                                             sticky="W")
        imagesize = ["224x224"]
        imagesize_input = ttk.Combobox(section01, values=imagesize, width=40)
        imagesize_input.current(0)
        imagesize_input.grid(column=1, row=2, pady=5)
        #new
        bt_new_imagesize = tk.Button(section01,
                                     padx=1,
                                     bd=1,
                                     text="New",
                                     fg="blue",
                                     command=self.newimagesize)
        bt_new_imagesize.grid(row=2, column=2, padx=5, sticky="W")

        label_text = tk.Label(section01, font=('arial', 12),
                              text='Label:  ').grid(column=0,
                                                    row=3,
                                                    sticky="W")
        #label=["","Abies", "Acer", "Betula"]

        labelname = "program/label.txt"
        t = open(labelname, "r")
        label = []
        for line in t:
            label.append(line.strip())
        t.close()

        self.label_input = ttk.Combobox(section01, values=label, width=40)
        self.label_input.current(0)
        self.label_input.grid(column=1, row=3, pady=5)
        #new
        bt_new_label = tk.Button(section01,
                                 padx=1,
                                 bd=1,
                                 text="New",
                                 fg="blue",
                                 command=self.newlabel)
        bt_new_label.grid(row=3, column=2, padx=5, sticky="W")

        #Preview
        preview_text = tk.Label(previewframe,
                                font=('arial', 16),
                                text='Preview').grid(column=0,
                                                     row=0,
                                                     sticky="W")
        bt_preview = tk.Button(previewframe,
                               padx=16,
                               bd=2,
                               text="Preview",
                               fg="blue",
                               command=self.preview).grid(row=1,
                                                          column=0,
                                                          pady=5,
                                                          sticky="W")
        bt_livepreview = tk.Button(previewframe,
                                   padx=16,
                                   bd=2,
                                   textvariable=self.livepreview_text,
                                   fg="blue",
                                   command=self.preview_live).grid(row=1,
                                                                   column=2,
                                                                   pady=5,
                                                                   sticky="W")
        bt_quit = tk.Button(previewframe,
                            padx=16,
                            bd=2,
                            text="Upload",
                            fg="blue",
                            command=self.upload).grid(row=1,
                                                      column=1,
                                                      pady=5,
                                                      sticky="W")
        bt_upload = tk.Button(previewframe,
                              padx=16,
                              bd=2,
                              text="Quit",
                              fg="blue",
                              command=self.root.quit).grid(row=1,
                                                           column=3,
                                                           pady=5,
                                                           sticky="W")
        saveimage_text = tk.Label(previewframe,
                                  font=('arial', 12),
                                  text='Save Image:  ').grid(column=0,
                                                             row=2,
                                                             sticky="W")
        bt_side1 = tk.Button(previewframe,
                             padx=16,
                             bd=2,
                             text="Save: Side 1",
                             fg="red",
                             command=self.side1).grid(row=3,
                                                      column=0,
                                                      pady=5,
                                                      sticky="W")
        bt_side2 = tk.Button(previewframe,
                             padx=16,
                             bd=2,
                             text="Save: Side 2",
                             fg="red",
                             command=self.side2).grid(row=3,
                                                      column=1,
                                                      pady=5,
                                                      sticky="W")

        image_preview_text = tk.Label(previewimageframe,
                                      font=('arial', 12),
                                      text='Preview Image:  ').grid(column=0,
                                                                    row=1,
                                                                    sticky="W")
        self.image_preview = ImageTk.PhotoImage(
            Image.open(self.current_image_path))
        self.image_panel01 = tk.Label(previewimageframe,
                                      image=self.image_preview)
        self.image_panel01.grid(column=0, row=2, sticky="W")

        image_livepreview_text = tk.Label(previewimageframe,
                                          font=('arial', 12),
                                          text='Live-Preview Image:  ').grid(
                                              column=1, row=1, sticky="W")
        self.image_livepreview = ImageTk.PhotoImage(
            Image.open(self.current_image_path))
        self.image_panel02 = tk.Label(previewimageframe,
                                      image=self.image_livepreview)
        self.image_panel02.grid(column=1, row=2, sticky="W")

        self.image_canny = ImageTk.PhotoImage(
            Image.fromarray(canny(self.current_image_path, "./canny.png")))
        self.image_panel03 = tk.Label(section04, image=self.image_canny)
        self.image_panel03.grid(column=0, row=1, sticky="W")

        self.image_gray = ImageTk.PhotoImage(
            Image.fromarray(gray(self.current_image_path, "./gray.png")))
        self.image_panel04 = tk.Label(section04, image=self.image_gray)
        self.image_panel04.grid(column=1, row=1, sticky="W")

        self.image_background = ImageTk.PhotoImage(
            Image.fromarray(
                background(self.current_image_path, "./backround.png")))
        self.image_panel05 = tk.Label(section04, image=self.image_background)
        self.image_panel05.grid(column=2, row=1, sticky="W")

        self.image_boundingbox = ImageTk.PhotoImage(
            Image.fromarray(
                boundingbox(self.current_image_path, "./boundingbox.png")))
        self.image_panel09 = tk.Label(section04, image=self.image_boundingbox)
        self.image_panel09.grid(column=3, row=1, sticky="W")

        # Detection/Classification
        dc_text = tk.Label(dcframe,
                           font=('arial', 14),
                           text='Detection/Classification ').grid(column=0,
                                                                  row=0)
        bt_detection = tk.Button(dcframe,
                                 padx=16,
                                 bd=2,
                                 text="Detection",
                                 fg="green",
                                 command=self.detection).grid(row=1,
                                                              column=0,
                                                              pady=5,
                                                              sticky="EW")
        bt_classification = tk.Button(dcframe,
                                      padx=16,
                                      bd=2,
                                      text="Classification",
                                      fg="green",
                                      command=self.classification).grid(
                                          row=1, column=1, pady=5)
        bt_segmentation = tk.Button(dcframe,
                                    padx=16,
                                    bd=2,
                                    text="Segmentation",
                                    fg="green",
                                    command=self.segmentation).grid(row=1,
                                                                    column=2,
                                                                    pady=5)

        self.image_detection = ImageTk.PhotoImage(
            Image.open(self.current_image_path))
        self.image_panel06 = tk.Label(dcimageframe, image=self.image_detection)
        self.image_panel06.grid(column=0, row=2, sticky="W")
        detection_image_text = tk.Label(dcimageframe,
                                        font=('arial', 12),
                                        textvariable=self.detection_text).grid(
                                            column=0, row=3, sticky="EW")

        self.image_classification = ImageTk.PhotoImage(
            Image.open(self.current_image_path))
        self.image_panel07 = tk.Label(dcimageframe,
                                      image=self.image_classification)
        self.image_panel07.grid(column=1, row=2, sticky="W")
        classification_image_text = tk.Label(
            dcimageframe,
            font=('arial', 12),
            textvariable=self.classification_text).grid(column=1,
                                                        row=3,
                                                        sticky="EW")

        self.image_segmentation = ImageTk.PhotoImage(
            Image.open(self.current_image_path))
        self.image_panel08 = tk.Label(dcimageframe,
                                      image=self.image_segmentation)
        self.image_panel08.grid(column=2, row=2, sticky="W")
        segmentation_image_text = tk.Label(
            dcimageframe,
            font=('arial', 12),
            textvariable=self.segmentation_text).grid(column=2,
                                                      row=3,
                                                      sticky="EW")

        self.root.mainloop()