File size: 802 Bytes
c159ca8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import cv2
import numpy as np
from PIL import Image

def preprocess_image(image):
    """Preprocess image for text erasing"""
    # Convert to RGB if needed
    if image.mode != "RGB":
        image = image.convert("RGB")
    return image

def create_text_mask(image_size, num_regions=5):
    """Create a simulated text mask for demonstration"""
    mask = np.zeros(image_size, dtype=np.uint8)
    
    for _ in range(num_regions):
        # Random position for text-like region
        x = np.random.randint(0, image_size[1] - 100)
    y = np.random.randint(0, image_size[0] - 30)
    width = np.random.randint(50, 200)
    height = np.random.randint(20, 40)
        
        # Draw rectangle (simulating text)
        cv2.rectangle(mask, (x, y), (x + width, y + height), 255, -1)
    
    return mask