Spaces:
Sleeping
Sleeping
import cv2 | |
import numpy as np | |
def detect_watermark_image(image): | |
ycrcb_image = cv2.cvtColor(image, cv2.COLOR_BGR2YCrCb) | |
y_channel, _, _ = cv2.split(ycrcb_image) | |
dct_y = cv2.dct(np.float32(y_channel)) | |
# Detecting the watermark | |
watermark = np.zeros_like(dct_y) | |
rows, cols = dct_y.shape | |
font = cv2.FONT_HERSHEY_SIMPLEX | |
text = "WATERMARK" | |
text_size = cv2.getTextSize(text, font, 0.5, 1)[0] | |
text_x = np.random.randint(0, cols - text_size[0]) | |
text_y = np.random.randint(text_size[1], rows) | |
watermark = cv2.putText(watermark, text, (text_x, text_y), font, 0.5, (0, 0, 255), 1, cv2.LINE_AA) | |
detected_image = cv2.idct(dct_y + watermark) | |
detected_image = np.uint8(np.clip(detected_image, 0, 255)) | |
return detected_image | |