Renamed techniques by technique category; Added new approach, but without wrapper
This commit is contained in:
@@ -79,10 +79,24 @@ class VTOONIFY:
|
||||
pad_left, pad_right,
|
||||
cv2.BORDER_REFLECT_101)
|
||||
return img_pad, (pad_top, pad_bottom, pad_left, pad_right)
|
||||
|
||||
@staticmethod
|
||||
def _resize_if_large(img, max_side=800):
|
||||
h, w = img.shape[:2]
|
||||
if max(h, w) <= max_side:
|
||||
return img
|
||||
scale = max_side / max(h, w)
|
||||
img_small = cv2.resize(img,
|
||||
(int(w * scale), int(h * scale)),
|
||||
interpolation=cv2.INTER_LINEAR)
|
||||
return img_small
|
||||
|
||||
|
||||
def obfuscate(self, face_roi_img_bgr: np.ndarray) -> np.ndarray:
|
||||
H0, W0 = face_roi_img_bgr.shape[:2]
|
||||
|
||||
face_roi_img_bgr = self._resize_if_large(face_roi_img_bgr)
|
||||
|
||||
kernel_1d = np.array([[0.125], [0.375], [0.375], [0.125]])
|
||||
|
||||
paras = get_video_crop_parameter(face_roi_img_bgr,
|
||||
@@ -103,7 +117,7 @@ class VTOONIFY:
|
||||
|
||||
I_pil = align_face(face_rgb, self.landmarkpredictor)
|
||||
if I_pil is None:
|
||||
I_pil = self.safe_align(face_roi_img_bgr) # already RGB inside
|
||||
I_pil = self.safe_align(face_roi_img_bgr)
|
||||
|
||||
I_tensor = self.transform(I_pil).unsqueeze(0).to(self.device)
|
||||
|
||||
@@ -134,11 +148,13 @@ class VTOONIFY:
|
||||
y_tilde = torch.clamp(y_tilde, -1, 1)
|
||||
|
||||
out = tensor2cv2(y_tilde[0].cpu()) # BGR uint8
|
||||
|
||||
|
||||
pad_top, pad_bottom, pad_left, pad_right = pads
|
||||
out = out[pad_top: out.shape[0]-pad_bottom,
|
||||
pad_left: out.shape[1]-pad_right] # symmetrical un‑pad
|
||||
pad_left: out.shape[1]-pad_right]
|
||||
|
||||
out = cv2.resize(out, (W0, H0), cv2.INTER_LINEAR) # back to caller’s size
|
||||
out = cv2.resize(out, (W0, H0), cv2.INTER_LINEAR)
|
||||
return out
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1 @@
|
||||
@echo off
|
||||
REM — Activate your conda env and return here
|
||||
call conda activate obfuscation_platform_p38
|
||||
if ERRORLEVEL 1 (
|
||||
echo Failed to activate obda environment.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Environment activated. Starting server...
|
||||
uvicorn face_obfuscator:app --host 127.0.0.1 --port 8000
|
||||
pause
|
||||
conda activate obfuscation_platform_p38
|
||||
Reference in New Issue
Block a user