1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
   | 
#Les Tk.Button en haut (dans __init__)
        self.buttons = [ Tk.Button(self.fr_Upper, text="Mean-Shift filtering parmeters", command = lambda x = None: self.change_frame(0)),
                    Tk.Button(self.fr_Upper, text="Correction light parameters", command = lambda x = None: self.change_frame(1)),
                    Tk.Button(self.fr_Upper, text="Method search markers", command = lambda x = None: self.change_frame(2)),
                    Tk.Button(self.fr_Upper, text="Method fitting ellipse", command = lambda x = None: self.change_frame(3)) ]
        self.pack_buttons()
    def pack_buttons(self):
        self.buttons[0].pack(fill=Tk.X)
        self.buttons[1].pack(fill=Tk.X)
        self.buttons[2].pack(fill=Tk.X)
        self.buttons[3].pack(fill=Tk.X)
#Les  class enfants en bas à droite (dans __init__)
        self.subclasses = [ ParamMeanShift(self.fr_Lright, self.buttons[0]), ParamLight(self.fr_Lright, self.buttons[1]), ParamMarker(self.fr_Lright, self.buttons[2]), ParamFit(self.fr_Lright, self.buttons[3]) ]
    def change_frame(self, frame_choice):
        """ Destruction du frame de la sous class courante et initialisation de la nouvelle sousclasse """
        if (frame_choice!=3 and self.subclasses[frame_choice].current_image!=None ):
            global current_image        
            current_image = self.subclasses[frame_choice].current_image
            self.show_curr_img()
        self.subclasses[self.previous_choice].forget()
        self.buttons[self.previous_choice]["background"] = "white"
        self.pack_buttons()
        self.buttons[frame_choice]["background"]="green"
        self.subclasses[frame_choice].pack()
        self.previous_choice = frame_choice    
# L'image pil en bas à gauche method de la class parent
    def show_curr_img(self):
        global current_image
        display = 1
        pil_image = None
        # Conversion de numpy.ndarray OU cv.iplimage vers PIL.Image (ImageTk.Image)
        if type(current_image) == cv.iplimage:
            if current_image.nChannels == 3:
                pil_image = Image.fromstring(
                        'RGB', 
                        cv.GetSize(current_image), 
                        current_image.tostring(), 
                        'raw', 
                        'BGR', 
                        current_image.width*3, 
                        0)    
            elif current_image.nChannels==1:
                pil_image = Image.fromstring(
                        'L', 
                        cv.GetSize(current_image), 
                        current_image.tostring())
            else:
                print("Error: Format non compatible nchannels!=1 ou 3")
        elif type(current_image) == np.ndarray:
            if len(np.shape(current_image)) == 3 or len(np.shape(current_image)) == 2:
                if current_image.dtype == np.uint32:
                    im8bit = np.zeros(np.shape(current_image), dtype = np.int8)
                    im8bit += np.floor(current_image*255/(np.max(current_image)-np.min(current_image)))
                    pil_image = Image.fromarray(im8bit)
                else:
                    pil_image = Image.fromarray(current_image)
            else:
                print("Error: Format non compatible nchannels!=1 ou 3")
        elif current_image==None:
            diplay=0
        else:
            display=0
            print("type d'image gérée")
        if display:
            pil_image = pil_image.resize((450,300), Image.ANTIALIAS)
            tk_image = ImageTk.PhotoImage(pil_image)
            try:
                panel1 = Tk.Label(self.fr_Lleft, image=tk_image)
                panel1.pack()
                panel1.image = tk_image
            except ValueError:
                print(ValueError)
                pass | 
Partager