컴퓨터/파이썬 (Python)

[Python] 이미지 흑백 변환

COMKONG 2022. 5. 18. 12:24
반응형
import cv2
import os
import numpy as np
from PIL import Image
 
path = 'Ferdata\\test\\angry'
imagePaths = [os.path.join(path,file_name) for file_name in os.listdir(path)]
for imagePath in imagePaths:
    img = Image.open(imagePath).convert('L')
    img_numpy = np.array(img, 'uint8')
    cv2.imwrite("Ferdata\\" + imagePath.split("\\")[-1], img_numpy)
    #저장 위치
print("All Done")
반응형