# preprocess.py import cv2 import numpy as np def resize_and_crop_image(image_path, output_path, crop_percentage=0.05): """ 이미지를 중앙을 기준으로 축소 크롭합니다. Parameters: - image_path: str, 원본 이미지의 경로입니다. - output_path: str, 수정된 이미지를 저장할 경로입니다. - crop_percentage: float, 이미지를 얼마나 축소할지 결정하는 비율입니다. Returns: - None """ # 이미지 로드 image = cv2.imread(image_path) if image is None: print(f"Error: '{image_path}' cannot be loaded.") return # 이미지의 크기 계산 height, width = image.shape[:2] # 크롭할 크기 계산 crop_height = int(height * crop_percentage) crop_width = int(width * crop_percentage) # 중앙을 기준으로 크롭 범위 계산 start_row, start_col = crop_height // 2, crop_width // 2 end_row, end_col = height - start_row, width - start_col # 이미지 크롭 cropped_image = image[start_row:end_row, start_col:end_col] # 크롭된 이미지 저장 cv2.imwrite(output_path, cropped_image) # print(f"Image saved to {output_path}") # 예제 사용 # resize_and_crop_image("path/to/input/image.jpg", "path/to/output/cropped_image.jpg")