Skip to content

Commit

Permalink
code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Sep 21, 2024
1 parent 5a8bc4c commit 1a14285
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
4 changes: 0 additions & 4 deletions PPOCRLabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3552,7 +3552,6 @@ def get_main_app(argv=[]):
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument("--lang", type=str, default="ch", nargs="?")
arg_parser.add_argument("--gpu", type=str2bool, default=True, nargs="?")
# 左侧列表排序方法
arg_parser.add_argument(
"--img_list_natural_sort", type=str2bool, default=True, nargs="?"
)
Expand All @@ -3564,13 +3563,10 @@ def get_main_app(argv=[]):
),
nargs="?",
)
# 外部模型参数
arg_parser.add_argument("--det_model_dir", type=str, default=None, nargs="?")
arg_parser.add_argument("--rec_model_dir", type=str, default=None, nargs="?")
arg_parser.add_argument("--rec_char_dict_path", type=str, default=None, nargs="?")
arg_parser.add_argument("--cls_model_dir", type=str, default=None, nargs="?")

# 只有一个标记框的时候自动放大居中
arg_parser.add_argument(
"--bbox_auto_zoom_center", type=str2bool, default=False, nargs="?"
)
Expand Down
1 change: 0 additions & 1 deletion libs/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class Canvas(QWidget):

epsilon = 5.0

# 切换选中标记框4个点单独上下左右移动, 默认为None,则四个点同时移动
shape_move_index = None

def __init__(self, *args, **kwargs):
Expand Down
32 changes: 12 additions & 20 deletions libs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,31 +363,31 @@ def keysInfo(lang="en"):

def polygon_bounding_box_center_and_area(points):
"""
计算多边形外接矩形的中心和面积
Calculate the center and area of the bounding rectangle of a polygon
"""
if len(points) < 3:
raise ValueError("At least three points are required to form a polygon")

area = 0
min_x = float("inf")
max_x = float("-inf")
min_y = float("inf")
max_y = float("-inf")

n = len(points)
# 计算多边形的面积和质心坐标
for i in range(n):
x1 = points[i].x()
y1 = points[i].y()
x2 = points[(i + 1) % n].x()
y2 = points[(i + 1) % n].y()
area += x1 * y2 - x2 * y1
min_x = min(min_x, x1, x2)
max_x = max(max_x, x1, x2)
min_y = min(min_y, y1, y2)
max_y = max(max_y, y1, y2)

# 计算面积
area = abs(area) / 2.0
min_x = min(min_x, x1)
max_x = max(max_x, x1)
min_y = min(min_y, y1)
max_y = max(max_y, y1)

# 计算外接矩形的中心
area = abs(area) / 2.0
center_x = (min_x + max_x) / 2
center_y = (min_y + max_y) / 2

Expand All @@ -396,16 +396,8 @@ def polygon_bounding_box_center_and_area(points):

def map_value(x, in_min, in_max, out_min, out_max):
"""
将数值x从[in_min, in_max]的范围映射到[out_min, out_max]的范围
参数:
x -- 要映射的数值
in_min -- 原始范围的最小值
in_max -- 原始范围的最大值
out_min -- 新范围的最小值
out_max -- 新范围的最大值
返回:
映射后的数值
Map the numerical value x from the range of [in_in, in_max] to the range of [out_in, out_max]
"""
if in_max == in_min:
raise ValueError("in_max and in_min cannot be equal")
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min

0 comments on commit 1a14285

Please sign in to comment.