CoolFace
Apppublic

luzasd/forensic

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
detect.py23 linesDownload Raw Back to root
1import cv2
2import numpy as np
3
4def detect_watermark_image(image):
5    ycrcb_image = cv2.cvtColor(image, cv2.COLOR_BGR2YCrCb)
6    y_channel, _, _ = cv2.split(ycrcb_image)
7    dct_y = cv2.dct(np.float32(y_channel))
8    
9    # Detecting the watermark
10    watermark = np.zeros_like(dct_y)
11    rows, cols = dct_y.shape
12    font = cv2.FONT_HERSHEY_SIMPLEX
13    text = "WATERMARK"
14    text_size = cv2.getTextSize(text, font, 0.5, 1)[0]
15    text_x = np.random.randint(0, cols - text_size[0])
16    text_y = np.random.randint(text_size[1], rows)
17    watermark = cv2.putText(watermark, text, (text_x, text_y), font, 0.5, (0, 0, 255), 1, cv2.LINE_AA)
18    
19    detected_image = cv2.idct(dct_y + watermark)
20    detected_image = np.uint8(np.clip(detected_image, 0, 255))
21    
22    return detected_image
23