예제 #1
0
 def opendir(self):
     self.parent.all_files = []
     cfg = helpers.config_to_dict(self.parent.Config, 'main')
     self.parent.input_dir = tkFileDialog.askdirectory(
         title="Select a Directory Containing Images",
         initialdir=cfg['last_in_dir'])
     self.parent.dirmode = True
     cfg['last_in_dir'] = self.parent.input_dir
     helpers.dict_to_config(cfg, self.parent.Config, True)
     valid_images = (".jpg", "jpeg", ".bmp", ".gif", ".png", ".tga")
     for f in os.listdir(self.parent.input_dir):
         if f.lower().endswith(valid_images):
             this_f = os.path.join(self.parent.input_dir, f)
             self.parent.all_files.append(this_f)
     n_img = len(self.parent.all_files)
     lbl_text = "Selected Directory: " + self.parent.input_dir
     #lbl_text += "\nDimensions (Height, Width, Colors): " + str(self.parent.img.shape)
     lbl_text += "\nNumber of Image Files in Directory: " + str(n_img)
     self.label_text.set(lbl_text)
     self.label_fname.pack(padx=5)
     print(self.parent.input_dir)
     if n_img > 0:
         self.parent.img = cv2.imread(self.parent.all_files[0])
         self.parent.img_orig = self.parent.img.copy()
         self.show_buttons()
예제 #2
0
 def save(self):
     cfg = {}
     cfg['shift_up'] = self.inp_offset_y.get()
     cfg['shift_right'] = self.inp_offset_x.get()
     cfg['horz_size'] = self.inp_horz_size.get()
     cfg['vert_size'] = self.inp_vert_size.get()
     cfg['bl_sz'] = self.inp_size.get()
     helpers.dict_to_config(cfg, self.parent.Config, True)
예제 #3
0
 def update_config(self):
     cfg = {}
     cfg['shift_up'] = self.p2.inp_offset_y.get()
     cfg['shift_right'] = self.p2.inp_offset_x.get()
     cfg['horz_size'] = self.p2.inp_horz_size.get()
     cfg['vert_size'] = self.p2.inp_vert_size.get()
     cfg['bl_sz'] = self.p2.inp_size.get()
     helpers.dict_to_config(cfg, self.Config)
     return helpers.config_to_dict(self.Config, 'main')
예제 #4
0
 def save_dir(self, cfg):
     if len(self.parent.all_out_files) < 1:
         self.parent.scramble()
     self.parent.output_dir = tkFileDialog.askdirectory(
         title="Select an Output Directory", initialdir=cfg['last_out_dir'])
     cfg['last_out_dir'] = self.parent.output_dir
     helpers.dict_to_config(cfg, self.parent.Config)
     for im, name in self.parent.all_out_files:
         f = os.path.join(self.parent.output_dir, name)
         cv2.imwrite(f, im)
예제 #5
0
 def select_output_directory(self):
     cfg = helpers.config_to_dict(self.parent.Config, 'main')
     try:
         init_dir = cfg['last_out_dir']
     except:
         init_dir = ''
     out_dir = tkFileDialog.askdirectory(
         title="Select a Directory Containing Images", initialdir=init_dir)
     cfg['last_out_dir'] = out_dir
     helpers.dict_to_config(cfg, self.parent.Config)
     self.out_dir = out_dir
예제 #6
0
 def openfile(self):
     if self.parent.mode == 'dir':
         self.opendir()
         return
     cfg = helpers.config_to_dict(self.parent.Config, 'main')
     self.file_opt['initialdir'] = cfg['last_in_dir']
     self.parent.input_file = tkFileDialog.askopenfilename(**self.file_opt)
     #self.show_button.config(state='normal')
     print(self.parent.input_file)
     if self.parent.input_file:
         self.parent.img = cv2.imread(self.parent.input_file)
         self.parent.img_orig = self.parent.img.copy()
         self.parent.dirmode = False
         dir_name = os.path.dirname(self.parent.input_file)
         cfg['last_in_dir'] = dir_name
         helpers.dict_to_config(cfg, self.parent.Config, True)
         lbl_text = "Selected File: " + self.parent.input_file
         lbl_text += "\nDimensions (Height, Width, Colors): " + str(
             self.parent.img.shape)
         self.label_text.set(lbl_text)
         self.label_fname.pack(padx=5)
         self.show_buttons()