File size: 1,592 Bytes
f9ecaae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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