Skip to content

Commit

Permalink
3.9.4
Browse files Browse the repository at this point in the history
  • Loading branch information
nachifur committed Aug 23, 2021
1 parent e29998c commit ee0146c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion about.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ")
Expand Down
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand All @@ -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"])
Expand Down
58 changes: 29 additions & 29 deletions utils_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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_

Expand All @@ -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]
Expand Down Expand Up @@ -1258,14 +1258,16 @@ 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():
os.makedirs(Path(self.out_path_str) / 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):
Expand Down Expand Up @@ -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(
Expand All @@ -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:
Expand Down

0 comments on commit ee0146c

Please sign in to comment.