From ee0146c52a7f42301aa77a9eb64a5e7bc28d5e6e Mon Sep 17 00:00:00 2001 From: nachifur <1476879092@qq.com> Date: Mon, 23 Aug 2021 14:54:08 +0800 Subject: [PATCH] 3.9.4 --- about.py | 2 +- main.py | 6 +++--- utils_img.py | 58 ++++++++++++++++++++++++++-------------------------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/about.py b/about.py index be71a2e..d720d0f 100755 --- a/about.py +++ b/about.py @@ -21,7 +21,7 @@ def __init__(self, parent): self.about_txt.BeginBold() self.about_txt.WriteText("Version: ") self.about_txt.EndBold() - self.about_txt.WriteText("3.9.3\n") + self.about_txt.WriteText("3.9.4\n") self.about_txt.BeginBold() self.about_txt.WriteText("Platform: ") diff --git a/main.py b/main.py index f315a6f..42adcbb 100755 --- a/main.py +++ b/main.py @@ -441,7 +441,7 @@ def img_left_click(self, event): x_y_array = [] for i in range(len(self.ImgManager.crop_points)): x_y_array.append(self.get_center_box( - self.ImgManager.crop_points[i])) + self.ImgManager.crop_points[i][0:4])) x_y_array = np.array(x_y_array) dist = (x_y_array[:, 0]-x)**2+(x_y_array[:, 1]-y)**2 self.box_id = np.array(dist).argmin() @@ -519,7 +519,7 @@ def img_left_release(self, event): show_scale = [float(x) for x in show_scale] points = self.ImgManager.ImgF.sort_box_point( [x_0, y_0, x, y], show_scale, self.ImgManager.img_resolution_origin, first_point=True) - self.xy_magnifier.append(points+show_scale+[self.title_down_up.Value]) + self.xy_magnifier.append(points+show_scale+[self.title_down_up.Value and self.title_show.Value]) self.refresh(event) def img_right_click(self, event): @@ -535,7 +535,7 @@ def img_right_click(self, event): show_scale = self.show_scale.GetLineText(0).split(',') show_scale = [float(x) for x in show_scale] points = self.move_box_point(x, y, show_scale) - self.xy_magnifier.append(points+show_scale+[self.title_down_up.Value]) + self.xy_magnifier.append(points+show_scale+[self.title_down_up.Value and self.title_show.Value]) except: self.SetStatusText_( ["-1", "Drawing a box need click left mouse button!", "-1", "-1"]) diff --git a/utils_img.py b/utils_img.py index f99ff3d..7041696 100644 --- a/utils_img.py +++ b/utils_img.py @@ -868,8 +868,19 @@ def stitch_images(self, img_mode, draw_points=[]): self.show_box = self.layout_params[14] if self.show_original and self.show_box and len(draw_points) != 0: + crop_points = self.crop_points + offset = [self.title_max_size[0]+self.layout_params[3][3],self.title_max_size[1]+self.layout_params[3][3]] + for crop_point in crop_points: + up = crop_point[-1] # down(False) or up(True) + if (up and self.title_setting[2] and self.title_setting[1]) or ((not up) and self.title_setting[2] and self.title_setting[1]): + if self.vertical: + crop_point[0] = crop_point[0]+offset[0] + crop_point[2] = crop_point[2]+offset[0] + else: + crop_point[1] = crop_point[1]+offset[1] + crop_point[3] = crop_point[3]+offset[1] self.img = self.ImgF.draw_rectangle( - self.img, self.xy_grid, self.crop_points, self.layout_params[9], line_width=self.layout_params[10]) + self.img, self.xy_grid, crop_points, self.layout_params[9], line_width=self.layout_params[10]) except: return 1 else: @@ -966,6 +977,7 @@ def crop_points_process(self, crop_points,title_up=False, img_mode=0): """img_mode, 0: show, 1: save""" crop_points_ = [] for crop_point_scale in crop_points: + crop_point_scale = copy.deepcopy(crop_point_scale) crop_point = crop_point_scale[0:4] show_scale_old = crop_point_scale[4:6] @@ -993,26 +1005,21 @@ def crop_points_process(self, crop_points,title_up=False, img_mode=0): scale = [show_scale[0]/show_scale_old[0], show_scale[1]/show_scale_old[1]] - crop_point[0] = int(crop_point[0]*scale[0]) - crop_point[1] = int(crop_point[1]*scale[1]) - crop_point[2] = int(crop_point[2]*scale[0]) - crop_point[3] = int(crop_point[3]*scale[1]) + offset = [self.title_max_size[0]+self.layout_params[3][3],self.title_max_size[1]+self.layout_params[3][3]] - if title_up and (not crop_point_scale[6]): + if crop_point_scale[6]: if self.vertical: - crop_point[0] = crop_point[0]+self.title_max_size[0]+self.layout_params[3][3] - crop_point[2] = crop_point[2]+self.title_max_size[0]+self.layout_params[3][3] + crop_point[0] = crop_point[0]-offset[0] + crop_point[2] = crop_point[2]-offset[0] else: - crop_point[1] = crop_point[1]+self.title_max_size[1]+self.layout_params[3][3] - crop_point[3] = crop_point[3]+self.title_max_size[1]+self.layout_params[3][3] - if (not title_up) and crop_point_scale[6]: - if self.vertical: - crop_point[0] = crop_point[0]-self.title_max_size[0]-self.layout_params[3][3] - crop_point[2] = crop_point[2]-self.title_max_size[0]-self.layout_params[3][3] - else: - crop_point[1] = crop_point[1]-self.title_max_size[1]-self.layout_params[3][3] - crop_point[3] = crop_point[3]-self.title_max_size[1]-self.layout_params[3][3] - crop_points_.append(crop_point) + crop_point[1] = crop_point[1]-offset[1] + crop_point[3] = crop_point[3]-offset[1] + + crop_point[0] = int(crop_point[0]*scale[0]) + crop_point[1] = int(crop_point[1]*scale[1]) + crop_point[2] = int(crop_point[2]*scale[0]) + crop_point[3] = int(crop_point[3]*scale[1]) + crop_points_.append(crop_point+[crop_point_scale[6]]) self.crop_points = crop_points_ @@ -1023,13 +1030,6 @@ def magnifier_preprocessing(self, img, img_mode=0, id=0): img_list = [] for crop_point in self.crop_points: crop_point = copy.deepcopy(crop_point) - if self.layout_params[17][2] and img_mode!=1: - if self.vertical: - crop_point[0] = crop_point[0]-self.title_max_size[0]-self.layout_params[3][3] - crop_point[2] = crop_point[2]-self.title_max_size[0]-self.layout_params[3][3] - else: - crop_point[1] = crop_point[1]-self.title_max_size[1]-self.layout_params[3][3] - crop_point[3] = crop_point[3]-self.title_max_size[1]-self.layout_params[3][3] img_list.append(img.crop(tuple(crop_point[0:4]))) gap = self.layout_params[3][4] @@ -1258,7 +1258,7 @@ def save_magnifier(self, dir_name): pass else: try: - self.crop_points_process(copy.deepcopy(self.draw_points), img_mode=1) + self.crop_points_process(copy.deepcopy(self.draw_points),title_up=self.title_setting[2], img_mode=1) if self.type == 3: sub_dir_name = "from_file" if not (Path(self.out_path_str)/dir_name).exists(): @@ -1266,6 +1266,8 @@ def save_magnifier(self, dir_name): if not (Path(self.out_path_str)/dir_name/sub_dir_name).exists(): os.makedirs(Path(self.out_path_str) / dir_name/sub_dir_name) + # origin image with box + self.save_origin_img_magnifier() for i_ in range(self.count_per_action): if self.action_count*self.count_per_action+i_ < len(self.path_list): @@ -1293,9 +1295,9 @@ def save_magnifier(self, dir_name): self.out_path_str) / dir_name/sub_dir_name / (str_+"_"+Path(img_name).stem+"_magnifier_"+str(i)+".png") img.save(f_path_output) i += 1 + else: # origin image with box self.save_origin_img_magnifier() - else: i = 0 for img in self.img_list: img_list = self.magnifier_preprocessing( @@ -1310,8 +1312,6 @@ def save_magnifier(self, dir_name): img.save(f_path_output) ii += 1 i += 1 - # origin image with box - self.save_origin_img_magnifier() except: self.check_2.append(1) else: