feat: 新增接口22生发控制与测试页

This commit is contained in:
xsl
2026-11-09 21:19:39 +08:00
parent c800822d54
commit b84a506b9b
21 changed files with 770 additions and 175 deletions
+15 -3
View File
@@ -858,7 +858,7 @@ def _grow_core(image_bgr, hairline_id, *, is_hr, seg_model, erode_cm, swap_mode,
mb_levels, hairline_push_cm, hairline_edge, blend_method, color_match,
color_match_strength, mb_feather_px, transition_band_px,
inpainting_fill, mask_blur, mask_dilate_scale, rid, render_viz=True,
hair_mask=None, webui_steps=None):
hair_mask=None, webui_steps=None, paste_dy=0):
"""接口11 共享核心:遮罩(pushed)→生成→硬贴回→接缝融合,产出 ④ final。
不做任何重绘。返回中间产物 dict(供接口11 构造响应、接口12 取 final+重绘带用):
@@ -903,6 +903,14 @@ def _grow_core(image_bgr, hairline_id, *, is_hr, seg_model, erode_cm, swap_mode,
mask_dilate_scale=mask_dilate_scale, webui_steps=webui_steps)
t_swap = time.time() - t0
# 接口22在生成之后才移动贴回位置,WebUI 始终使用原始坐标和遮罩。
if paste_dy:
transform = np.float32([[1, 0, 0], [0, 1, paste_dy]])
swap_result = cv2.warpAffine(swap_result, transform, (w, h))
mask_bool = cv2.warpAffine(mask_bool.astype(np.uint8), transform, (w, h),
flags=cv2.INTER_NEAREST).astype(bool)
mask_bool &= mask_viz["_upper_mask"]
# 步骤3:严格按遮罩硬贴回(无融合,用于对比)
hard_paste = image_bgr.copy()
hard_paste[mask_bool] = swap_result[mask_bool]
@@ -1038,7 +1046,7 @@ def generate_hairline_redraw(image_bgr, hairline_id, is_hr=False, seg_model="seg
inpainting_fill=1, mask_blur=11, mask_dilate_scale=1.0,
comfyui_prompt=None, beauty_alpha=0.6,
band_lo_mult=0.5, band_hi_mult=1.5, rid=None,
hair_mask=None, webui_steps=None):
hair_mask=None, webui_steps=None, paste_dy=0):
"""接口12 发际线带重绘。内部先跑接口11 核心拿到 ④ final,再取 ⑤-① 发际线重绘带
(外推↔内推之间、经 baseline 截断只留上部)作遮罩。
@@ -1067,7 +1075,7 @@ def generate_hairline_redraw(image_bgr, hairline_id, is_hr=False, seg_model="seg
mb_feather_px=mb_feather_px, transition_band_px=transition_band_px,
inpainting_fill=inpainting_fill, mask_blur=mask_blur,
mask_dilate_scale=mask_dilate_scale, rid=rid, render_viz=False,
hair_mask=hair_mask, webui_steps=webui_steps)
hair_mask=hair_mask, webui_steps=webui_steps, paste_dy=paste_dy)
final = core["final"]
mask_viz = core["mask_viz"]
w, h = core["w"], core["h"]
@@ -1084,6 +1092,10 @@ def generate_hairline_redraw(image_bgr, hairline_id, is_hr=False, seg_model="seg
redraw_info = {"enabled": False}
band_mask = None
try:
if paste_dy:
offset = np.array([0, paste_dy])
if inner_pts is not None and outer_pts is not None:
inner_pts, outer_pts = inner_pts + offset, outer_pts + offset
band_mask = _redraw_band_mask(inner_pts, outer_pts, h, w, rid=rid, upper=upper_mask,
lo_mult=band_lo_mult, hi_mult=band_hi_mult)
if band_mask.sum() < 30: