-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add bbox auto zoom center and vertex moves independently #86
add bbox auto zoom center and vertex moves independently #86
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把代码里的注释改成英文吧
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段逻辑太复杂了,如果只是计算外接矩形,下面这段代码是不是也可以
for point in points:
x = point.x()
y = point.y()
min_x = min(min_x, x)
max_x = max(max_x, x)
min_y = min(min_y, y)
max_y = max(max_y, y)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还需要计算面积,外接矩形应该改成你这种写法
"———————————————————————\n" | ||
"Notice:For Mac users, use the 'Command' key instead of the 'Ctrl' key" | ||
) | ||
|
||
return msg | ||
|
||
|
||
def polygon_bounding_box_center_and_area(points): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
min_x, max_x, min_y, max_y初始值为正无穷和负无穷,如果points为空,这些值将保持不变,导致计算的中心坐标为nan。
建议开头添加检查
if len(points) < 3:
raise ValueError("At least three points are required to form a polygon")
返回: | ||
映射后的数值 | ||
""" | ||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
当in_max - in_min为零时,程序将抛出ZeroDivisionError。应在函数中添加检查,避免这种情况:
if in_max == in_min:
raise ValueError("in_max and in_min cannot be equal")
本次新增两个功能:
1、新增一个开关,用来自动将第一个bbox自动居中放大,适合一张图只有一个标记框的场景,例如车牌识别
2、新增5个快捷键,用来通过键盘的上下左右单独移动bbox的四个顶点,方便精确移动顶点的场景