示例#1
0
    def undoCrop(self,event=None):
        """
        Undoes crop and resets the raw image

        @type  event: event
        @param event: Ctrl + Z event

        @rtype:  None
        @return: None
        """
        if event != None:
            self.x0 = None
            self.y0 = None
            self.x1 = None
            self.y1 = None
        self.draw_np = np.copy(self.org_np)
        self.img_im = tab_tools.np2im(self.draw_np)
        self.resized_im = tab_tools.resizeIm(self.img_im,self.org_width,self.org_height,self.t1c1i1_width,self.t1c1i1_height)
        self.img_tk = tab_tools.im2tk(self.resized_im)
        self.t1c1i1.configure(image=self.img_tk)
        self.crop_preview_im = self.img_im.copy()
        self.crop_preview_width,self.crop_preview_height = self.crop_preview_im.size
        self.crop_preview_resized_im = tab_tools.resizeIm(self.crop_preview_im,self.crop_preview_width,self.crop_preview_height,self.t1c1i1_width*self.crop_preview_img_ratio,self.t1c1i1_height*self.crop_preview_img_ratio)
        self.crop_preview_tk = tab_tools.im2tk(self.crop_preview_resized_im)
        self.t1c2i1.configure(image=self.crop_preview_tk)
示例#2
0
    def previousRaw(self,event):
        """
        Requests and displays previous raw image

        @type  event: event
        @param event: Left arrow event

        @rtype:  None
        @return: None
        """
        if not(self.loading):
            self.loading = True
            self.t1c2r2.configure(text="loading",foreground="red") # display that it's loading
            self.master.update() # update loading setting
            self.pingServer()
            if self.serverConnected:
                query = self.interface.getPrevRawImage()
                if query == None:
                    self.noPreviousRaw()
                    self.t1_functional = False
                else:
                    self.t1_functional = True
                    self.imageID = query[1]
                    self.org_np = np.array(query[0]) #tab_tools.get_image('frame0744.jpg')
                    timestamp = datetime.datetime.fromtimestamp(self.interface.getImageInfo(self.imageID).time_stamp)
                    self.t1c2r1b.configure(text=timestamp.strftime('%H : %M : %S'))
                self.draw_np = np.copy(self.org_np)
                self.img_im = tab_tools.np2im(self.draw_np)
                self.crop_preview_im = self.img_im.copy()
                self.crop_preview_tk = tab_tools.im2tk(self.crop_preview_im)
                self.org_width,self.org_height = self.img_im.size
                self.crop_preview_width,self.crop_preview_height = self.img_im.size
                self.cropped = False
                self.resized_im = tab_tools.resizeIm(self.img_im,self.org_width,self.org_height,self.t1c1i1_width,self.t1c1i1_height)
                self.img_tk = tab_tools.im2tk(self.resized_im)
                self.t1c1i1.configure(image=self.img_tk)
                self.crop_preview_resized_im = tab_tools.resizeIm(self.crop_preview_im,self.crop_preview_width,self.crop_preview_height,self.t1c1i1_width*self.crop_preview_img_ratio,self.t1c1i1_height*self.crop_preview_img_ratio)
                self.crop_preview_tk = tab_tools.im2tk(self.crop_preview_resized_im)
                self.t1c2i1.configure(image=self.crop_preview_tk)
                self.t1c2r6b.configure(text="unsubmitted",foreground="red")
                # reset crop points to none
                self.x0 = None
                self.y0 = None
                self.x1 = None
                self.y1 = None
                # zooming variables
                #self.zoomPercent = 1.0  # (0.1,1.0) --> (10%,100%) of image shown
                #self.img_im_org = self.img_im.copy() # PIL raw image that won't be changed
                self.hourtime = datetime.datetime.now()
                self.t1c2r0b.configure(text="%d : %d : %d" % (self.hourtime.hour,self.hourtime.minute,self.hourtime.second))
                self.t1c2r2.configure(text="loaded",foreground="green") # display done loading
                self.loading = False
示例#3
0
    def cropImage(self,x0,y0,x1,y1):
        """
        Crops raw image
        @type  x0: integer
        @param x0: pixel x location of first click

        @type  y0: integer
        @param y0: pixel y location of first click

        @type  x1: integer
        @param x1: pixel x location of second click

        @type  y1: integer
        @param y1: pixel y location of second click

        @rtype:  None
        @return: None
        """
        if x0 < x1:
            self.cx0 = x0
            self.cx1 = x1
        else:
            self.cx0 = x1
            self.cx1 = x0
        if y0 < y1:
            self.cy0 = y0
            self.cy1 = y1
        else:
            self.cy0 = y1
            self.cy1 = y0
        self.crop_preview_im = self.crop_preview_im.crop((self.cx0,self.cy0,self.cx1,self.cy1))
        self.crop_preview_width,self.crop_preview_height = self.crop_preview_im.size
        self.crop_preview_resized_im = tab_tools.resizeIm(self.crop_preview_im,self.crop_preview_width,self.crop_preview_height,self.t1c1i1_width*self.crop_preview_img_ratio,self.t1c1i1_height*self.crop_preview_img_ratio)
        self.crop_preview_tk = tab_tools.im2tk(self.crop_preview_resized_im)
        self.t1c2i1.configure(image=self.crop_preview_tk)
示例#4
0
    def resizeEventTab1(self,event=None):
        """
        Resizes pictures on Tab1
        @type  event: event
        @param event: resize window event

        @rtype:  None
        @return: None
        """
        if self.initialized and (time.time()-self.resize_counter_tab1) > 0.050:
            if self.t1c1i1.winfo_width() > 1:
                self.resize_counter_tab1 = time.time()
                self.master.update()
                # main image
                self.t1c1i1_width = self.t1c1i1.winfo_width() #widget width
                self.t1c1i1_height = self.t1c1i1.winfo_height() # widget height
                self.resized_im = tab_tools.resizeIm(self.img_im,self.org_width,self.org_height,self.t1c1i1_width,self.t1c1i1_height)
                self.t1c1i1_img_width,self.t1c1i1_img_height = self.resized_im.size
                self.img_tk = tab_tools.im2tk(self.resized_im)
                self.t1c1i1.configure(image=self.img_tk)
                # cropped image
                self.crop_preview_resized_im = tab_tools.resizeIm(self.crop_preview_im,self.crop_preview_width,self.crop_preview_height,self.t1c1i1_width*self.crop_preview_img_ratio,self.t1c1i1_height*self.crop_preview_img_ratio)
                self.crop_preview_tk = tab_tools.im2tk(self.crop_preview_resized_im)
                self.t1c2i1.configure(image=self.crop_preview_tk)
示例#5
0
	def resizeEventTab0(self,event=None):
		"""
		Resizes picture on Tab0
		@type  event: event
		@param event: resize window event

		@rtype:  None
		@return: None
		"""
		if self.initialized and (time.time()-self.resize_counter_tab0) > 0.050:
			if self.t0c2r0.winfo_width() > 1:
				self.resize_counter_tab0 = time.time()
				self.master.update()
				# get container label height and width
				t0c2i1_width = self.t0c2r0.winfo_width()
				t0c2i1_height = self.t0c2r0.winfo_height()
				logoW, logoH = self.logo_im.size
				self.logo_resized_im = tab_tools.resizeIm(self.logo_im, logoW, logoH, t0c2i1_width, t0c2i1_height)
				self.logo_tk = tab_tools.im2tk(self.logo_resized_im)
				self.t0c2r0.configure(image=self.logo_tk)
示例#6
0
文件: tab2.py 项目: BYU-AUVSI/imaging
    def resizeEventTab2(self, event=None):
        """
        Resizes picture on Tab2
        @type  event: event
        @param event: resize window event

        @rtype:  None
        @return: None
        """
        if self.initialized and (time.time() -
                                 self.resize_counter_tab2) > 0.050:
            if self.t2c2i1.winfo_width() > 1:
                self.resize_counter_tab2 = time.time()
                self.master.update()
                self.t2c2i1_width = self.t2c2i1.winfo_width()
                self.t2c2i1_height = self.t2c2i1.winfo_height()
                self.cropped_resized_im = tab_tools.resizeIm(
                    self.cropped_im, self.cropped_width, self.cropped_height,
                    self.t2c2i1_width, self.t2c2i1_height)
                self.cropped_tk = tab_tools.im2tk(self.cropped_resized_im)
                self.t2c2i1.configure(image=self.cropped_tk)
示例#7
0
文件: tab2.py 项目: BYU-AUVSI/imaging
    def previousCropped(self, event):
        """
        Requests and displays previous cropped image

        @type  event: event
        @param event: Left arrow event

        @rtype:  None
        @return: None
        """
        if not (self.t2_entry_focus):
            focus = self.tab2.focus_get()
            self.serverConnected = self.interface.ping()
            if self.serverConnected:
                query = self.interface.getPrevCroppedImage()
                if query == None:
                    self.t2_functional = False
                    self.noPreviousCropped()
                else:
                    self.t2_functional = True
                    self.imageID = query[1]
                    self.cropped_np = np.array(query[0])
                    yaw_angle = tab_tools.getYawAngle(self.interface,
                                                      self.imageID)
                    self.cropped_np = imutils.rotate_bound(
                        self.cropped_np, yaw_angle)
                    status = query[2]
                    if status:
                        self.t2c2lr48b.configure(text='submitted',
                                                 foreground='green')
                    else:
                        self.t2c2lr48b.configure(text='unsubmitted',
                                                 foreground='red')
                self.cropped_im = tab_tools.np2im(self.cropped_np)
                self.cropped_width, self.cropped_height = self.cropped_im.size
                self.cropped_resized_im = tab_tools.resizeIm(
                    self.cropped_im, self.cropped_width, self.cropped_height,
                    self.t2c2i1_width, self.t2c2i1_height)
                self.cropped_tk = tab_tools.im2tk(self.cropped_resized_im)
                self.t2c2i1.configure(image=self.cropped_tk)
示例#8
0
	def __init__(self,master,notebook):
		# itialize variables
		self.version_num = "Version 0.1.8.1"
		self.master = master
		self.n = notebook
		self.initialized = False
		#self.default_host = '127.0.0.1' # host if running on own machine
		self.default_host = '192.168.1.10'
		self.default_port = '5000'
		self.default_idnum = 9999
		self.default_debug = False
		self.interface = client_rest.ImagingInterface(host=self.default_host,port=self.default_port,numIdsStored=self.default_idnum,isDebug=self.default_debug)
		self.resize_counter_tab0 = time.time()


		# Tab 0: SETTINGS ------------------------------------------------------
		self.tab0 = ttk.Frame(self.n)
		self.n.add(self.tab0, text='Settings')
		# makes resizing possible
		for x in range(6):
			tk.Grid.columnconfigure(self.tab0,x,weight=1)
		for y in range(10):
			tk.Grid.rowconfigure(self.tab0,y,weight=1)
		# Left Column
		self.t0c0r0 = ttk.Label(self.tab0, anchor=tk.CENTER, text='                               ')
		self.t0c0r0.grid(row=0,column=0,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
		self.t0c1r0 = ttk.Label(self.tab0, anchor=tk.CENTER, text='                               ')
		self.t0c1r0.grid(row=0,column=1,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)

		# Middle Column
		self.logo_np = tab_tools.get_image('assets/logo.png')
		self.logo_im = tab_tools.np2im(self.logo_np)
		self.logo_width,self.logo_height = self.logo_im.size
		self.logo_tk = tab_tools.im2tk(self.logo_im)

		self.t0c2r0 = ttk.Label(self.tab0, anchor=tk.CENTER,image=self.logo_tk)
		self.t0c2r0.image = self.logo_tk
		self.t0c2r0.grid(row=0,column=2,rowspan=5,columnspan=2,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
		self.t0c2r5 = ttk.Label(self.tab0, anchor=tk.E, text='Host:')
		self.t0c2r5.grid(row=5,column=2,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
		self.t0c3host = tk.StringVar()
		self.t0c3host.set(self.default_host)
		self.t0c3r5 = ttk.Entry(self.tab0,textvariable=self.t0c3host)
		self.t0c3r5.grid(row=5,column=3,sticky=tk.N+tk.S+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
		self.t0c2r6 = ttk.Label(self.tab0, anchor=tk.E, text='Port:')
		self.t0c2r6.grid(row=6,column=2,sticky=tk.N+tk.E+tk.S+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
		self.t0c3port = tk.StringVar()
		self.t0c3port.set(self.default_port)
		self.t0c3r6 = ttk.Entry(self.tab0,textvariable=self.t0c3port)
		self.t0c3r6.grid(row=6,column=3,sticky=tk.N+tk.S+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
		self.t0c2r7 = ttk.Label(self.tab0, anchor=tk.E, text='Number of IDs Stored:')
		self.t0c2r7.grid(row=7,column=2,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
		self.t0c3ids = tk.StringVar()
		self.t0c3ids.set(self.default_idnum)
		self.t0c3r7 = ttk.Entry(self.tab0,textvariable=self.t0c3ids)
		self.t0c3r7.grid(row=7,column=3,sticky=tk.N+tk.S+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
		self.t0c2r8 = ttk.Label(self.tab0, anchor=tk.E, text='Debug Mode:')
		self.t0c2r8.grid(row=8,column=2,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
		self.t0c3debug = tk.IntVar()
		self.t0c3r8 = ttk.Radiobutton(self.tab0,text='True',value=0,variable=self.t0c3debug)
		self.t0c3r8.grid(row=8,column=3,sticky=tk.N+tk.S+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
		self.t0c3r8b = ttk.Radiobutton(self.tab0,text='False',value=1,variable=self.t0c3debug)
		self.t0c3r8b.grid(row=8,column=3,sticky=tk.N+tk.S,padx=5,pady=5,ipadx=5,ipady=5)
		if not self.default_debug:
			self.t0c3debug.set(1)
		self.t0c2r9 = ttk.Button(self.tab0, text="Apply Settings",command=self.updateSettings)
		self.t0c2r9.grid(row=9,column=2,columnspan=2,sticky=tk.N+tk.S,padx=5,pady=5,ipadx=5,ipady=5)
		# Right Column
		self.t0c4r0 = ttk.Label(self.tab0, anchor=tk.CENTER, text='                                   ')
		self.t0c4r0.grid(row=0,column=4,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
		self.t0c5r0 = ttk.Label(self.tab0, anchor=tk.CENTER, text='                                   ')
		self.t0c5r0.grid(row=0,column=5,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
		self.t0c4r6 = ttk.Label(self.tab0, anchor=tk.S, text=self.version_num)
		self.t0c4r6.grid(row=6,column=4,columnspan=2,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
		self.t0c4r7 = ttk.Button(self.tab0, text="  Save Database  ",command=self.saveDatabase)
		self.t0c4r7.grid(row=7,column=4,columnspan=2,sticky=tk.N+tk.S,padx=5,pady=5,ipadx=5,ipady=5)
		self.t0c4r8 = ttk.Button(self.tab0, text="  Load Database  ",command=self.loadDatabase)
		self.t0c4r8.grid(row=8,column=4,columnspan=2,sticky=tk.N+tk.S,padx=5,pady=5,ipadx=5,ipady=5)
		if not self.default_debug:
			self.t0c4r8.configure(state=tk.DISABLED)
		self.t0c4r9 = tk.Button(self.tab0, text="Delete Database",command=self.deleteDatabase, \
								bg='red',fg='white',bd=2)
		self.t0c4r9.grid(row=9,column=4,columnspan=2,sticky=tk.N+tk.S,padx=5,pady=5,ipadx=5,ipady=5)
		if not self.default_debug:
			self.t0c4r9.configure(state=tk.DISABLED)

		# Done with initialization
		self.initialized = True
示例#9
0
    def mouse_release(self,event):
        """
        Saves pixel location of where the mouse clicks and creates crop preview
        @type  event: event
        @param event: mouse event

        @rtype:  None
        @return: None
        """
        if self.cropped:
            self.undoCrop()
        self.t1c1i1.unbind("<Motion>")
        self.t1c1i1.unbind("<ButtonRelease-1>")

        disp_width,disp_height = self.resized_im.size
        # ratio between full-size image and displayed image
        self.sr = (self.org_width/float(disp_width) + self.org_height/float(disp_height))/2.0
        self.draw_np = np.copy(self.org_np)

        # prevent going out of bounds
        x1 = event.x - self.offset_x
        y1 = event.y - self.offset_y
        if x1 > self.resized_im.size[0]:
            x1 = self.resized_im.size[0]
        elif x1 < 0:
            x1 = 0
        if y1 > self.resized_im.size[1]:
            y1 = self.resized_im.size[1]
        elif y1 < 0:
            y1 = 0
        if self.new_crop:
            self.x1 = x1
            self.y1 = y1
        else:
            self.pan_x1 = x1
            self.pan_y1 = y1
            xdif = int((self.pan_x1 - self.pan_x0))
            ydif = int((self.pan_y1 - self.pan_y0))
            self.x0_hat = self.x0 + xdif
            self.y0_hat = self.y0 + ydif
            self.x1_hat = self.x1 + xdif
            self.y1_hat = self.y1 + ydif

            # prevent panning out of bounds
            if self.x0_hat < self.x1_hat:
                if self.x0_hat < 0:
                    self.x0_hat = 0
                    self.x1_hat = np.abs(self.x1-self.x0)
                elif self.x1_hat > self.resized_im.size[0]:
                    self.x0_hat = self.resized_im.size[0]-np.abs(self.x1-self.x0)
                    self.x1_hat = self.resized_im.size[0]
            else:
                if self.x1_hat < 0:
                    self.x1_hat = 0
                    self.x0_hat = np.abs(self.x1-self.x0)
                elif self.x0_hat > self.resized_im.size[0]:
                    self.x1_hat = self.resized_im.size[0]-np.abs(self.x1-self.x0)
                    self.x0_hat = self.resized_im.size[0]
            if self.y0_hat < self.y1_hat:
                if self.y0_hat < 0:
                    self.y0_hat = 0
                    self.y1_hat = np.abs(self.y1-self.y0)
                elif self.y1_hat > self.resized_im.size[1]:
                    self.y0_hat = self.resized_im.size[1]-np.abs(self.y1-self.y0)
                    self.y1_hat = self.resized_im.size[1]
            else:
                if self.y1_hat < 0:
                    self.y1_hat = 0
                    self.y0_hat = np.abs(self.x1-self.x0)
                elif self.y0_hat > self.resized_im.size[1]:
                    self.y1_hat = self.resized_im.size[1]-np.abs(self.y1-self.y0)
                    self.y0_hat = self.resized_im.size[1]

            # save hat values as the new values
            self.x0 = self.x0_hat
            self.y0 = self.y0_hat
            self.x1 = self.x1_hat
            self.y1 = self.y1_hat

        # do nothing if it was a single click
        if self.x0 != self.x1 or self.y0 != self.y1:
            cv2.rectangle(self.draw_np,(int(self.sr*self.x0),int(self.sr*self.y0)),(int(self.sr*self.x1),int(self.sr*self.y1)),(255,0,0),2)
            self.cropImage(int(self.sr*self.x0),int(self.sr*self.y0),int(self.sr*self.x1),int(self.sr*self.y1))
            self.img_im = tab_tools.np2im(self.draw_np)
            self.resized_im = tab_tools.resizeIm(self.img_im,self.org_width,self.org_height,self.t1c1i1_width,self.t1c1i1_height)
            self.img_tk = tab_tools.im2tk(self.resized_im)
            self.t1c1i1.configure(image=self.img_tk)
            # Crop Image
            self.cropped = True
            self.t1c2r6b.configure(text="unsubmitted",foreground="red")
示例#10
0
    def mouse_move(self,event):
        """
        Gets pixel location of where the mouse is moving and show rectangle for crop preview
        @type  event: event
        @param event: mouse event

        @rtype:  None
        @return: None
        """
        self.t1c1i1.bind("<ButtonRelease-1>",self.mouse_release)
        disp_width,disp_height = self.resized_im.size
        # ratio between full-size image and displayed image
        self.sr = (self.org_width/float(disp_width) + self.org_height/float(disp_height))/2.0
        self.draw_np = np.copy(self.org_np)

        x1 = event.x - self.offset_x
        y1 = event.y - self.offset_y
        # prevent from going out of bounds
        if x1 > self.resized_im.size[0]:
            x1 = self.resized_im.size[0]
        elif x1 < 0:
            x1 = 0
        if y1 > self.resized_im.size[1]:
            y1 = self.resized_im.size[1]
        elif y1 < 0:
            y1 = 0
        if self.new_crop:
            self.x1 = x1
            self.y1 = y1
            cv2.rectangle(self.draw_np,(int(self.sr*self.x0),int(self.sr*self.y0)),(int(self.sr*self.x1),int(self.sr*self.y1)),(255,0,0),2)
        else:
            self.pan_x1 = x1
            self.pan_y1 = y1
            xdif = int((self.pan_x1 - self.pan_x0))
            ydif = int((self.pan_y1 - self.pan_y0))
            self.x0_hat = self.x0 + xdif
            self.y0_hat = self.y0 + ydif
            self.x1_hat = self.x1 + xdif
            self.y1_hat = self.y1 + ydif

            # prevent panning out of bounds
            if self.x0_hat < self.x1_hat:
                if self.x0_hat < 0:
                    self.x0_hat = 0
                    self.x1_hat = np.abs(self.x1-self.x0)
                elif self.x1_hat > self.resized_im.size[0]:
                    self.x0_hat = self.resized_im.size[0]-np.abs(self.x1-self.x0)
                    self.x1_hat = self.resized_im.size[0]
            else:
                if self.x1_hat < 0:
                    self.x1_hat = 0
                    self.x0_hat = np.abs(self.x1-self.x0)
                elif self.x0_hat > self.resized_im.size[0]:
                    self.x1_hat = self.resized_im.size[0]-np.abs(self.x1-self.x0)
                    self.x0_hat = self.resized_im.size[0]
            if self.y0_hat < self.y1_hat:
                if self.y0_hat < 0:
                    self.y0_hat = 0
                    self.y1_hat = np.abs(self.y1-self.y0)
                elif self.y1_hat > self.resized_im.size[1]:
                    self.y0_hat = self.resized_im.size[1]-np.abs(self.y1-self.y0)
                    self.y1_hat = self.resized_im.size[1]
            else:
                if self.y1_hat < 0:
                    self.y1_hat = 0
                    self.y0_hat = np.abs(self.x1-self.x0)
                elif self.y0_hat > self.resized_im.size[1]:
                    self.y1_hat = self.resized_im.size[1]-np.abs(self.y1-self.y0)
                    self.y0_hat = self.resized_im.size[1]

            cv2.rectangle(self.draw_np,(int(self.sr*self.x0_hat),int(self.sr*self.y0_hat)),(int(self.sr*self.x1_hat),int(self.sr*self.y1_hat)),(255,0,0),2)
            cv2.line(self.draw_np,(int(self.sr*self.pan_x0),int(self.sr*self.pan_y0)),(int(self.sr*self.pan_x1),int(self.sr*self.pan_y1)),(45,255,255),2)

        self.img_im = tab_tools.np2im(self.draw_np)
        self.resized_im = tab_tools.resizeIm(self.img_im,self.org_width,self.org_height,self.t1c1i1_width,self.t1c1i1_height)
        self.img_tk = tab_tools.im2tk(self.resized_im)
        self.t1c1i1.configure(image=self.img_tk)
示例#11
0
    def __init__(self,master,notebook,interface):
        # itialize variables
        self.master = master
        self.n = notebook
        self.interface = interface
        self.initialized = False
        self.resize_counter_tab1 = time.time()
        self.hourtime = datetime.datetime.now()
        self.loading = False


        self.t1_functional = False
        self.x0 = None
        self.y0 = None
        self.x1 = None
        self.y1 = None


        self.imageID = 0
        self.pingServer()
        self.draw_np = np.copy(self.org_np) # create numpy array that can be drawn on
        self.img_im = tab_tools.np2im(self.draw_np) # create PIL image of raw image numpy array
        self.crop_preview_im = self.img_im.copy()   # create PIL image of crop preview
        self.crop_preview_tk = tab_tools.im2tk(self.crop_preview_im) # create TK image of crop preview
        self.img_tk = tab_tools.im2tk(self.img_im) # create TK image of big image
        self.org_width,self.org_height = self.img_im.size # original width/height of raw PIL image
        self.crop_preview_width,self.crop_preview_height = self.img_im.size # crop width,height
        self.cropped = False

        # TAB 1: CROPPING ------------------------------------------------------
        self.tab1 = ttk.Frame(self.n)
        self.n.add(self.tab1, text='Cropping')
        # Allows everthing to be resized
        for ii in range(8):
            tk.Grid.rowconfigure(self.tab1,ii,weight=1)

        tk.Grid.columnconfigure(self.tab1,0,weight=14)
        tk.Grid.columnconfigure(self.tab1,1,weight=1)
        tk.Grid.columnconfigure(self.tab1,2,weight=1)

        self.t1c1i1 = ttk.Label(self.tab1, anchor=tk.CENTER,image=self.img_tk)
        self.t1c1i1.image = self.img_tk
        self.t1c1i1.grid(row=0,column=0,rowspan=8,columnspan=1,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
        self.t1c1i1.bind("<Button-1>",self.mouse_click)
        self.t1c1i1_width = self.t1c1i1.winfo_width()
        self.t1c1i1_height = self.t1c1i1.winfo_height()
        self.crop_preview_img_ratio = 1/7. # ratio between image and crop preview
        self.t1c2i1 = ttk.Label(self.tab1, anchor=tk.CENTER,image=self.crop_preview_tk)
        self.t1c2i1.image = self.crop_preview_tk
        self.t1c2i1.grid(row=3,column=1,columnspan=2,rowspan=3,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
        self.t1c2r0a = ttk.Label(self.tab1, anchor=tk.E, text='Current Time: ')
        self.t1c2r0a.grid(row=0,column=1,columnspan=1,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
        self.t1c2r0b = ttk.Label(self.tab1, anchor=tk.W, text="%d : %d : %d" % (self.hourtime.hour,self.hourtime.minute,self.hourtime.second))
        self.t1c2r0b.grid(row=0,column=2,columnspan=1,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
        self.t1c2r1a = ttk.Label(self.tab1, anchor=tk.E, text='Image Time: ')
        self.t1c2r1a.grid(row=1,column=1,columnspan=1,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
        self.t1c2r1b = ttk.Label(self.tab1, anchor=tk.W, text='N/A')
        self.t1c2r1b.grid(row=1,column=2,columnspan=1,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
        self.t1c2r2 = ttk.Label(self.tab1, anchor=tk.S, text='Loaded',foreground='green')
        self.t1c2r2.grid(row=2,column=1,columnspan=2,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
        self.t1c2r6a = ttk.Label(self.tab1, anchor=tk.E, text='Submission Status: ')
        self.t1c2r6a.grid(row=6,column=1,columnspan=1,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
        self.t1c2r6b = ttk.Label(self.tab1, anchor=tk.W, text='N/A')
        self.t1c2r6b.grid(row=6,column=2,columnspan=1,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)
        self.t1c2r7 = ttk.Button(self.tab1, text="Submit Crop",command=self.submitCropped)
        self.t1c2r7.grid(row=7,column=1,columnspan=2,sticky=tk.N+tk.S+tk.E+tk.W,padx=5,pady=5,ipadx=5,ipady=5)

        # Zooming variables
        #self.imageFocus = False # whether or not mouse is over image label
        #self.zoomPercent = 1.0  # (0.1,1.0) --> (10%,100%) of image shown
        #self.img_im_org = self.img_im.copy() # PIL raw image that won't be changed


        self.initialized = True
示例#12
0
文件: tab2.py 项目: BYU-AUVSI/imaging
    def __init__(self, master, notebook, interface):
        self.master = master
        self.n = notebook
        self.interface = interface
        self.initialized = False
        self.resize_counter_tab2 = time.time()

        self.pingServer()
        self.cropped_im = tab_tools.np2im(self.cropped_np)
        self.cropped_width, self.cropped_height = self.cropped_im.size
        self.cropped_tk = tab_tools.im2tk(self.cropped_im)

        # Tab 2 variables
        self.t2_functional = False  # prevent
        self.t2_entry_focus = False

        # TAB 2: CLASSIFICATION ------------------------------------------------
        self.tab2 = ttk.Frame(self.n)  # second page
        self.n.add(self.tab2, text='Classification')

        for x in range(16):
            tk.Grid.columnconfigure(self.tab2, x, weight=1)
        for y in range(50):
            tk.Grid.rowconfigure(self.tab2, y, weight=1)

        # Column One
        self.t2c1title = ttk.Label(self.tab2,
                                   anchor=tk.CENTER,
                                   text='                  ')
        self.t2c1title.grid(row=0,
                            column=0,
                            columnspan=4,
                            sticky=tk.N + tk.S + tk.E + tk.W,
                            padx=5,
                            pady=5,
                            ipadx=5,
                            ipady=5)

        # Column Two
        self.t2sep12 = ttk.Separator(self.tab2, orient=tk.VERTICAL)
        self.t2sep12.grid(row=0,
                          column=4,
                          rowspan=50,
                          sticky=tk.N + tk.S + tk.E + tk.W,
                          pady=5)
        self.t2c2title = ttk.Label(self.tab2,
                                   anchor=tk.CENTER,
                                   text='Classification')
        self.t2c2title.grid(row=0,
                            column=4,
                            columnspan=8,
                            sticky=tk.N + tk.S + tk.E + tk.W,
                            padx=5,
                            pady=5,
                            ipadx=5,
                            ipady=5)
        self.t2c2i1 = ttk.Label(self.tab2,
                                anchor=tk.CENTER,
                                image=self.cropped_tk)
        self.t2c2i1.image = self.cropped_tk
        self.t2c2i1.grid(row=2,
                         column=4,
                         rowspan=38,
                         columnspan=8,
                         sticky=tk.N + tk.S + tk.E + tk.W,
                         padx=5,
                         pady=5,
                         ipadx=5,
                         ipady=5)
        self.t2c2l1 = ttk.Label(self.tab2, anchor=tk.CENTER, text='Shape')
        self.t2c2l1.grid(row=40,
                         column=4,
                         columnspan=2,
                         rowspan=2,
                         sticky=tk.N + tk.S + tk.E + tk.W,
                         padx=5,
                         pady=5,
                         ipadx=5,
                         ipady=5)
        shape_options = ('circle', 'semicircle', 'quarter_circle', 'triangle',
                         'square', 'rectangle', 'trapezoid', 'pentagon',
                         'hexagon', 'heptagon', 'octagon', 'star', 'cross')
        self.t2c2l2_var = tk.StringVar(self.master)
        self.t2c2l2 = ttk.OptionMenu(self.tab2, self.t2c2l2_var,
                                     shape_options[0], *shape_options)
        self.t2c2l2.grid(row=42,
                         column=4,
                         columnspan=2,
                         rowspan=2,
                         sticky=tk.N + tk.S + tk.E + tk.W,
                         padx=5,
                         pady=5,
                         ipadx=5,
                         ipady=5)
        self.t2c2l3 = ttk.Label(self.tab2,
                                anchor=tk.CENTER,
                                text='Alphanumeric')
        self.t2c2l3.grid(row=40,
                         column=6,
                         columnspan=2,
                         rowspan=2,
                         sticky=tk.N + tk.S + tk.E + tk.W,
                         padx=5,
                         pady=5,
                         ipadx=5,
                         ipady=5)
        self.t2c2l4_var = tk.StringVar(self.master)
        alphanumericValidateCommand = self.master.register(
            self.alphanumericValidate)
        self.t2c2l4 = ttk.Entry(self.tab2,
                                textvariable=self.t2c2l4_var,
                                validate=tk.ALL,
                                validatecommand=(alphanumericValidateCommand,
                                                 '%d', '%P'))
        self.t2c2l4.grid(row=42,
                         column=6,
                         columnspan=2,
                         rowspan=2,
                         sticky=tk.N + tk.S + tk.E + tk.W,
                         padx=5,
                         pady=5,
                         ipadx=5,
                         ipady=5)
        self.t2c2l5 = ttk.Label(self.tab2,
                                anchor=tk.CENTER,
                                text='Orientation')
        self.t2c2l5.grid(row=40,
                         column=8,
                         columnspan=4,
                         rowspan=2,
                         sticky=tk.N + tk.S + tk.E + tk.W,
                         padx=5,
                         pady=5,
                         ipadx=5,
                         ipady=5)
        orientation_options = ('N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW')
        self.t2c2l6_var = tk.StringVar(self.master)
        self.t2c2l6 = ttk.OptionMenu(self.tab2, self.t2c2l6_var,
                                     orientation_options[0],
                                     *orientation_options)
        self.t2c2l6.grid(row=42,
                         column=8,
                         columnspan=4,
                         rowspan=2,
                         sticky=tk.N + tk.S + tk.E + tk.W,
                         padx=5,
                         pady=5,
                         ipadx=5,
                         ipady=5)
        self.t2c2l9 = ttk.Label(self.tab2,
                                anchor=tk.CENTER,
                                text='Background Color')
        self.t2c2l9.grid(row=44,
                         column=4,
                         columnspan=2,
                         rowspan=2,
                         sticky=tk.N + tk.S + tk.E + tk.W,
                         padx=5,
                         pady=5,
                         ipadx=5,
                         ipady=5)
        color_options = ('white', 'black', 'gray', 'red', 'blue', 'green',
                         'yellow', 'purple', 'brown', 'orange')
        self.t2c2l10_var = tk.StringVar(self.master)
        self.t2c2l10 = ttk.OptionMenu(self.tab2, self.t2c2l10_var,
                                      color_options[0], *color_options)
        self.t2c2l10.grid(row=46,
                          column=4,
                          columnspan=2,
                          rowspan=2,
                          sticky=tk.N + tk.S + tk.E + tk.W,
                          padx=5,
                          pady=5,
                          ipadx=5,
                          ipady=5)
        self.t2c2l11 = ttk.Label(self.tab2,
                                 anchor=tk.CENTER,
                                 text='Alphanumeric Color')
        self.t2c2l11.grid(row=44,
                          column=6,
                          columnspan=2,
                          rowspan=2,
                          sticky=tk.N + tk.S + tk.E + tk.W,
                          padx=5,
                          pady=5,
                          ipadx=5,
                          ipady=5)
        self.t2c2l12_var = tk.StringVar(self.master)
        self.t2c2l12 = ttk.OptionMenu(self.tab2, self.t2c2l12_var,
                                      color_options[0], *color_options)
        self.t2c2l12.grid(row=46,
                          column=6,
                          columnspan=2,
                          rowspan=2,
                          sticky=tk.N + tk.S + tk.E + tk.W,
                          padx=5,
                          pady=5,
                          ipadx=5,
                          ipady=5)
        self.t2c2l13 = ttk.Label(self.tab2,
                                 anchor=tk.CENTER,
                                 text='Target Type')
        self.t2c2l13.grid(row=44,
                          column=8,
                          columnspan=2,
                          rowspan=2,
                          sticky=tk.N + tk.S + tk.E + tk.W,
                          padx=5,
                          pady=5,
                          ipadx=5,
                          ipady=5)
        self.t2c2l14_var = tk.StringVar(self.master)
        target_options = ('standard', 'emergent', 'off_axis')
        self.t2c2l14 = ttk.OptionMenu(self.tab2, self.t2c2l14_var,
                                      target_options[0], *target_options)
        self.t2c2l14.grid(row=46,
                          column=8,
                          columnspan=2,
                          rowspan=2,
                          sticky=tk.N + tk.S + tk.E + tk.W,
                          padx=5,
                          pady=5,
                          ipadx=5,
                          ipady=5)
        self.t2c2l14_var.trace("w", self.disableEmergentDescription)
        self.t2c2l15 = ttk.Label(self.tab2,
                                 anchor=tk.CENTER,
                                 text='Emergent Description')
        self.t2c2l15.grid(row=44,
                          column=10,
                          columnspan=2,
                          rowspan=2,
                          sticky=tk.N + tk.S + tk.E + tk.W,
                          padx=5,
                          pady=5,
                          ipadx=5,
                          ipady=5)
        self.t2c2l16_var = tk.StringVar()
        self.t2c2l16_var.set(None)
        self.t2c2l16 = ttk.Entry(self.tab2, textvariable=self.t2c2l16_var)
        self.t2c2l16.grid(row=46,
                          column=10,
                          columnspan=2,
                          rowspan=2,
                          sticky=tk.N + tk.S + tk.E + tk.W,
                          padx=5,
                          pady=5,
                          ipadx=5,
                          ipady=5)
        self.t2c2r48a = ttk.Label(self.tab2,
                                  anchor=tk.E,
                                  text='Submission Status: ')
        self.t2c2r48a.grid(row=48,
                           column=4,
                           columnspan=2,
                           rowspan=2,
                           sticky=tk.N + tk.S + tk.E + tk.W,
                           padx=5,
                           pady=5,
                           ipadx=5,
                           ipady=5)
        self.t2c2lr48b = ttk.Label(self.tab2, anchor=tk.W, text='N/A')
        self.t2c2lr48b.grid(row=48,
                            column=6,
                            columnspan=2,
                            rowspan=2,
                            sticky=tk.N + tk.S + tk.E + tk.W,
                            padx=5,
                            pady=5,
                            ipadx=5,
                            ipady=5)
        self.t2c2l17 = ttk.Button(self.tab2,
                                  text="Submit Classification",
                                  command=self.submitClassification)
        self.t2c2l17.grid(row=48,
                          column=8,
                          columnspan=4,
                          rowspan=2,
                          sticky=tk.N + tk.S + tk.E + tk.W,
                          padx=5,
                          pady=5,
                          ipadx=5,
                          ipady=5)
        self.disableEmergentDescription()

        # Column Three
        self.t2sep23 = ttk.Separator(self.tab2, orient=tk.VERTICAL)
        self.t2sep23.grid(row=0,
                          column=12,
                          rowspan=50,
                          sticky=tk.N + tk.S + tk.E + tk.W,
                          pady=5)
        self.t2c3title = ttk.Label(self.tab2,
                                   anchor=tk.CENTER,
                                   text='                      ')
        self.t2c3title.grid(row=0,
                            column=12,
                            columnspan=4,
                            sticky=tk.N + tk.S + tk.E + tk.W,
                            padx=5,
                            pady=5,
                            ipadx=5,
                            ipady=5)
        t2c2i1_np = tab_tools.get_image('assets/compass.jpg')
        self.t2c3i1_im = tab_tools.np2im(t2c2i1_np)
        self.t2c3i1_default_width, self.t2c3i1_default_height = self.t2c3i1_im.size
        self.t2c3i1_tk = tab_tools.im2tk(self.t2c3i1_im)
        # place image
        self.t2c3i1 = ttk.Label(self.tab2,
                                anchor=tk.CENTER,
                                image=self.t2c3i1_tk)
        self.t2c3i1.image = self.t2c3i1_tk
        self.t2c3i1.grid(row=2,
                         column=12,
                         rowspan=38,
                         columnspan=4,
                         sticky=tk.N + tk.S + tk.E + tk.W,
                         padx=5,
                         pady=5,
                         ipadx=5,
                         ipady=5)

        self.initialized = True