반응형

Python OpenCV에서 이미지 크기(width, height)를 가져오는 방법입니다. 



2021. 11. 14




컬러 이미지의 경우에는 shape 함수를 통해 height, width, channels를 얻을 수 있습니다. 

 

import numpy as np
import cv2


img = cv2.imread('apple.png', cv2.IMREAD_COLOR)


print('img.shape ', img.shape)


h, w, c = img.shape

print('height ', h)
print('width ', w)
print('channel ', c)



img.shape  (618, 641, 3)
height  618
width  641
channel  3





흑백 이미지의 경우에는 shape 함수를 통해 height, width를 얻을 수 있습니다. 



import numpy as np
import cv2


img = cv2.imread('apple.png', cv2.IMREAD_GRAYSCALE)


print('img.shape ', img.shape)


h, w = img.shape

print('height ', h)
print('width ', w)



img.shape  (618, 641)
height  618
width  641






참고

https://stackoverflow.com/questions/19098104/python-opencv2-cv2-wrapper-to-get-image-size 

 

 

 



반응형

문제 발생시 지나치지 마시고 댓글 남겨주시면 가능한 빨리 답장드립니다.

도움이 되셨다면 토스아이디로 후원해주세요.
https://toss.me/momo2024


제가 쓴 책도 한번 검토해보세요 ^^

+ Recent posts