save code

This commit is contained in:
xsl
2026-06-23 22:46:24 +08:00
parent 85f1ca521d
commit 6e8113b3ff
+6 -6
View File
@@ -161,9 +161,9 @@ def create_annotated_image(image_bgr, measure_result, hair_mask=None):
s = min(w, h) s = min(w, h)
font_size = max(11, round(s * 0.026)) # 字体更小 font_size = max(11, round(s * 0.026)) # 字体更小
line_w = max(1, round(s * 0.0022)) line_w = max(1, round(s * 0.0022))
dash_len = max(4, round(s * 0.013)) dash_len = max(4, round(s * 0.008))
gap_len = max(4, round(dash_len * 1.2)) # 虚线更稀疏(间隙>划线) gap_len = max(2, round(dash_len * 0.7)) # 虚线更稠密(间隙<划线)
arrow_size = max(2, round(s * 0.007)) # 箭头更小 arrow_size = max(2, round(s * 0.0045)) # 箭头更小
pad = max(4, round(s * 0.012)) # 文字与线的间距 pad = max(4, round(s * 0.012)) # 文字与线的间距
line_h = font_size + max(2, round(font_size * 0.18)) line_h = font_size + max(2, round(font_size * 0.18))
@@ -206,7 +206,7 @@ def create_annotated_image(image_bgr, measure_result, hair_mask=None):
# --- 3a. 横线右侧:线名(头顶/发际线/眉心/鼻翼下缘/下巴尖),文字在线上方 --- # --- 3a. 横线右侧:线名(头顶/发际线/眉心/鼻翼下缘/下巴尖),文字在线上方 ---
name_x = fx1 + pad name_x = fx1 + pad
name_gap = max(2, round(pad * 0.5)) # 文字底部到线的间距 name_gap = max(2, round(pad * 1.6)) # 文字底部到线的间距(再上移)
for i, name in enumerate(order): for i, name in enumerate(order):
text = _LINE_NAMES[name] text = _LINE_NAMES[name]
tw, th = _text_size(draw, text, font) tw, th = _text_size(draw, text, font)
@@ -237,8 +237,8 @@ def create_annotated_image(image_bgr, measure_result, hair_mask=None):
draw.text((max(2, label_right - vw), y_top + line_h), val, fill=LINE_COLOR, font=font) draw.text((max(2, label_right - vw), y_top + line_h), val, fill=LINE_COLOR, font=font)
# --- 4. 七眼每段宽度:上下交替(上 3 / 下 4),横向虚线双箭头 + 数值(无 cm) --- # --- 4. 七眼每段宽度:上下交替(上 3 / 下 4),横向虚线双箭头 + 数值(无 cm) ---
# 文字与箭头间留出「箭头高度 + pad」,避免文字压住箭头 # 文字与箭头间留更大间距,避免文字压住箭头
txt_off = arrow_size + pad txt_off = arrow_size + pad * 2
y_arrow_top = max(txt_off + font_size + 2, fy0 - pad - arrow_size) y_arrow_top = max(txt_off + font_size + 2, fy0 - pad - arrow_size)
y_arrow_bot = min(h - txt_off - font_size - 2, fy1 + pad + arrow_size) y_arrow_bot = min(h - txt_off - font_size - 2, fy1 + pad + arrow_size)
for i in range(len(xs) - 1): for i in range(len(xs) - 1):