본문 바로가기

프로그래밍 관련/[Python] 간단 해결

[Python] cv2.imread 한글 경로 인식 문제

 

- 증상

#imagePath에 한글 경로 존재 시

import cv2

img = cv2.imread(imagePath, -1) # img = None

print(np.shape(img)) # ()

 

- 해결

# numpy fromfile, cv2 imdecode를 사용하여 해결

import numpy as np
import cv2

ff = np.fromfile(imagePath, np.uint8)
img = cv2.imdecode(ff, cv2.IMREAD_UNCHANGED) # img = array

print(np.shape(img)) # (w, h, scale)

 

- 참고 (OpenCV API Documentation)

 

OpenCV: Image file reading and writing

For TIFF, use to specify the image compression scheme. See libtiff for integer constants corresponding to compression formats. Note, for images whose depth is CV_32F, only libtiff's SGILOG compression scheme is used. For other supported depths, the compres

docs.opencv.org