💻/멀티미디어
[파이썬] 이미지 → 그리드(배열)
ruhz
2020. 9. 21. 13:57
코드토막
import numpy as np
import cv2
# 이미지를 불러온다.
map_img = cv2.imread('map.png', 0)
# 이미지를 원하는 그리드 사이즈로 줄인다(40 × 40)
map_img = cv2.resize(map_img, dsize=(40, 40))
# numpy 배열을 만들고,
width, height = map_img.shape
map = np.zeros((width, height), np.uint8)
# 검정색 픽셀은 0, 나머지 픽셀은 1로 채웠다.
for x in range(height):
for y in range(width):
if map_img[x][y] > 0:
map[x][y] = 1
else:
map[x][y] = 0
# hhlab.tistory.com
그 외, OpenCV를 이용한 이미지 전처리