Spaces:
Sleeping
Sleeping
Update faceless_processing.py
Browse files- faceless_processing.py +25 -24
faceless_processing.py
CHANGED
|
@@ -84,19 +84,20 @@ class LineartConfig:
|
|
| 84 |
min_silhouette_area: float = 200.0
|
| 85 |
|
| 86 |
# Silhouette outline β thicker for embroidery visibility
|
| 87 |
-
silhouette_line_thickness: int =
|
| 88 |
-
|
| 89 |
-
# Edge detection β
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
| 100 |
enable_detail_pass: bool = False
|
| 101 |
detail_canny_low: int = 15
|
| 102 |
detail_canny_high: int = 55
|
|
@@ -105,8 +106,8 @@ class LineartConfig:
|
|
| 105 |
detail_bilateral_d: int = 7
|
| 106 |
detail_bilateral_sigma: int = 60
|
| 107 |
|
| 108 |
-
# Embroidery stitch feasibility
|
| 109 |
-
min_embroidery_stitch_px: int =
|
| 110 |
|
| 111 |
# Face detection
|
| 112 |
face_scale_factor: float = 1.05
|
|
@@ -123,20 +124,20 @@ class LineartConfig:
|
|
| 123 |
# Nose: ~45β60%
|
| 124 |
# Mouth: ~60β70%
|
| 125 |
# Chin: ~80β100% β must NOT be erased
|
| 126 |
-
# cy=0.
|
| 127 |
face_cx_ratio: float = 0.50
|
| 128 |
-
face_cy_ratio: float = 0.
|
| 129 |
-
face_rx_ratio: float = 0.
|
| 130 |
-
face_ry_ratio: float = 0.
|
| 131 |
-
face_erase_blur: int =
|
| 132 |
-
face_erase_threshold: int =
|
| 133 |
|
| 134 |
# MediaPipe face landmarker: max faces
|
| 135 |
mediapipe_num_faces: int = 6
|
| 136 |
|
| 137 |
# Eyebrow drawing β thick and bold for embroidery visibility
|
| 138 |
-
eyebrow_thickness: int =
|
| 139 |
-
eyebrow_dilate: int =
|
| 140 |
|
| 141 |
|
| 142 |
def _nms_faces(faces: list, iou_thresh: float) -> list:
|
|
@@ -330,7 +331,7 @@ def build_interior_edges(rgb: np.ndarray, subject_mask: np.ndarray, cfg: Lineart
|
|
| 330 |
|
| 331 |
# --- Detail pass (fine features) ---
|
| 332 |
edges_detail = np.zeros_like(edges_primary)
|
| 333 |
-
if getattr(cfg, 'enable_detail_pass',
|
| 334 |
detail_d = getattr(cfg, 'detail_bilateral_d', 7)
|
| 335 |
detail_sigma = getattr(cfg, 'detail_bilateral_sigma', 60)
|
| 336 |
detail_ksize = getattr(cfg, 'detail_gaussian_ksize', 5)
|
|
|
|
| 84 |
min_silhouette_area: float = 200.0
|
| 85 |
|
| 86 |
# Silhouette outline β thicker for embroidery visibility
|
| 87 |
+
silhouette_line_thickness: int = 6 # bold outer contour
|
| 88 |
+
|
| 89 |
+
# Edge detection β aggressive blur + high Canny to skip fabric folds/texture.
|
| 90 |
+
# Only major structural body/clothing borders should survive.
|
| 91 |
+
canny_low: int = 50 # raised: avoids fabric crease noise
|
| 92 |
+
canny_high: int = 170 # raised: only strong structural edges
|
| 93 |
+
bilateral_d: int = 11 # larger diameter β more texture smoothing
|
| 94 |
+
bilateral_sigma_color: int = 130.0 # stronger colour smoothing
|
| 95 |
+
bilateral_sigma_space: int = 130
|
| 96 |
+
gaussian_ksize: int = 17 # bigger kernel β smoother before Canny
|
| 97 |
+
min_contour_perimeter: float = 100.0 # raised: discard short noise/fold lines
|
| 98 |
+
interior_line_thickness: int = 5 # thicker interior lines
|
| 99 |
+
|
| 100 |
+
# Secondary detail pass β OFF (adds too much clothing/texture noise)
|
| 101 |
enable_detail_pass: bool = False
|
| 102 |
detail_canny_low: int = 15
|
| 103 |
detail_canny_high: int = 55
|
|
|
|
| 106 |
detail_bilateral_d: int = 7
|
| 107 |
detail_bilateral_sigma: int = 60
|
| 108 |
|
| 109 |
+
# Embroidery stitch feasibility β longer minimum so tiny wrinkle lines are dropped
|
| 110 |
+
min_embroidery_stitch_px: int = 70
|
| 111 |
|
| 112 |
# Face detection
|
| 113 |
face_scale_factor: float = 1.05
|
|
|
|
| 124 |
# Nose: ~45β60%
|
| 125 |
# Mouth: ~60β70%
|
| 126 |
# Chin: ~80β100% β must NOT be erased
|
| 127 |
+
# cy=0.52, ry=0.16 β erases from 36% to 68% β eyebrows safely above, chin safely below.
|
| 128 |
face_cx_ratio: float = 0.50
|
| 129 |
+
face_cy_ratio: float = 0.52 # center shifted down β protects eyebrow zone
|
| 130 |
+
face_rx_ratio: float = 0.26 # moderate width
|
| 131 |
+
face_ry_ratio: float = 0.16 # tighter: 52-16=36% top, 52+16=68% bottom
|
| 132 |
+
face_erase_blur: int = 3 # tighter blur β won't spill onto eyebrows/chin
|
| 133 |
+
face_erase_threshold: int = 95 # harder edge
|
| 134 |
|
| 135 |
# MediaPipe face landmarker: max faces
|
| 136 |
mediapipe_num_faces: int = 6
|
| 137 |
|
| 138 |
# Eyebrow drawing β thick and bold for embroidery visibility
|
| 139 |
+
eyebrow_thickness: int = 7 # thicker stroke
|
| 140 |
+
eyebrow_dilate: int = 3 # extra dilation for bolder lines
|
| 141 |
|
| 142 |
|
| 143 |
def _nms_faces(faces: list, iou_thresh: float) -> list:
|
|
|
|
| 331 |
|
| 332 |
# --- Detail pass (fine features) ---
|
| 333 |
edges_detail = np.zeros_like(edges_primary)
|
| 334 |
+
if getattr(cfg, 'enable_detail_pass', False): # default=False: detail pass adds clothing noise
|
| 335 |
detail_d = getattr(cfg, 'detail_bilateral_d', 7)
|
| 336 |
detail_sigma = getattr(cfg, 'detail_bilateral_sigma', 60)
|
| 337 |
detail_ksize = getattr(cfg, 'detail_gaussian_ksize', 5)
|