JacobLinCool/captcha-recognizer
1
1# Description: Preprocesses sample images2import os3import cv24import numpy as np5from PIL import Image6from src.shared import raw_dir, preprocess_dir7from src.preprocess import preprocess8 9 10def main():11 print(f"Preprocessing images in {raw_dir}")12 13 for filename in os.listdir(raw_dir):14 if not filename.endswith(".jpg"):15 continue16 17 raw_path = os.path.join(raw_dir, filename)18 image = np.array(Image.open(raw_path))19 20 image = preprocess(image)21 22 # Save to preprocessed23 preprocessed_path = os.path.join(preprocess_dir, filename)24 cv2.imwrite(preprocessed_path, image)25 26 print(f"Preprocessed {filename}")27 28 print("Done")29 30 31if __name__ == "__main__":32 main()33 