adapted client for synthetic face, but also server...

This commit is contained in:
2025-07-21 20:50:12 +02:00
parent d29b8bd8ac
commit af589ecc6b
5 changed files with 10 additions and 23 deletions
Binary file not shown.
+2
View File
@@ -6,6 +6,7 @@ from obfuscation.swap import Swap
#from obfuscation.fams import FAMS
from obfuscation.pixelation import Pixelation
from obfuscation.style import Style
from obfuscation.synthetic import Synthetic
class Config:
@@ -39,6 +40,7 @@ class Config:
debug_show_preprocessing=False
obfuscation_techniques=[
Synthetic(),
Style(),
Swap(),
Blackening(),
@@ -43,14 +43,6 @@ class GANONYMIZATION():
self.padding_resize = ZeroPaddingResize(self.img_size)
self.pix2pix_transformer = Pix2PixTransformer(model_file, self.img_size, self.device)
#def obfuscate(self, face_img):
# face_img = self.padding_resize(face_img)
# face_img = self.landmark_model(face_img)
# face_img = self.pix2pix_transformer(face_img)
# face_img = torch.squeeze(face_img)
# face_img = (face_img + 1) / 2 #TODO what is this?
# return face_img
def obfuscate(self, face_img):
orig_h, orig_w = face_img.shape[:2]
@@ -70,28 +62,26 @@ class GANONYMIZATION():
face = cv2.cvtColor(face, cv2.COLOR_BGR2RGB)
#mask = np.any(face > 0, axis=2)
# build mask: everything that wasn’t black padding
gray = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY)
_, mask = cv2.threshold(gray, 1, 255, cv2.THRESH_BINARY)
#result = face_img.copy()
result = face_img.copy()
#result[mask] = face[mask]
center = (orig_w // 2, orig_h // 2)
result = cv2.seamlessClone(face, face_img, mask, center, flags=cv2.NORMAL_CLONE)
result = cv2.cvtColor(result, cv2.COLOR_RGB2BGR)
return result
app = FastAPI()
ganonymization = None
image_processing_path = "C:/Users/bijan/Desktop/obfuscation_platform/project/models/ganonymization/image_cache/"
image_processing_path = "/mnt/c/Users/bijan/Desktop/obfuscation_platform/project/models/ganonymization/image_cache/"
@app.get("/init")
def init():
try:
print("initiating face_anon_simple")
print("initiating ganonymization")
global ganonymization
ganonymization = GANONYMIZATION()
Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

+5 -10
View File
@@ -6,22 +6,17 @@ import cv2
from obfuscation.base_obfuscation_technique import ObfuscationTechnique
import requests
#NOTE: Run the server with WSL and conda obfuscation_platform_face_anon_simple
#NOTE: Run the server with WSL and conda obfuscation_platform_ganonymization
class Synthetic(ObfuscationTechnique):
"""
Replace face with generated face
"""
#TODO DEEP PRIVACY2 einbinden
#TODO Problem ist, dass wir hier
def __init__(self):
print("synthetic not active")
# self.image_processing_path = "C:/Users/bijan/Desktop/obfuscation_platform/project/models/deep_privacy2/image_cache/"
# resp = requests.get(f"http://127.0.0.1:8000/init", timeout=120)
# resp.raise_for_status()
#print("synthetic not active")
self.image_processing_path = "C:/Users/bijan/Desktop/obfuscation_platform/project/models/ganonymization/image_cache/"
resp = requests.get(f"http://127.0.0.1:8000/init", timeout=120)
resp.raise_for_status()
def obfuscate(self, face_roi_img_bgr: np.ndarray) -> np.ndarray: