import cv2 import numpy as np class TextTargetPreprocessor: def __init__(self, upscale_factor=3): self.upscale_factor = upscale_factor def run(self, image_path): img = cv2.imread(image_path) if img is None: raise FileNotFoundError("Image not found.") # 1. Upscale (Maintain Cubic interpolation for smoothness) h, w = img.shape[:2] img_scaled = cv2.resize(img, (w*self.upscale_factor, h*self.upscale_factor), interpolation=cv2.INTER_CUBIC) return img_scaled class DoorTargetPreprocessor: def __init__(self, upscale_factor=3): self.upscale_factor = upscale_factor def run(self, image_path): img = cv2.imread(image_path) if img is None: raise FileNotFoundError("Image not found.") # Upscale (Maintain Sub-pixel details) h, w = img.shape[:2] img_scaled = cv2.resize(img, (w*self.upscale_factor, h*self.upscale_factor), interpolation=cv2.INTER_CUBIC) denoised = cv2.bilateralFilter(img_scaled, 9, 75, 75) gamma = 0.8 lookUpTable = np.empty((1,256), np.uint8) for i in range(256): lookUpTable[0,i] = np.clip(pow(i / 255.0, gamma) * 255.0, 0, 255) structural_img = cv2.LUT(denoised, lookUpTable) kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]]) final_yolo_img = cv2.filter2D(structural_img, -1, kernel) return final_yolo_img