File size: 737 Bytes
ffa6aac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Description: Preprocesses sample images
import os
import cv2
import numpy as np
from PIL import Image
from src.shared import raw_dir, preprocess_dir
from src.preprocess import preprocess


def main():
    print(f"Preprocessing images in {raw_dir}")

    for filename in os.listdir(raw_dir):
        if not filename.endswith(".jpg"):
            continue

        raw_path = os.path.join(raw_dir, filename)
        image = np.array(Image.open(raw_path))

        image = preprocess(image)

        # Save to preprocessed
        preprocessed_path = os.path.join(preprocess_dir, filename)
        cv2.imwrite(preprocessed_path, image)

        print(f"Preprocessed {filename}")

    print("Done")


if __name__ == "__main__":
    main()