Skip to content

Commit

Permalink
fix bug: magnifier box with scale
Browse files Browse the repository at this point in the history
  • Loading branch information
nachifur committed May 23, 2021
1 parent 91410ff commit e864cc1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
24 changes: 17 additions & 7 deletions mulimg_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def __init__(self, parent, UpdateUI, get_type):
self.color_list = []
self.box_id = -1
self.xy_magnifier=[]
show_scale = self.show_scale.GetLineText(0).split(',')
show_scale = [float(x) for x in show_scale]
self.show_scale_old=show_scale

def frame_resize(self, event):
self.auto_layout(frame_resize=True)
Expand Down Expand Up @@ -280,7 +283,7 @@ def up_img(self, event):
x,y = self.get_center_box(self.ImgManager.crop_points[self.box_id])
x=x+0
y=y-1
self.xy_magnifier[self.box_id] = self.move_box_point(x, y)
self.xy_magnifier[self.box_id][0:3] = self.move_box_point(x, y)
self.refresh(event)
else:
size = self.scrolledWindow_img.GetSize()
Expand All @@ -300,7 +303,7 @@ def down_img(self, event):
x,y = self.get_center_box(self.ImgManager.crop_points[self.box_id])
x=x+0
y=y+1
self.xy_magnifier[self.box_id] = self.move_box_point(x, y)
self.xy_magnifier[self.box_id][0:3] = self.move_box_point(x, y)
self.refresh(event)
else:
size = self.scrolledWindow_img.GetSize()
Expand All @@ -323,7 +326,7 @@ def right_img(self, event):
x,y = self.get_center_box(self.ImgManager.crop_points[self.box_id])
x=x+1
y=y+0
self.xy_magnifier[self.box_id] = self.move_box_point(x, y)
self.xy_magnifier[self.box_id][0:3] = self.move_box_point(x, y)
self.refresh(event)
else:
size = self.scrolledWindow_img.GetSize()
Expand All @@ -346,7 +349,7 @@ def left_img(self, event):
x,y = self.get_center_box(self.ImgManager.crop_points[self.box_id])
x=x-1
y=y+0
self.xy_magnifier[self.box_id] = self.move_box_point(x, y)
self.xy_magnifier[self.box_id][0:3] = self.move_box_point(x, y)
self.refresh(event)
else:
size = self.scrolledWindow_img.GetSize()
Expand Down Expand Up @@ -452,7 +455,10 @@ def img_left_release(self, event):
if width > 5 and height > 5:
self.xy_magnifier = []
self.color_list.append(self.colourPicker_draw.GetColour())
self.xy_magnifier.append([x, y, x_0, y_0])

show_scale = self.show_scale.GetLineText(0).split(',')
show_scale = [float(x) for x in show_scale]
self.xy_magnifier.append([x, y, x_0, y_0]+show_scale)
self.refresh(event)

def img_right_click(self, event):
Expand All @@ -465,7 +471,11 @@ def img_right_click(self, event):
if self.magnifier.Value:
self.color_list.append(self.colourPicker_draw.GetColour())
try:
self.xy_magnifier.append(self.move_box_point(x, y))
show_scale = self.show_scale.GetLineText(0).split(',')
show_scale = [float(x) for x in show_scale]
points = self.move_box_point(x, y)
points_show_scale = points+show_scale
self.xy_magnifier.append(points_show_scale)
except:
self.SetStatusText_(["-1", "Drawing a box need click left mouse button!", "-1", "-1"])
self.refresh(event)
Expand Down Expand Up @@ -597,7 +607,7 @@ def set_img_layout(self):
def show_img(self):
# check layout_params change
try:
if self.layout_params_old != self.ImgManager.layout_params[0:3]:
if self.layout_params_old[0:3] != self.ImgManager.layout_params[0:3]:
action_count = self.ImgManager.action_count
self.ImgManager.init(
self.ImgManager.input_path, self.ImgManager.type)
Expand Down
8 changes: 6 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,9 @@ def img_preprocessing(self, img):
def crop_points_process(self, crop_points, img_mode=0):
"""img_mode, 0: show, 1: save"""
crop_points_ = []
for crop_point in crop_points:
for crop_point_scale in crop_points:
crop_point = crop_point_scale[0:4]
show_scale_old = crop_point_scale[4:6]
if crop_point[2] < crop_point[0]:
temp = crop_point[0]
crop_point[0] = crop_point[2]
Expand Down Expand Up @@ -748,7 +750,9 @@ def crop_points_process(self, crop_points, img_mode=0):
scale = np.array(
self.layout_params[5])/np.array(self.layout_params[4])
else:
scale = self.layout_params[4]
show_scale = self.layout_params[4]
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])
Expand Down

0 comments on commit e864cc1

Please sign in to comment.